From 44608517c1dc0080fc50941cf989573fed2fc6f7 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 20 Sep 2023 14:32:55 -0600 Subject: [PATCH] WIP --- Cargo.lock | 16 + Cargo.toml | 1 + crates/gpui3/Cargo.toml | 1 + crates/gpui3/src/elements.rs | 9 +- crates/gpui3/src/elements/div.rs | 2 +- crates/gpui3/src/elements/editor.rs | 61 - crates/gpui3/src/elements/img.rs | 116 +- crates/gpui3/src/elements/svg.rs | 73 +- crates/gpui3/src/elements/text.rs | 95 +- crates/gpui3/src/geometry.rs | 15 + crates/gpui3/src/gpui3.rs | 48 +- crates/gpui3/src/style.rs | 13 + crates/gpui3/src/taffy.rs | 35 +- crates/gpui3/src/window.rs | 24 +- crates/storybook2/Cargo.lock | 2919 +++++++++++++++++++++++++ crates/storybook2/Cargo.toml | 23 + crates/storybook2/build.rs | 5 + crates/storybook2/docs/thoughts.md | 72 + crates/storybook2/src/collab_panel.rs | 177 ++ crates/storybook2/src/components.rs | 97 + crates/storybook2/src/element_ext.rs | 22 + crates/storybook2/src/storybook2.rs | 108 + crates/storybook2/src/theme.rs | 190 ++ crates/storybook2/src/workspace.rs | 431 ++++ 24 files changed, 4277 insertions(+), 276 deletions(-) delete mode 100644 crates/gpui3/src/elements/editor.rs create mode 100644 crates/storybook2/Cargo.lock create mode 100644 crates/storybook2/Cargo.toml create mode 100644 crates/storybook2/build.rs create mode 100644 crates/storybook2/docs/thoughts.md create mode 100644 crates/storybook2/src/collab_panel.rs create mode 100644 crates/storybook2/src/components.rs create mode 100644 crates/storybook2/src/element_ext.rs create mode 100644 crates/storybook2/src/storybook2.rs create mode 100644 crates/storybook2/src/theme.rs create mode 100644 crates/storybook2/src/workspace.rs diff --git a/Cargo.lock b/Cargo.lock index 090ab493bf..1c34050c7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3363,6 +3363,7 @@ dependencies = [ "font-kit", "foreign-types 0.3.2", "futures 0.3.28", + "gpui2_macros", "gpui_macros", "image", "itertools", @@ -7696,6 +7697,21 @@ dependencies = [ "util", ] +[[package]] +name = "storybook2" +version = "0.1.0" +dependencies = [ + "anyhow", + "gpui3", + "log", + "rust-embed", + "serde", + "settings", + "simplelog", + "theme", + "util", +] + [[package]] name = "stringprep" version = "0.1.3" diff --git a/Cargo.toml b/Cargo.toml index 4c6d3a6fb9..4a9606ffa1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,6 +65,7 @@ members = [ "crates/sqlez_macros", "crates/feature_flags", "crates/storybook", + "crates/storybook2", "crates/sum_tree", "crates/terminal", "crates/text", diff --git a/crates/gpui3/Cargo.toml b/crates/gpui3/Cargo.toml index 3a995aeb40..68a6ed0812 100644 --- a/crates/gpui3/Cargo.toml +++ b/crates/gpui3/Cargo.toml @@ -16,6 +16,7 @@ doctest = false [dependencies] collections = { path = "../collections" } gpui_macros = { path = "../gpui_macros" } +gpui2_macros = { path = "../gpui2_macros" } util = { path = "../util" } sum_tree = { path = "../sum_tree" } sqlez = { path = "../sqlez" } diff --git a/crates/gpui3/src/elements.rs b/crates/gpui3/src/elements.rs index c2cecaf6c6..f9d5a99101 100644 --- a/crates/gpui3/src/elements.rs +++ b/crates/gpui3/src/elements.rs @@ -1,7 +1,8 @@ -pub mod div; -pub mod editor; +mod div; +mod img; +mod svg; +mod text; use super::*; -pub use div::div; -pub use editor::field; +pub use div::*; diff --git a/crates/gpui3/src/elements/div.rs b/crates/gpui3/src/elements/div.rs index 4545bc83bd..9faad7a3e4 100644 --- a/crates/gpui3/src/elements/div.rs +++ b/crates/gpui3/src/elements/div.rs @@ -77,7 +77,7 @@ impl Element for Div { // } for child in &mut self.children { - child.paint(scrolled_origin, state, cx); + child.paint(scrolled_origin, state, cx)?; } // if pop_layer { diff --git a/crates/gpui3/src/elements/editor.rs b/crates/gpui3/src/elements/editor.rs deleted file mode 100644 index 8b2cbc808b..0000000000 --- a/crates/gpui3/src/elements/editor.rs +++ /dev/null @@ -1,61 +0,0 @@ -use super::{Element, Handle, Layout, LayoutId, Result, SharedString, ViewContext}; -use std::marker::PhantomData; - -pub fn field(editor: Handle) -> EditorElement { - EditorElement { - editor, - field: true, - placeholder_text: None, - parent_state: PhantomData, - } -} - -pub struct EditorElement { - editor: Handle, - field: bool, - placeholder_text: Option, - parent_state: PhantomData, -} - -impl EditorElement { - pub fn field(mut self) -> Self { - self.field = true; - self - } - - pub fn placeholder_text(mut self, text: impl Into) -> Self { - self.placeholder_text = Some(text.into()); - self - } -} - -impl Element for EditorElement { - type State = S; - type FrameState = (); - - fn layout( - &mut self, - _: &mut Self::State, - cx: &mut ViewContext, - ) -> Result<(LayoutId, Self::FrameState)> { - self.editor.update(cx, |_editor, _cx| todo!()) - } - - fn paint( - &mut self, - _layout: Layout, - _state: &mut Self::State, - _frame_state: &mut Self::FrameState, - cx: &mut ViewContext, - ) -> Result<()> { - self.editor.update(cx, |_editor, _cx| todo!()) - } -} - -pub struct Editor {} - -impl Editor { - pub fn new(_: &mut ViewContext) -> Self { - Editor {} - } -} diff --git a/crates/gpui3/src/elements/img.rs b/crates/gpui3/src/elements/img.rs index 866f2fa971..6ff9116c41 100644 --- a/crates/gpui3/src/elements/img.rs +++ b/crates/gpui3/src/elements/img.rs @@ -1,101 +1,93 @@ -use crate as gpui2; -use crate::{ - style::{Style, StyleHelpers, Styleable}, - Element, -}; -use futures::FutureExt; -use gpui::geometry::vector::Vector2F; -use gpui::scene; -use gpui2_macros::IntoElement; +use crate::{Element, Layout, LayoutId, Result, Style, Styled}; use refineable::RefinementCascade; -use util::arc_cow::ArcCow; -use util::ResultExt; +use std::marker::PhantomData; +use util::{arc_cow::ArcCow, ResultExt}; -#[derive(IntoElement)] -pub struct Img { +pub struct Img { style: RefinementCascade