pub struct ThemeState { /* private fields */ }Expand description
Global theme state - accessed directly by widgets during render
Implementations§
Source§impl ThemeState
impl ThemeState
Sourcepub fn init(bundle: ThemeBundle, scheme: ColorScheme)
pub fn init(bundle: ThemeBundle, scheme: ColorScheme)
Initialize the global theme state (call once at app startup)
Sourcepub fn set_scheduler(&self, scheduler: &Arc<Mutex<AnimationScheduler>>)
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.
Sourcepub fn init_default()
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
Sourcepub fn get() -> &'static ThemeState
pub fn get() -> &'static ThemeState
Get the global theme state instance
Sourcepub fn try_get() -> Option<&'static ThemeState>
pub fn try_get() -> Option<&'static ThemeState>
Try to get the global theme state (returns None if not initialized)
Sourcepub fn scheme(&self) -> ColorScheme
pub fn scheme(&self) -> ColorScheme
Get the current color scheme
Sourcepub fn set_scheme(&self, scheme: ColorScheme)
pub fn set_scheme(&self, scheme: ColorScheme)
Set the color scheme (animates colors if scheduler is available)
Sourcepub fn tick(&self) -> bool
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.
Sourcepub fn is_animating(&self) -> bool
pub fn is_animating(&self) -> bool
Check if a theme transition animation is in progress
Sourcepub fn toggle_scheme(&self)
pub fn toggle_scheme(&self)
Toggle between light and dark mode
Sourcepub fn color(&self, token: ColorToken) -> Color
pub fn color(&self, token: ColorToken) -> Color
Get a color token value (checks override first)
Sourcepub fn colors(&self) -> ColorTokens
pub fn colors(&self) -> ColorTokens
Get all color tokens
Sourcepub fn set_color_override(&self, token: ColorToken, color: Color)
pub fn set_color_override(&self, token: ColorToken, color: Color)
Set a color override (triggers repaint only)
Sourcepub fn remove_color_override(&self, token: ColorToken)
pub fn remove_color_override(&self, token: ColorToken)
Remove a color override
Sourcepub fn to_css_variable_map(&self) -> HashMap<String, String>
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"Sourcepub fn spacing_value(&self, token: SpacingToken) -> f32
pub fn spacing_value(&self, token: SpacingToken) -> f32
Get a spacing token value (checks override first)
Sourcepub fn spacing(&self) -> SpacingTokens
pub fn spacing(&self) -> SpacingTokens
Get all spacing tokens
Sourcepub fn set_spacing_override(&self, token: SpacingToken, value: f32)
pub fn set_spacing_override(&self, token: SpacingToken, value: f32)
Set a spacing override (triggers layout)
Sourcepub fn remove_spacing_override(&self, token: SpacingToken)
pub fn remove_spacing_override(&self, token: SpacingToken)
Remove a spacing override
Sourcepub fn typography(&self) -> TypographyTokens
pub fn typography(&self) -> TypographyTokens
Get all typography tokens
Sourcepub fn radius(&self, token: RadiusToken) -> f32
pub fn radius(&self, token: RadiusToken) -> f32
Get a radius token value (checks override first)
Sourcepub fn radii(&self) -> RadiusTokens
pub fn radii(&self) -> RadiusTokens
Get all radius tokens
Sourcepub fn set_radius_override(&self, token: RadiusToken, value: f32)
pub fn set_radius_override(&self, token: RadiusToken, value: f32)
Set a radius override (triggers repaint - radii don’t affect layout)
Sourcepub fn shadows(&self) -> ShadowTokens
pub fn shadows(&self) -> ShadowTokens
Get all shadow tokens
Sourcepub fn animations(&self) -> AnimationTokens
pub fn animations(&self) -> AnimationTokens
Get all animation tokens
Sourcepub fn needs_repaint(&self) -> bool
pub fn needs_repaint(&self) -> bool
Check if theme changes require repaint
Sourcepub fn clear_repaint(&self)
pub fn clear_repaint(&self)
Clear the repaint flag
Sourcepub fn needs_layout(&self) -> bool
pub fn needs_layout(&self) -> bool
Check if theme changes require layout
Sourcepub fn clear_layout(&self)
pub fn clear_layout(&self)
Clear the layout flag
Sourcepub fn clear_overrides(&self)
pub fn clear_overrides(&self)
Clear all overrides