From 37ded190cf3c755ea544b489715fd9c0bf0845d9 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Fri, 4 Oct 2024 12:37:55 +0200 Subject: [PATCH] gpui: Use taffy to retrieve the parent for a given layout node (#18730) Again. https://github.com/zed-industries/zed/pull/4070 Let's see how it goes this time around. The only thing that might've been related to that revert on our Slack was about crashing in collab panel. Release Notes: - N/A --- crates/gpui/src/taffy.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/crates/gpui/src/taffy.rs b/crates/gpui/src/taffy.rs index c26b404b088d04092e2747ca38fa3c0d249e3398..feec5bf8c17bf7f37eef42f97e4461b94fe2f093 100644 --- a/crates/gpui/src/taffy.rs +++ b/crates/gpui/src/taffy.rs @@ -18,7 +18,6 @@ type NodeMeasureFn = pub struct TaffyLayoutEngine { taffy: TaffyTree<()>, styles: FxHashMap, - children_to_parents: FxHashMap, absolute_layout_bounds: FxHashMap>, computed_layouts: FxHashSet, nodes_to_measure: FxHashMap, @@ -31,7 +30,6 @@ impl TaffyLayoutEngine { TaffyLayoutEngine { taffy: TaffyTree::new(), styles: FxHashMap::default(), - children_to_parents: FxHashMap::default(), absolute_layout_bounds: FxHashMap::default(), computed_layouts: FxHashSet::default(), nodes_to_measure: FxHashMap::default(), @@ -40,7 +38,6 @@ impl TaffyLayoutEngine { pub fn clear(&mut self) { self.taffy.clear(); - self.children_to_parents.clear(); self.absolute_layout_bounds.clear(); self.computed_layouts.clear(); self.nodes_to_measure.clear(); @@ -68,8 +65,6 @@ impl TaffyLayoutEngine { }) .expect(EXPECT_MESSAGE) .into(); - self.children_to_parents - .extend(children.iter().map(|child_id| (*child_id, parent_id))); parent_id }; self.styles.insert(layout_id, style); @@ -209,8 +204,8 @@ impl TaffyLayoutEngine { size: layout.size.into(), }; - if let Some(parent_id) = self.children_to_parents.get(&id).copied() { - let parent_bounds = self.layout_bounds(parent_id); + if let Some(parent_id) = self.taffy.parent(id.0) { + let parent_bounds = self.layout_bounds(parent_id.into()); bounds.origin += parent_bounds.origin; } self.absolute_layout_bounds.insert(id, bounds);