diff --git a/crates/gpui3/src/taffy.rs b/crates/gpui3/src/taffy.rs index 3aa53a11cd3fb587b827fb63389dbe7309678b99..919f4889f901eb3a3ec52f6024da023470041a58 100644 --- a/crates/gpui3/src/taffy.rs +++ b/crates/gpui3/src/taffy.rs @@ -66,11 +66,62 @@ impl TaffyLayoutEngine { .into()) } + fn count_all_children(&self, parent: LayoutId) -> Result { + let mut count = 0; + + for child in self.taffy.children(parent.0)? { + // Count this child. + count += 1; + + // Count all of this child's children. + count += self.count_all_children(LayoutId(child))? + } + + Ok(count) + } + + fn max_depth(&self, depth: u32, parent: LayoutId) -> Result { + println!( + "{parent:?} at depth {depth} has {} children", + self.taffy.child_count(parent.0)? + ); + + let mut max_child_depth = 0; + + for child in self.taffy.children(parent.0)? { + max_child_depth = std::cmp::max(max_child_depth, self.max_depth(0, LayoutId(child))?); + } + + Ok(depth + 1 + max_child_depth) + } + + fn get_edges(&self, parent: LayoutId) -> Result> { + let mut edges = Vec::new(); + + for child in self.taffy.children(parent.0)? { + edges.push((parent, LayoutId(child))); + + edges.extend(self.get_edges(LayoutId(child))?); + } + + Ok(edges) + } + pub fn compute_layout( &mut self, id: LayoutId, available_space: Size, ) -> Result<()> { + println!("Laying out {} children", self.count_all_children(id)?); + println!("Max layout depth: {}", self.max_depth(0, id)?); + + // Output the edges (branches) of the tree in Mermaid format for visualization. + // println!("Edges:"); + // for (a, b) in self.get_edges(id)? { + // println!("N{} --> N{}", u64::from(a), u64::from(b)); + // } + // println!(""); + self.taffy .compute_layout(id.into(), available_space.into())?; Ok(()) diff --git a/crates/gpui3/src/window.rs b/crates/gpui3/src/window.rs index f255172c776276f5e8297e3037e033f982d0bfd3..b9516d44e985467cc9929c6efda9ad3b1ef04ad5 100644 --- a/crates/gpui3/src/window.rs +++ b/crates/gpui3/src/window.rs @@ -401,9 +401,11 @@ impl<'a, 'w> WindowContext<'a, 'w> { let (root_layout_id, mut frame_state) = root_view.layout(&mut (), cx)?; let available_space = cx.window.content_size.map(Into::into); + let started_at = std::time::Instant::now(); cx.window .layout_engine .compute_layout(root_layout_id, available_space)?; + println!("compute_layout took {:?}", started_at.elapsed()); let layout = cx.window.layout_engine.layout(root_layout_id)?; root_view.paint(layout, &mut (), &mut frame_state, cx)?;