From dd34bb273e72ab4e1445e491f71ce66aaec6544d Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 25 Oct 2023 15:50:50 +0200 Subject: [PATCH] Load `Theme` from `theme2` into the storybook --- Cargo.lock | 1 + crates/storybook2/src/storybook2.rs | 14 +++++++++++--- crates/ui2/Cargo.toml | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3b14f2dbc3..9db01b9e07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9364,6 +9364,7 @@ dependencies = [ "smallvec", "strum", "theme", + "theme2", ] [[package]] diff --git a/crates/storybook2/src/storybook2.rs b/crates/storybook2/src/storybook2.rs index 0d85119af3..7f7cbfa150 100644 --- a/crates/storybook2/src/storybook2.rs +++ b/crates/storybook2/src/storybook2.rs @@ -10,13 +10,15 @@ use std::sync::Arc; use clap::Parser; use gpui2::{ - div, px, size, view, AnyView, AppContext, Bounds, Context, Element, ViewContext, - WindowBounds, WindowOptions, + div, px, size, view, AnyView, AppContext, Bounds, Context, Element, ViewContext, WindowBounds, + WindowOptions, }; use log::LevelFilter; use simplelog::SimpleLogger; use story_selector::ComponentStory; +use theme2::ThemeRegistry; use ui::{prelude::*, themed}; +use util::ResultExt; use crate::assets::Assets; use crate::story_selector::StorySelector; @@ -48,7 +50,7 @@ fn main() { let story_selector = args.story.clone(); let theme_name = args.theme.unwrap_or("One Dark".to_string()); - let theme = themes::load_theme(theme_name).unwrap(); + let theme = themes::load_theme(theme_name.clone()).unwrap(); let asset_source = Arc::new(Assets); gpui2::App::production(asset_source).run(move |cx| { @@ -57,6 +59,12 @@ fn main() { let selector = story_selector.unwrap_or(StorySelector::Component(ComponentStory::Workspace)); + let theme_registry = cx.default_global::(); + + if let Some(new_theme) = theme_registry.get(&theme_name).log_err() { + cx.set_global(new_theme); + } + cx.set_global(theme.clone()); ui::settings::init(cx); diff --git a/crates/ui2/Cargo.toml b/crates/ui2/Cargo.toml index 3e9769a54c..6778249c28 100644 --- a/crates/ui2/Cargo.toml +++ b/crates/ui2/Cargo.toml @@ -14,6 +14,7 @@ settings = { path = "../settings" } smallvec.workspace = true strum = { version = "0.25.0", features = ["derive"] } theme = { path = "../theme" } +theme2 = { path = "../theme2" } rand = "0.8" [features]