Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Relativize child layouts to their parent origin
Nathan Sobo5bb780073e1f
diff --git a/crates/gpui/playground/src/adapter.rs b/crates/gpui/playground/src/adapter.rsindex 7a5a0399a81..eff2356c94a 100644--- a/crates/gpui/playground/src/adapter.rs+++ b/crates/gpui/playground/src/adapter.rs@@ -47,7 +47,7 @@ impl<V: 'static> gpui::Element<V> for AdapterElement<V> {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.rsindex 75ac5d965b6..ca71ede6d44 100644--- a/crates/gpui/playground/src/div.rs+++ b/crates/gpui/playground/src/div.rs@@ -72,7 +72,7 @@ impl<V: 'static> Element<V> for Div<V> {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.rsindex c39ee7e1967..6091e17989f 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<V: 'static>: 'static {/// Used to make ElementState<V, E> into a trait object, so we can wrap it in AnyElement<V>.trait AnyStatefulElement<V> {fn layout(&mut self, view: &mut V, cx: &mut LayoutContext<V>) -> Result<LayoutId>;- fn paint(&mut self, view: &mut V, cx: &mut PaintContext<V>);+ fn paint(&mut self, view: &mut V, parent_origin: Vector2F, cx: &mut PaintContext<V>);}/// A wrapper around an element that stores its layout state.@@ -91,13 +92,14 @@ impl<V, E: Element<V>> AnyStatefulElement<V> for StatefulElement<V, E> {result}- fn paint(&mut self, view: &mut V, cx: &mut PaintContext<V>) {+ fn paint(&mut self, view: &mut V, parent_origin: Vector2F, cx: &mut PaintContext<V>) {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<V> AnyElement<V> {self.0.layout(view, cx)}- pub fn paint(&mut self, view: &mut V, cx: &mut PaintContext<V>) {- self.0.paint(view, cx)+ pub fn paint(&mut self, view: &mut V, parent_origin: Vector2F, cx: &mut PaintContext<V>) {+ 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.rsindex 482f6ccaf48..180d19227d8 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<V>,) {- rendered_element.paint(view, cx);+ rendered_element.paint(view, layout.bounds.origin(), cx);}}