diff --git a/crates/gpui/playground/src/adapter.rs b/crates/gpui/playground/src/adapter.rs index e9f279346f..b66a176231 100644 --- a/crates/gpui/playground/src/adapter.rs +++ b/crates/gpui/playground/src/adapter.rs @@ -14,19 +14,16 @@ impl gpui::Element for Adapter { &mut self, constraint: gpui::SizeConstraint, view: &mut V, - legacy_cx: &mut gpui::LayoutContext, + cx: &mut LayoutContext, ) -> (gpui::geometry::vector::Vector2F, Self::LayoutState) { - legacy_cx.push_layout_engine(LayoutEngine::new()); - let node = self - .0 - .layout(view, &mut LayoutContext { legacy_cx }) - .log_err(); + cx.push_layout_engine(LayoutEngine::new()); + let node = self.0.layout(view, cx).log_err(); if let Some(node) = node { - let layout_engine = legacy_cx.layout_engine().unwrap(); + let layout_engine = cx.layout_engine().unwrap(); layout_engine.compute_layout(node, constraint.max).log_err(); } - let layout_engine = legacy_cx.pop_layout_engine(); + let layout_engine = cx.pop_layout_engine(); debug_assert!(layout_engine.is_some()); (constraint.max, layout_engine) } diff --git a/crates/gpui/playground/src/element.rs b/crates/gpui/playground/src/element.rs index b81df22a4b..26fef21a21 100644 --- a/crates/gpui/playground/src/element.rs +++ b/crates/gpui/playground/src/element.rs @@ -1,24 +1,19 @@ -use std::{any::Any, rc::Rc}; - use crate::{ adapter::Adapter, style::{Display, ElementStyle, Fill, Overflow, Position}, }; use anyhow::Result; use derive_more::{Deref, DerefMut}; +pub use gpui::LayoutContext; use gpui::{ geometry::{DefinedLength, Length}, scene::MouseClick, - EngineLayout, LayoutContext as LegacyLayoutContext, PaintContext as LegacyPaintContext, + EngineLayout, PaintContext as LegacyPaintContext, }; use playground_macros::tailwind_lengths; +use std::{any::Any, rc::Rc}; pub use taffy::tree::NodeId; -#[derive(Deref, DerefMut)] -pub struct LayoutContext<'a, 'b, 'c, 'd, V> { - pub(crate) legacy_cx: &'d mut LegacyLayoutContext<'a, 'b, 'c, V>, -} - #[derive(Deref, DerefMut)] pub struct PaintContext<'a, 'b, 'c, 'd, V> { #[deref] @@ -355,12 +350,9 @@ impl> ElementObject for E { self.paint(layout, view, cx) } - - // fn clone_object(&self) -> Box> { - // Box::new(Clone::clone(self)) - // } } +/// A dynamically typed element. pub struct AnyElement { element: Box>, layout: Option<(NodeId, Box)>, diff --git a/crates/gpui/playground/src/playground.rs b/crates/gpui/playground/src/playground.rs index 2c68f6caf6..7b98ac3026 100644 --- a/crates/gpui/playground/src/playground.rs +++ b/crates/gpui/playground/src/playground.rs @@ -18,6 +18,7 @@ mod components; mod element; mod frame; mod style; +mod text; mod themes; mod view; diff --git a/crates/gpui/playground/src/text.rs b/crates/gpui/playground/src/text.rs new file mode 100644 index 0000000000..561d5506a6 --- /dev/null +++ b/crates/gpui/playground/src/text.rs @@ -0,0 +1,36 @@ +use std::borrow::Cow; + +use crate::element::Element; + +impl Element for S +where + V: 'static, + S: 'static + Into>, +{ + type Layout = Cow<'static, str>; + + fn style_mut(&mut self) -> &mut crate::style::ElementStyle { + todo!() + } + + fn handlers_mut(&mut self) -> &mut crate::element::ElementHandlers { + todo!() + } + + fn layout( + &mut self, + view: &mut V, + cx: &mut crate::element::LayoutContext, + ) -> anyhow::Result<(taffy::tree::NodeId, Self::Layout)> { + todo!() + } + + fn paint<'a>( + &mut self, + layout: crate::element::Layout, + view: &mut V, + cx: &mut crate::element::PaintContext, + ) -> anyhow::Result<()> { + todo!() + } +}