diff --git a/crates/gpui3/src/elements/div.rs b/crates/gpui3/src/elements/div.rs index ee0bb22779..bbe45be8a1 100644 --- a/crates/gpui3/src/elements/div.rs +++ b/crates/gpui3/src/elements/div.rs @@ -1,5 +1,5 @@ use crate::{ - AnyElement, Bounds, Element, ElementId, IdentifiedElement, Interactive, LayoutId, + AnyElement, BorrowWindow, Bounds, Element, ElementId, IdentifiedElement, Interactive, LayoutId, MouseEventListeners, Overflow, ParentElement, Pixels, Point, Refineable, RefinementCascade, Style, Styled, ViewContext, }; @@ -44,7 +44,9 @@ impl Element for Div, ) -> (LayoutId, Self::ElementState) { let style = self.computed_style(); - let child_layout_ids = style.apply_text_style(cx, |cx| self.layout_children(view, cx)); + let child_layout_ids = style.apply_text_style(cx, |cx| { + self.with_element_id(cx, |this, cx| this.layout_children(view, cx)) + }); let layout_id = cx.request_layout(style.into(), child_layout_ids.clone()); (layout_id, ()) } @@ -60,11 +62,14 @@ impl Element for Div( + &mut self, + cx: &mut ViewContext, + f: impl FnOnce(&mut Self, &mut ViewContext) -> R, + ) -> R { + if let Some(element_id) = self.element_id() { + cx.with_element_id(element_id, |cx| f(self, cx)) + } else { + f(self, cx) + } + } } impl Styled for Div { diff --git a/crates/gpui3/src/view.rs b/crates/gpui3/src/view.rs index 88eeab8aa3..a7db926fc3 100644 --- a/crates/gpui3/src/view.rs +++ b/crates/gpui3/src/view.rs @@ -1,8 +1,8 @@ use parking_lot::Mutex; use crate::{ - AnyBox, AnyElement, Bounds, Element, Handle, IntoAnyElement, LayoutId, Pixels, ViewContext, - WindowContext, + AnyBox, AnyElement, BorrowWindow, Bounds, Element, ElementId, Handle, IdentifiedElement, + IntoAnyElement, LayoutId, Pixels, ViewContext, WindowContext, }; use std::{any::Any, marker::PhantomData, sync::Arc}; @@ -12,7 +12,7 @@ pub struct View { parent_state_type: PhantomData

, } -impl View { +impl View { pub fn into_any(self) -> AnyView

{ AnyView { view: Arc::new(Mutex::new(self)), @@ -54,7 +54,7 @@ impl Element for View type ElementState = AnyElement; fn element_id(&self) -> Option { - None + Some(ElementId::View(self.state.id)) } fn layout( @@ -87,20 +87,26 @@ trait ViewObject: Send + 'static { fn paint(&mut self, bounds: Bounds, element: &mut dyn Any, cx: &mut WindowContext); } -impl ViewObject for View { +impl IdentifiedElement for View {} + +impl ViewObject for View { fn layout(&mut self, cx: &mut WindowContext) -> (LayoutId, AnyBox) { - self.state.update(cx, |state, cx| { - let mut element = (self.render)(state, cx); - let layout_id = element.layout(state, cx); - let element = Box::new(element) as AnyBox; - (layout_id, element) + cx.with_element_id(IdentifiedElement::element_id(self), |cx| { + self.state.update(cx, |state, cx| { + let mut element = (self.render)(state, cx); + let layout_id = element.layout(state, cx); + let element = Box::new(element) as AnyBox; + (layout_id, element) + }) }) } fn paint(&mut self, _: Bounds, element: &mut dyn Any, cx: &mut WindowContext) { - self.state.update(cx, |state, cx| { - let element = element.downcast_mut::>().unwrap(); - element.paint(state, None, cx); + cx.with_element_id(IdentifiedElement::element_id(self), |cx| { + self.state.update(cx, |state, cx| { + let element = element.downcast_mut::>().unwrap(); + element.paint(state, None, cx); + }); }); } } diff --git a/crates/gpui3/src/window.rs b/crates/gpui3/src/window.rs index df0d8cb1da..1f1f87afac 100644 --- a/crates/gpui3/src/window.rs +++ b/crates/gpui3/src/window.rs @@ -21,7 +21,7 @@ use std::{ mem, sync::Arc, }; -use util::{arc_cow::ArcCow, ResultExt}; +use util::ResultExt; #[derive(Deref, DerefMut, Ord, PartialOrd, Eq, PartialEq, Clone, Default)] pub struct StackingOrder(pub(crate) SmallVec<[u32; 16]>); @@ -1110,22 +1110,19 @@ impl From> for StackingOrder { } #[derive(Clone, Debug, Eq, PartialEq, Hash)] -pub struct ElementId(ArcCow<'static, [u8]>); +pub enum ElementId { + View(EntityId), + Number(usize), +} impl From for ElementId { fn from(id: usize) -> Self { - Self(id.to_ne_bytes().to_vec().into()) + ElementId::Number(id) } } impl From for ElementId { fn from(id: i32) -> Self { - Self(id.to_ne_bytes().to_vec().into()) - } -} - -impl From<&'static str> for ElementId { - fn from(id: &'static str) -> Self { - Self(id.into()) + Self::Number(id as usize) } } diff --git a/crates/storybook2/src/workspace.rs b/crates/storybook2/src/workspace.rs index fd48cea009..e91e267f06 100644 --- a/crates/storybook2/src/workspace.rs +++ b/crates/storybook2/src/workspace.rs @@ -47,7 +47,8 @@ impl Workspace { .flex_row() .overflow_hidden() .child(self.left_panel.clone()) - .child(div().h_full().flex_1()), // .child(self.right_panel.clone()), + .child(div().h_full().flex_1()) + .child(self.right_panel.clone()), ) .child(statusbar::statusbar(cx)) })