Skip to main content

ThemeState

Struct ThemeState 

Source
pub struct ThemeState { /* private fields */ }
Expand description

Global theme state - accessed directly by widgets during render

Implementations§

Source§

impl ThemeState

Source

pub fn init(bundle: ThemeBundle, scheme: ColorScheme)

Initialize the global theme state (call once at app startup)

Source

pub fn set_scheduler(&self, scheduler: &Arc<Mutex<AnimationScheduler>>)

Set the animation scheduler for theme transitions

This should be called by the app layer after the window is created to enable animated theme transitions.

Source

pub fn init_default()

Initialize with platform-native theme and system color scheme

Detects the current OS and uses the appropriate native theme:

  • macOS: Apple Human Interface Guidelines theme
  • Windows: Fluent Design System 2 theme
  • Linux: GNOME Adwaita theme
Source

pub fn get() -> &'static ThemeState

Get the global theme state instance

Source

pub fn try_get() -> Option<&'static ThemeState>

Try to get the global theme state (returns None if not initialized)

Source

pub fn scheme(&self) -> ColorScheme

Get the current color scheme

Source

pub fn set_scheme(&self, scheme: ColorScheme)

Set the color scheme (animates colors if scheduler is available)

Source

pub fn tick(&self) -> bool

Update theme colors based on animation progress

This should be called during the render loop to update interpolated colors. Returns true if animation is still in progress and needs more frames.

Source

pub fn is_animating(&self) -> bool

Check if a theme transition animation is in progress

Source

pub fn toggle_scheme(&self)

Toggle between light and dark mode

Source

pub fn color(&self, token: ColorToken) -> Color

Get a color token value (checks override first)

Source

pub fn colors(&self) -> ColorTokens

Get all color tokens

Source

pub fn set_color_override(&self, token: ColorToken, color: Color)

Set a color override (triggers repaint only)

Source

pub fn remove_color_override(&self, token: ColorToken)

Remove a color override

Source

pub fn to_css_variable_map(&self) -> HashMap<String, String>

Generate a CSS variable map from all color tokens.

Returns a HashMap<String, String> where keys are variable names (without -- prefix) and values are hex color strings. Variable names match the theme() CSS function token names.

§Example
let vars = ThemeState::get().to_css_variable_map();
// vars["text-primary"] == "#1a1a2e"
// vars["surface"] == "#ffffff"
Source

pub fn spacing_value(&self, token: SpacingToken) -> f32

Get a spacing token value (checks override first)

Source

pub fn spacing(&self) -> SpacingTokens

Get all spacing tokens

Source

pub fn set_spacing_override(&self, token: SpacingToken, value: f32)

Set a spacing override (triggers layout)

Source

pub fn remove_spacing_override(&self, token: SpacingToken)

Remove a spacing override

Source

pub fn typography(&self) -> TypographyTokens

Get all typography tokens

Source

pub fn radius(&self, token: RadiusToken) -> f32

Get a radius token value (checks override first)

Source

pub fn radii(&self) -> RadiusTokens

Get all radius tokens

Source

pub fn set_radius_override(&self, token: RadiusToken, value: f32)

Set a radius override (triggers repaint - radii don’t affect layout)

Source

pub fn shadows(&self) -> ShadowTokens

Get all shadow tokens

Source

pub fn animations(&self) -> AnimationTokens

Get all animation tokens

Source

pub fn needs_repaint(&self) -> bool

Check if theme changes require repaint

Source

pub fn clear_repaint(&self)

Clear the repaint flag

Source

pub fn needs_layout(&self) -> bool

Check if theme changes require layout

Source

pub fn clear_layout(&self)

Clear the layout flag

Source

pub fn clear_overrides(&self)

Clear all overrides

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more