Remove themed
wrapper
This commit is contained in:
parent
b31a004def
commit
7b4e699d0e
3 changed files with 11 additions and 101 deletions
|
@ -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;
|
||||
|
|
|
@ -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<V, E, F>(theme: Theme, cx: &mut ViewContext<V>, build_child: F) -> Themed<E>
|
||||
where
|
||||
V: 'static,
|
||||
E: Element<V>,
|
||||
F: FnOnce(&mut ViewContext<V>) -> E,
|
||||
{
|
||||
cx.default_global::<ThemeStack>().0.push(theme.clone());
|
||||
let child = build_child(cx);
|
||||
cx.default_global::<ThemeStack>().0.pop();
|
||||
Themed { theme, child }
|
||||
}
|
||||
|
||||
pub struct Themed<E> {
|
||||
pub(crate) theme: Theme,
|
||||
pub(crate) child: E,
|
||||
}
|
||||
|
||||
impl<V, E> Component<V> for Themed<E>
|
||||
where
|
||||
V: 'static,
|
||||
E: 'static + Element<V> + Send,
|
||||
E::ElementState: Send,
|
||||
{
|
||||
fn render(self) -> AnyElement<V> {
|
||||
AnyElement::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct ThemeStack(Vec<Theme>);
|
||||
|
||||
impl<V, E: 'static + Element<V> + Send> Element<V> for Themed<E>
|
||||
where
|
||||
V: 'static,
|
||||
E::ElementState: Send,
|
||||
{
|
||||
type ElementState = E::ElementState;
|
||||
|
||||
fn id(&self) -> Option<gpui2::ElementId> {
|
||||
None
|
||||
}
|
||||
|
||||
fn initialize(
|
||||
&mut self,
|
||||
view_state: &mut V,
|
||||
element_state: Option<Self::ElementState>,
|
||||
cx: &mut ViewContext<V>,
|
||||
) -> Self::ElementState {
|
||||
cx.default_global::<ThemeStack>().0.push(self.theme.clone());
|
||||
let element_state = self.child.initialize(view_state, element_state, cx);
|
||||
cx.default_global::<ThemeStack>().0.pop();
|
||||
element_state
|
||||
}
|
||||
|
||||
fn layout(
|
||||
&mut self,
|
||||
view_state: &mut V,
|
||||
element_state: &mut Self::ElementState,
|
||||
cx: &mut ViewContext<V>,
|
||||
) -> LayoutId
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
cx.default_global::<ThemeStack>().0.push(self.theme.clone());
|
||||
let layout_id = self.child.layout(view_state, element_state, cx);
|
||||
cx.default_global::<ThemeStack>().0.pop();
|
||||
layout_id
|
||||
}
|
||||
|
||||
fn paint(
|
||||
&mut self,
|
||||
bounds: Bounds<Pixels>,
|
||||
view_state: &mut V,
|
||||
frame_state: &mut Self::ElementState,
|
||||
cx: &mut ViewContext<V>,
|
||||
) where
|
||||
Self: Sized,
|
||||
{
|
||||
cx.default_global::<ThemeStack>().0.push(self.theme.clone());
|
||||
self.child.paint(bounds, view_state, frame_state, cx);
|
||||
cx.default_global::<ThemeStack>().0.pop();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn old_theme(cx: &WindowContext) -> Arc<Theme> {
|
||||
Arc::new(cx.global::<Theme>().clone())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue