Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
WIP
Nathan Soboa0b6e500cf5b
diff --git a/crates/gpui/playground/src/components.rs b/crates/gpui/playground/src/components.rsindex 304e8bc9e98..73dca57f359 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<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());diff --git a/crates/gpui/playground/src/interactive.rs b/crates/gpui/playground/src/interactive.rsindex e91436499ca..3afe928b3e6 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<V: 'static> {fn interaction_handlers(&mut self) -> &mut InteractionHandlers<V>;- // 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.rsindex 59c9113fd40..6d05d19a66c 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<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 = ¤t_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 = ¤t_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 = ¤t_theme(cx).colors;- div().flex_grow()- }-}diff --git a/crates/gpui/playground/src/themes.rs b/crates/gpui/playground/src/themes.rsindex ce57c8c1472..4057491eed3 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::<Theme>()}diff --git a/crates/gpui/playground/src/workspace.rs b/crates/gpui/playground/src/workspace.rsnew file mode 100644index 00000000000..bae8f80c24a--- /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<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()+ }+}diff --git a/crates/gpui/playground_macros/src/derive_element.rs b/crates/gpui/playground_macros/src/derive_element.rsindex 180d19227d8..82fb63574a0 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<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))}