diff --git a/crates/gpui/playground/src/adapter.rs b/crates/gpui/playground/src/adapter.rs index 7a5a0399a81224ac2a9032f791b55764d9d76f68..eff2356c94a36cffdcf08d13df9985fd7f9a025a 100644 --- a/crates/gpui/playground/src/adapter.rs +++ b/crates/gpui/playground/src/adapter.rs @@ -47,7 +47,7 @@ impl gpui::Element for AdapterElement { let (layout_engine, layout_id) = layout_data.take().unwrap(); legacy_cx.push_layout_engine(layout_engine); let mut cx = PaintContext::new(legacy_cx, scene); - self.0.paint(view, &mut cx); + self.0.paint(view, bounds.origin(), &mut cx); *layout_data = legacy_cx.pop_layout_engine().zip(Some(layout_id)); debug_assert!(layout_data.is_some()); } diff --git a/crates/gpui/playground/src/div.rs b/crates/gpui/playground/src/div.rs index 75ac5d965b6dea24b77725327a2f947ad3d0bf61..ca71ede6d447c5aa36f3012316ff7630ec2db90d 100644 --- a/crates/gpui/playground/src/div.rs +++ b/crates/gpui/playground/src/div.rs @@ -72,7 +72,7 @@ impl Element for Div { self.interaction_handlers() .paint(layout.order, layout.bounds, cx); for child in &mut self.children { - child.paint(view, cx); + child.paint(view, layout.bounds.origin(), cx); } if pop_text_style { cx.pop_text_style(); diff --git a/crates/gpui/playground/src/element.rs b/crates/gpui/playground/src/element.rs index c39ee7e19671d537d9c027d837c4ca67f67f0f07..6091e17989fe54b7a95a27e1789e9eb3eef2fecd 100644 --- a/crates/gpui/playground/src/element.rs +++ b/crates/gpui/playground/src/element.rs @@ -1,6 +1,7 @@ pub use crate::layout_context::LayoutContext; pub use crate::paint_context::PaintContext; use anyhow::Result; +use gpui::geometry::vector::Vector2F; pub use gpui::{Layout, LayoutId}; use smallvec::SmallVec; @@ -38,7 +39,7 @@ pub trait Element: 'static { /// Used to make ElementState into a trait object, so we can wrap it in AnyElement. trait AnyStatefulElement { fn layout(&mut self, view: &mut V, cx: &mut LayoutContext) -> Result; - fn paint(&mut self, view: &mut V, cx: &mut PaintContext); + fn paint(&mut self, view: &mut V, parent_origin: Vector2F, cx: &mut PaintContext); } /// A wrapper around an element that stores its layout state. @@ -91,13 +92,14 @@ impl> AnyStatefulElement for StatefulElement { result } - fn paint(&mut self, view: &mut V, cx: &mut PaintContext) { + fn paint(&mut self, view: &mut V, parent_origin: Vector2F, cx: &mut PaintContext) { self.phase = match std::mem::take(&mut self.phase) { ElementPhase::PostLayout { layout_id, mut paint_state, } => match cx.computed_layout(layout_id) { - Ok(layout) => { + Ok(mut layout) => { + layout.bounds = layout.bounds + parent_origin; self.element.paint(view, &layout, &mut paint_state, cx); ElementPhase::PostPaint { layout, @@ -120,8 +122,8 @@ impl AnyElement { self.0.layout(view, cx) } - pub fn paint(&mut self, view: &mut V, cx: &mut PaintContext) { - self.0.paint(view, cx) + pub fn paint(&mut self, view: &mut V, parent_origin: Vector2F, cx: &mut PaintContext) { + self.0.paint(view, parent_origin, cx) } } diff --git a/crates/gpui/playground_macros/src/derive_element.rs b/crates/gpui/playground_macros/src/derive_element.rs index 482f6ccaf48b6e00dd0161c9fbdbabbc77842d7f..180d19227d875a895676c43c8897902ba7865743 100644 --- a/crates/gpui/playground_macros/src/derive_element.rs +++ b/crates/gpui/playground_macros/src/derive_element.rs @@ -81,7 +81,7 @@ pub fn derive_element(input: TokenStream) -> TokenStream { rendered_element: &mut Self::PaintState, cx: &mut playground::element::PaintContext, ) { - rendered_element.paint(view, cx); + rendered_element.paint(view, layout.bounds.origin(), cx); } }