WIP

Nathan Sobo created

Change summary

crates/gpui/playground/src/adapter.rs    | 13 +++-----
crates/gpui/playground/src/element.rs    | 16 ++--------
crates/gpui/playground/src/playground.rs |  1 
crates/gpui/playground/src/text.rs       | 36 ++++++++++++++++++++++++++
4 files changed, 46 insertions(+), 20 deletions(-)

Detailed changes

crates/gpui/playground/src/adapter.rs 🔗

@@ -14,19 +14,16 @@ impl<V: 'static> gpui::Element<V> for Adapter<V> {
         &mut self,
         constraint: gpui::SizeConstraint,
         view: &mut V,
-        legacy_cx: &mut gpui::LayoutContext<V>,
+        cx: &mut LayoutContext<V>,
     ) -> (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)
     }

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<V: 'static, E: Element<V>> ElementObject<V> for E {
 
         self.paint(layout, view, cx)
     }
-
-    // fn clone_object(&self) -> Box<dyn ElementObject<V>> {
-    //     Box::new(Clone::clone(self))
-    // }
 }
 
+/// A dynamically typed element.
 pub struct AnyElement<V> {
     element: Box<dyn ElementObject<V>>,
     layout: Option<(NodeId, Box<dyn Any>)>,

crates/gpui/playground/src/text.rs 🔗

@@ -0,0 +1,36 @@
+use std::borrow::Cow;
+
+use crate::element::Element;
+
+impl<V, S> Element<V> for S
+where
+    V: 'static,
+    S: 'static + Into<Cow<'static, str>>,
+{
+    type Layout = Cow<'static, str>;
+
+    fn style_mut(&mut self) -> &mut crate::style::ElementStyle {
+        todo!()
+    }
+
+    fn handlers_mut(&mut self) -> &mut crate::element::ElementHandlers<V> {
+        todo!()
+    }
+
+    fn layout(
+        &mut self,
+        view: &mut V,
+        cx: &mut crate::element::LayoutContext<V>,
+    ) -> anyhow::Result<(taffy::tree::NodeId, Self::Layout)> {
+        todo!()
+    }
+
+    fn paint<'a>(
+        &mut self,
+        layout: crate::element::Layout<Self::Layout>,
+        view: &mut V,
+        cx: &mut crate::element::PaintContext<V>,
+    ) -> anyhow::Result<()> {
+        todo!()
+    }
+}