Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add storybook3
Conrad Irwin547888942f59
diff --git a/Cargo.lock b/Cargo.lockindex bf2e964ea8f..a364cbce647 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -8802,6 +8802,17 @@ dependencies = ["util",]+[[package]]+name = "storybook3"+version = "0.1.0"+dependencies = [+ "anyhow",+ "gpui2",+ "settings2",+ "theme2",+ "ui2",+]+[[package]]name = "stringprep"version = "0.1.4"diff --git a/Cargo.toml b/Cargo.tomlindex f8d0af77fa8..f107dc5390a 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -95,6 +95,7 @@ members = ["crates/sqlez_macros","crates/rich_text","crates/storybook2",+ "crates/storybook3","crates/sum_tree","crates/terminal","crates/terminal2",diff --git a/crates/storybook2/src/storybook2.rs b/crates/storybook2/src/storybook2.rsindex c4c1d75eac2..1481ab9fb4b 100644--- a/crates/storybook2/src/storybook2.rs+++ b/crates/storybook2/src/storybook2.rs@@ -66,7 +66,6 @@ fn main() {story_selector.unwrap_or(StorySelector::Component(ComponentStory::Workspace));let theme_registry = cx.global::<ThemeRegistry>();-let mut theme_settings = ThemeSettings::get_global(cx).clone();theme_settings.active_theme = theme_registry.get(&theme_name).unwrap();ThemeSettings::override_global(theme_settings, cx);@@ -114,6 +113,7 @@ impl Render for StoryWrapper {.flex().flex_col().size_full()+ .font("Zed Mono").child(self.story.clone())}}diff --git a/crates/storybook3/Cargo.toml b/crates/storybook3/Cargo.tomlnew file mode 100644index 00000000000..8b04e4d44b3--- /dev/null+++ b/crates/storybook3/Cargo.toml@@ -0,0 +1,17 @@+[package]+name = "storybook3"+version = "0.1.0"+edition = "2021"+publish = false++[[bin]]+name = "storybook"+path = "src/storybook3.rs"++[dependencies]+anyhow.workspace = true++gpui = { package = "gpui2", path = "../gpui2" }+ui = { package = "ui2", path = "../ui2", features = ["stories"] }+theme = { package = "theme2", path = "../theme2", features = ["stories"] }+settings = { package = "settings2", path = "../settings2"}diff --git a/crates/storybook3/src/storybook3.rs b/crates/storybook3/src/storybook3.rsnew file mode 100644index 00000000000..b73bb8c563a--- /dev/null+++ b/crates/storybook3/src/storybook3.rs@@ -0,0 +1,75 @@+use anyhow::Result;+use gpui::AssetSource;+use gpui::{+ div, hsla, px, size, AnyView, Bounds, Div, Render, ViewContext, VisualContext, WindowBounds,+ WindowOptions,+};+use settings::{default_settings, Settings, SettingsStore};+use std::borrow::Cow;+use std::sync::Arc;+use theme::ThemeSettings;+use ui::{prelude::*, ContextMenuStory};++struct Assets;++impl AssetSource for Assets {+ fn load(&self, _path: &str) -> Result<Cow<[u8]>> {+ todo!();+ }++ fn list(&self, _path: &str) -> Result<Vec<SharedString>> {+ Ok(vec![])+ }+}++fn main() {+ let asset_source = Arc::new(Assets);+ gpui::App::production(asset_source).run(move |cx| {+ let mut store = SettingsStore::default();+ store+ .set_default_settings(default_settings().as_ref(), cx)+ .unwrap();+ cx.set_global(store);+ ui::settings::init(cx);+ theme::init(cx);++ cx.open_window(+ WindowOptions {+ bounds: WindowBounds::Fixed(Bounds {+ origin: Default::default(),+ size: size(px(1500.), px(780.)).into(),+ }),+ ..Default::default()+ },+ move |cx| {+ let ui_font_size = ThemeSettings::get_global(cx).ui_font_size;+ cx.set_rem_size(ui_font_size);++ cx.build_view(|cx| TestView {+ story: cx.build_view(|_| ContextMenuStory).into(),+ })+ },+ );++ cx.activate(true);+ })+}++struct TestView {+ story: AnyView,+}++impl Render for TestView {+ type Element = Div<Self>;++ fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {+ div()+ .p(px(10.))+ .bg(hsla(1., 1., 1., 0.))+ .flex()+ .flex_col()+ .size_full()+ .font("Helvetica")+ .child(self.story.clone())+ }+}diff --git a/crates/ui2/src/story.rs b/crates/ui2/src/story.rsindex 94e38267f4c..c98cfa012f2 100644--- a/crates/ui2/src/story.rs+++ b/crates/ui2/src/story.rs@@ -12,7 +12,6 @@ impl Story {.flex_col().pt_2().px_4()- .font("Zed Mono").bg(cx.theme().colors().background)}