Skip to content

Commit

Permalink
Add taffy node count and depth to inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Nov 3, 2023
1 parent 7094fb3 commit 5d65c16
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ pub struct Capture {
pub post_layout: Instant,
pub end: Instant,
pub taffy_duration: Duration,
pub taffy_node_count: usize,
pub taffy_depth: usize,
pub window: Option<Rc<DynamicImage>>,
pub window_size: Size,
pub scale: f64,
Expand Down Expand Up @@ -305,13 +307,24 @@ fn stats(capture: &Capture) -> impl View {
"Taffy time",
format!("{:.4} ms", capture.taffy_duration.as_secs_f64() * 1000.0),
);
let taffy_node_count = info("Taffy node count", capture.taffy_node_count.to_string());
let taffy_depth = info("Taffy depth", capture.taffy_depth.to_string());
let paint_time = info(
"Paint time",
format!("Paint time: {:.4} ms", paint_time.as_secs_f64() * 1000.0),
);
let w = info("Window Width", format!("{}", capture.window_size.width));
let h = info("Window Height", format!("{}", capture.window_size.height));
stack((layout_time, taffy_time, paint_time, w, h)).style(|s| s.flex_col())
stack((
layout_time,
taffy_time,
taffy_node_count,
taffy_depth,
paint_time,
w,
h,
))
.style(|s| s.flex_col())
}

fn selected_view(capture: &Rc<Capture>, selected: RwSignal<Option<Id>>) -> impl View {
Expand Down
17 changes: 17 additions & 0 deletions src/window_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,23 @@ impl WindowHandle {
.values_mut()
.for_each(|state| state.request_layout = true);

fn get_taffy_depth(taffy: &taffy::Taffy, root: taffy::node::Node) -> usize {
let children = taffy.children(root).unwrap();
if children.is_empty() {
1
} else {
children
.iter()
.map(|child| get_taffy_depth(taffy, *child))
.max()
.unwrap()
+ 1
}
}

let start = Instant::now();

let taffy_root_node = self.app_state.view_state(self.view.id()).node;
let taffy_duration = self.layout();
let post_layout = Instant::now();
let window = self.paint().map(Rc::new);
Expand All @@ -562,6 +577,8 @@ impl WindowHandle {
post_layout,
end,
taffy_duration,
taffy_node_count: self.app_state.taffy.total_node_count(),
taffy_depth: get_taffy_depth(&self.app_state.taffy, taffy_root_node),
window,
window_size: self.size.get_untracked() / self.app_state.scale,
scale: self.scale * self.app_state.scale,
Expand Down

0 comments on commit 5d65c16

Please sign in to comment.