diff --git a/crates/storybook2/src/storybook2.rs b/crates/storybook2/src/storybook2.rs index a06a1392b2..493997ccfe 100644 --- a/crates/storybook2/src/storybook2.rs +++ b/crates/storybook2/src/storybook2.rs @@ -18,7 +18,7 @@ use settings2::{default_settings, Settings, SettingsStore}; use simplelog::SimpleLogger; use story_selector::ComponentStory; use theme2::{ThemeRegistry, ThemeSettings}; -use ui::{prelude::*, themed}; +use ui::prelude::*; use crate::assets::Assets; use crate::story_selector::StorySelector; @@ -86,7 +86,7 @@ fn main() { }, move |cx| { cx.build_view( - |cx| StoryWrapper::new(selector.story(cx), theme), + |cx| StoryWrapper::new(selector.story(cx)), StoryWrapper::render, ) }, @@ -99,22 +99,19 @@ fn main() { #[derive(Clone)] pub struct StoryWrapper { story: AnyView, - theme: Theme, } impl StoryWrapper { - pub(crate) fn new(story: AnyView, theme: Theme) -> Self { - Self { story, theme } + pub(crate) fn new(story: AnyView) -> Self { + Self { story } } fn render(&mut self, cx: &mut ViewContext) -> impl Component { - themed(self.theme.clone(), cx, |cx| { - div() - .flex() - .flex_col() - .size_full() - .child(self.story.clone()) - }) + div() + .flex() + .flex_col() + .size_full() + .child(self.story.clone()) } } diff --git a/crates/ui2/src/prelude.rs b/crates/ui2/src/prelude.rs index b8143b6e50..95cd6ffa6d 100644 --- a/crates/ui2/src/prelude.rs +++ b/crates/ui2/src/prelude.rs @@ -5,7 +5,7 @@ pub use gpui2::{ pub use crate::elevation::*; use crate::settings::user_settings; -pub use crate::{old_theme, theme, ButtonVariant, Theme}; +pub use crate::{old_theme, theme, ButtonVariant}; use gpui2::{rems, Hsla, Rems}; use strum::EnumIter; diff --git a/crates/ui2/src/theme.rs b/crates/ui2/src/theme.rs index cc46ddcb17..f160a24da3 100644 --- a/crates/ui2/src/theme.rs +++ b/crates/ui2/src/theme.rs @@ -1,7 +1,4 @@ -use gpui2::{ - AnyElement, AppContext, Bounds, Component, Element, Hsla, LayoutId, Pixels, Result, - ViewContext, WindowContext, -}; +use gpui2::{AppContext, Hsla, Result, WindowContext}; use serde::{de::Visitor, Deserialize, Deserializer}; use std::collections::HashMap; use std::fmt; @@ -132,90 +129,6 @@ where deserializer.deserialize_map(SyntaxVisitor) } -pub fn themed(theme: Theme, cx: &mut ViewContext, build_child: F) -> Themed -where - V: 'static, - E: Element, - F: FnOnce(&mut ViewContext) -> E, -{ - cx.default_global::().0.push(theme.clone()); - let child = build_child(cx); - cx.default_global::().0.pop(); - Themed { theme, child } -} - -pub struct Themed { - pub(crate) theme: Theme, - pub(crate) child: E, -} - -impl Component for Themed -where - V: 'static, - E: 'static + Element + Send, - E::ElementState: Send, -{ - fn render(self) -> AnyElement { - AnyElement::new(self) - } -} - -#[derive(Default)] -struct ThemeStack(Vec); - -impl + Send> Element for Themed -where - V: 'static, - E::ElementState: Send, -{ - type ElementState = E::ElementState; - - fn id(&self) -> Option { - None - } - - fn initialize( - &mut self, - view_state: &mut V, - element_state: Option, - cx: &mut ViewContext, - ) -> Self::ElementState { - cx.default_global::().0.push(self.theme.clone()); - let element_state = self.child.initialize(view_state, element_state, cx); - cx.default_global::().0.pop(); - element_state - } - - fn layout( - &mut self, - view_state: &mut V, - element_state: &mut Self::ElementState, - cx: &mut ViewContext, - ) -> LayoutId - where - Self: Sized, - { - cx.default_global::().0.push(self.theme.clone()); - let layout_id = self.child.layout(view_state, element_state, cx); - cx.default_global::().0.pop(); - layout_id - } - - fn paint( - &mut self, - bounds: Bounds, - view_state: &mut V, - frame_state: &mut Self::ElementState, - cx: &mut ViewContext, - ) where - Self: Sized, - { - cx.default_global::().0.push(self.theme.clone()); - self.child.paint(bounds, view_state, frame_state, cx); - cx.default_global::().0.pop(); - } -} - pub fn old_theme(cx: &WindowContext) -> Arc { Arc::new(cx.global::().clone()) }