From a0b6e500cf5bdb62b1729980e622b53ecfa253ae Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 29 Aug 2023 18:40:24 -0600 Subject: [PATCH] WIP --- 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 +++++++++++++++ .../playground_macros/src/derive_element.rs | 2 +- 6 files changed, 58 insertions(+), 59 deletions(-) create mode 100644 crates/gpui/playground/src/workspace.rs diff --git a/crates/gpui/playground/src/components.rs b/crates/gpui/playground/src/components.rs index 304e8bc9e9..73dca57f35 100644 --- a/crates/gpui/playground/src/components.rs +++ b/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 Button { &mut self, view: &mut V, cx: &mut ViewContext, - ) -> impl Element + Interactive { - // TODO: Drive theme from the context + ) -> impl IntoElement + Interactive { + let colors = &cx.theme::().colors; + let button = div() - .fill(rose_pine::dawn().error(0.5)) + .fill(colors.error(0.5)) .h_4() .children(self.label.clone()); diff --git a/crates/gpui/playground/src/interactive.rs b/crates/gpui/playground/src/interactive.rs index e91436499c..3afe928b3e 100644 --- a/crates/gpui/playground/src/interactive.rs +++ b/crates/gpui/playground/src/interactive.rs @@ -11,7 +11,6 @@ use crate::element::PaintContext; pub trait Interactive { fn interaction_handlers(&mut self) -> &mut InteractionHandlers; - // One line change. fn on_mouse_down( mut self, button: MouseButton, diff --git a/crates/gpui/playground/src/playground.rs b/crates/gpui/playground/src/playground.rs index 59c9113fd4..6d05d19a66 100644 --- a/crates/gpui/playground/src/playground.rs +++ b/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(theme: Theme) -> impl Element { workspace().themed(theme) } - -fn workspace() -> impl Element { - WorkspaceElement -} - -use crate as playground; -#[derive(Element)] -struct WorkspaceElement; - -impl WorkspaceElement { - fn render(&mut self, _: &mut V, cx: &mut ViewContext) -> impl Element { - use div::div; - let theme = &cx.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(&mut self, cx: &mut ViewContext) -> impl IntoElement { - use div::div; - - let theme = ¤t_theme(cx).colors; - div().h(pixels(cx.titlebar_height())).fill(theme.base(0.)) - } - - fn status_bar(&mut self, cx: &mut ViewContext) -> impl IntoElement { - use div::div; - - let theme = ¤t_theme(cx).colors; - div().h(pixels(cx.titlebar_height())).fill(theme.base(0.)) - } - - fn stage(&mut self, cx: &mut ViewContext) -> impl IntoElement { - use div::div; - - let theme = ¤t_theme(cx).colors; - div().flex_grow() - } -} diff --git a/crates/gpui/playground/src/themes.rs b/crates/gpui/playground/src/themes.rs index ce57c8c147..4057491eed 100644 --- a/crates/gpui/playground/src/themes.rs +++ b/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::() } diff --git a/crates/gpui/playground/src/workspace.rs b/crates/gpui/playground/src/workspace.rs new file mode 100644 index 0000000000..bae8f80c24 --- /dev/null +++ b/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() -> impl Element { + WorkspaceElement +} + +impl WorkspaceElement { + fn render(&mut self, _: &mut V, cx: &mut ViewContext) -> impl IntoElement { + let theme = &cx.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(&mut self, cx: &mut ViewContext) -> impl IntoElement { + let colors = &theme(cx).colors; + div().h(pixels(cx.titlebar_height())).fill(colors.base(0.)) + } + + fn status_bar(&mut self, cx: &mut ViewContext) -> impl IntoElement { + let colors = &theme(cx).colors; + div().h(pixels(cx.titlebar_height())).fill(colors.base(0.)) + } + + fn stage(&mut self, cx: &mut ViewContext) -> impl IntoElement { + let colors = &theme(cx).colors; + div().flex_grow() + } +} diff --git a/crates/gpui/playground_macros/src/derive_element.rs b/crates/gpui/playground_macros/src/derive_element.rs index 180d19227d..82fb63574a 100644 --- a/crates/gpui/playground_macros/src/derive_element.rs +++ b/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, ) -> 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)) }