diff --git a/crates/gpui3/src/elements/nested.rs b/crates/gpui3/src/elements/nested.rs index bd1a8008fc..532654958a 100644 --- a/crates/gpui3/src/elements/nested.rs +++ b/crates/gpui3/src/elements/nested.rs @@ -1,7 +1,7 @@ use crate::{ - group_bounds, AnyElement, DispatchPhase, Element, ElementId, IdentifiedElement, IntoAnyElement, - MouseDownEvent, MouseMoveEvent, MouseUpEvent, SharedString, Style, StyleCascade, - StyleRefinement, ViewContext, + group_bounds, AnyElement, BorrowWindow, DispatchPhase, Element, ElementId, IdentifiedElement, + IntoAnyElement, MouseDownEvent, MouseMoveEvent, MouseUpEvent, SharedString, Style, + StyleCascade, StyleRefinement, ViewContext, }; use parking_lot::Mutex; use refineable::{CascadeSlot, Refineable}; @@ -72,6 +72,20 @@ impl LayoutNodeElement { } } +impl LayoutNodeElement { + fn with_element_id( + &mut self, + cx: &mut ViewContext, + f: impl FnOnce(&mut Self, &mut ViewContext) -> R, + ) -> R { + if let Some(id) = self.id() { + cx.with_element_id(id, |cx| f(self, cx)) + } else { + f(self, cx) + } + } +} + impl Styled for LayoutNodeElement { fn style_cascade(&mut self) -> &mut StyleCascade { &mut self.style_cascade @@ -84,7 +98,7 @@ impl Styled for LayoutNodeElement IdentifiedElement for LayoutNodeElement { - fn element_id(&self) -> crate::ElementId { + fn element_id(&self) -> ElementId { self.kind.0.clone() } } @@ -103,8 +117,8 @@ impl Element for LayoutNodeElement Option { - None + fn id(&self) -> Option { + self.kind.id() } fn layout( @@ -113,16 +127,17 @@ impl Element for LayoutNodeElement, cx: &mut crate::ViewContext, ) -> (crate::LayoutId, Self::ElementState) { - let layout_ids = self - .children - .iter_mut() - .map(|child| child.layout(state, cx)) - .collect::>(); + self.with_element_id(cx, |this, cx| { + let layout_ids = this + .children + .iter_mut() + .map(|child| child.layout(state, cx)) + .collect::>(); - // todo!("pass just the style cascade") - let style = self.computed_style().clone(); - let layout_id = cx.request_layout(style, layout_ids); - (layout_id, ()) + let style = this.computed_style().clone(); + let layout_id = cx.request_layout(style, layout_ids); + (layout_id, ()) + }) } fn paint( @@ -132,9 +147,11 @@ impl Element for LayoutNodeElement, ) { - for child in &mut self.children { - child.paint(state, None, cx); - } + self.with_element_id(cx, |this, cx| { + for child in &mut this.children { + child.paint(state, None, cx); + } + }) } } @@ -198,7 +215,7 @@ where type ViewState = E::ViewState; type ElementState = E::ElementState; - fn id(&self) -> Option { + fn id(&self) -> Option { self.child.id() } @@ -331,7 +348,7 @@ where type ViewState = E::ViewState; type ElementState = ClickableElementState; - fn id(&self) -> Option { + fn id(&self) -> Option { self.child.id() }