WIP

Nathan Sobo created

Change summary

crates/gpui/playground/src/components.rs            | 11 +-
crates/gpui/playground/src/interactive.rs           |  1 
crates/gpui/playground/src/playground.rs            | 56 +-------------
crates/gpui/playground/src/themes.rs                |  2 
crates/gpui/playground/src/workspace.rs             | 45 ++++++++++++
crates/gpui/playground_macros/src/derive_element.rs |  2 
6 files changed, 58 insertions(+), 59 deletions(-)

Detailed changes

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

@@ -1,10 +1,10 @@
 use crate::{
     div::div,
-    element::{Element, ParentElement},
+    element::{IntoElement, ParentElement},
     interactive::Interactive,
     style::StyleHelpers,
     text::ArcCow,
-    themes::rose_pine,
+    themes::Theme,
 };
 use gpui::{platform::MouseButton, ViewContext};
 use playground_macros::Element;
@@ -81,10 +81,11 @@ impl<V: 'static, D: 'static> Button<V, D> {
         &mut self,
         view: &mut V,
         cx: &mut ViewContext<V>,
-    ) -> impl Element<V> + Interactive<V> {
-        // TODO: Drive theme from the context
+    ) -> impl IntoElement<V> + Interactive<V> {
+        let colors = &cx.theme::<Theme>().colors;
+
         let button = div()
-            .fill(rose_pine::dawn().error(0.5))
+            .fill(colors.error(0.5))
             .h_4()
             .children(self.label.clone());
 

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

@@ -11,7 +11,6 @@ use crate::element::PaintContext;
 pub trait Interactive<V: 'static> {
     fn interaction_handlers(&mut self) -> &mut InteractionHandlers<V>;
 
-    // One line change.
     fn on_mouse_down(
         mut self,
         button: MouseButton,

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

@@ -1,16 +1,14 @@
 #![allow(dead_code, unused_variables)]
-use crate::{element::ParentElement, style::StyleHelpers};
-use element::{Element, IntoElement};
+use element::Element;
 use gpui::{
-    geometry::{pixels, rect::RectF, vector::vec2f},
+    geometry::{rect::RectF, vector::vec2f},
     platform::WindowOptions,
-    ViewContext,
 };
 use log::LevelFilter;
-use playground_macros::Element;
 use simplelog::SimpleLogger;
-use themes::{current_theme, rose_pine, Theme, ThemeColors};
+use themes::{rose_pine, Theme, ThemeColors};
 use view::view;
+use workspace::workspace;
 
 mod adapter;
 mod color;
@@ -26,6 +24,7 @@ mod style;
 mod text;
 mod themes;
 mod view;
+mod workspace;
 
 fn main() {
     SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
@@ -55,48 +54,3 @@ fn main() {
 fn playground<V: 'static>(theme: Theme) -> impl Element<V> {
     workspace().themed(theme)
 }
-
-fn workspace<V: 'static>() -> impl Element<V> {
-    WorkspaceElement
-}
-
-use crate as playground;
-#[derive(Element)]
-struct WorkspaceElement;
-
-impl WorkspaceElement {
-    fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl Element<V> {
-        use div::div;
-        let theme = &cx.theme::<Theme>().colors;
-        // one line change1!
-        div()
-            .full()
-            .flex()
-            .flex_col()
-            .fill(theme.base(0.5))
-            .child(self.title_bar(cx))
-            .child(self.stage(cx))
-            .child(self.status_bar(cx))
-    }
-
-    fn title_bar<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
-        use div::div;
-
-        let theme = &current_theme(cx).colors;
-        div().h(pixels(cx.titlebar_height())).fill(theme.base(0.))
-    }
-
-    fn status_bar<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
-        use div::div;
-
-        let theme = &current_theme(cx).colors;
-        div().h(pixels(cx.titlebar_height())).fill(theme.base(0.))
-    }
-
-    fn stage<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
-        use div::div;
-
-        let theme = &current_theme(cx).colors;
-        div().flex_grow()
-    }
-}

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

@@ -13,7 +13,7 @@ pub struct Theme {
     pub colors: ThemeColors,
 }
 
-pub fn current_theme<'a>(cx: &'a WindowContext) -> &'a Theme {
+pub fn theme<'a>(cx: &'a WindowContext) -> &'a Theme {
     cx.theme::<Theme>()
 }
 

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

@@ -0,0 +1,45 @@
+use crate::div::div;
+use crate::element::{IntoElement, ParentElement};
+use crate::style::StyleHelpers;
+use crate::themes::theme;
+use crate::{element::Element, themes::Theme};
+use gpui::geometry::pixels;
+use gpui::ViewContext;
+use playground_macros::Element;
+
+use crate as playground;
+#[derive(Element)]
+struct WorkspaceElement;
+
+pub fn workspace<V: 'static>() -> impl Element<V> {
+    WorkspaceElement
+}
+
+impl WorkspaceElement {
+    fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
+        let theme = &cx.theme::<Theme>().colors;
+        div()
+            .full()
+            .flex()
+            .flex_col()
+            .fill(theme.base(0.5))
+            .child(self.title_bar(cx))
+            .child(self.stage(cx))
+            .child(self.status_bar(cx))
+    }
+
+    fn title_bar<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
+        let colors = &theme(cx).colors;
+        div().h(pixels(cx.titlebar_height())).fill(colors.base(0.))
+    }
+
+    fn status_bar<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
+        let colors = &theme(cx).colors;
+        div().h(pixels(cx.titlebar_height())).fill(colors.base(0.))
+    }
+
+    fn stage<V: 'static>(&mut self, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
+        let colors = &theme(cx).colors;
+        div().flex_grow()
+    }
+}

crates/gpui/playground_macros/src/derive_element.rs 🔗

@@ -69,7 +69,7 @@ pub fn derive_element(input: TokenStream) -> TokenStream {
                 view: &mut V,
                 cx: &mut playground::element::LayoutContext<V>,
             ) -> anyhow::Result<(playground::element::LayoutId, Self::PaintState)> {
-                let mut rendered_element = self.render(view, cx).into_any();
+                let mut rendered_element = self.render(view, cx).into_element().into_any();
                 let layout_id = rendered_element.layout(view, cx)?;
                 Ok((layout_id, rendered_element))
             }