mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-07 20:39:04 +03:00
Add storybook3
This commit is contained in:
parent
074a221e0f
commit
547888942f
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -8802,6 +8802,17 @@ dependencies = [
|
|||||||
"util",
|
"util",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "storybook3"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"gpui2",
|
||||||
|
"settings2",
|
||||||
|
"theme2",
|
||||||
|
"ui2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stringprep"
|
name = "stringprep"
|
||||||
version = "0.1.4"
|
version = "0.1.4"
|
||||||
|
@ -95,6 +95,7 @@ members = [
|
|||||||
"crates/sqlez_macros",
|
"crates/sqlez_macros",
|
||||||
"crates/rich_text",
|
"crates/rich_text",
|
||||||
"crates/storybook2",
|
"crates/storybook2",
|
||||||
|
"crates/storybook3",
|
||||||
"crates/sum_tree",
|
"crates/sum_tree",
|
||||||
"crates/terminal",
|
"crates/terminal",
|
||||||
"crates/terminal2",
|
"crates/terminal2",
|
||||||
|
@ -66,7 +66,6 @@ fn main() {
|
|||||||
story_selector.unwrap_or(StorySelector::Component(ComponentStory::Workspace));
|
story_selector.unwrap_or(StorySelector::Component(ComponentStory::Workspace));
|
||||||
|
|
||||||
let theme_registry = cx.global::<ThemeRegistry>();
|
let theme_registry = cx.global::<ThemeRegistry>();
|
||||||
|
|
||||||
let mut theme_settings = ThemeSettings::get_global(cx).clone();
|
let mut theme_settings = ThemeSettings::get_global(cx).clone();
|
||||||
theme_settings.active_theme = theme_registry.get(&theme_name).unwrap();
|
theme_settings.active_theme = theme_registry.get(&theme_name).unwrap();
|
||||||
ThemeSettings::override_global(theme_settings, cx);
|
ThemeSettings::override_global(theme_settings, cx);
|
||||||
@ -114,6 +113,7 @@ impl Render for StoryWrapper {
|
|||||||
.flex()
|
.flex()
|
||||||
.flex_col()
|
.flex_col()
|
||||||
.size_full()
|
.size_full()
|
||||||
|
.font("Zed Mono")
|
||||||
.child(self.story.clone())
|
.child(self.story.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
crates/storybook3/Cargo.toml
Normal file
17
crates/storybook3/Cargo.toml
Normal file
@ -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"}
|
75
crates/storybook3/src/storybook3.rs
Normal file
75
crates/storybook3/src/storybook3.rs
Normal file
@ -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())
|
||||||
|
}
|
||||||
|
}
|
@ -12,7 +12,6 @@ impl Story {
|
|||||||
.flex_col()
|
.flex_col()
|
||||||
.pt_2()
|
.pt_2()
|
||||||
.px_4()
|
.px_4()
|
||||||
.font("Zed Mono")
|
|
||||||
.bg(cx.theme().colors().background)
|
.bg(cx.theme().colors().background)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user