Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add taffy node count and depth to inspector #139

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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