pub struct Theme {
pub name: String,
pub author: Option<String>,
pub url: Option<String>,
pub color_scheme: Option<ColorScheme>,
pub colors: ThemeColors,
pub metrics: ThemeMetrics,
/* private fields */
}Fields§
§name: String§url: Option<String>§color_scheme: Option<ColorScheme>§colors: ThemeColors§metrics: ThemeMetricsImplementations§
Source§impl Theme
impl Theme
pub fn revision(&self) -> u64
pub fn color(&self, key: ThemeColorKey) -> Color
pub fn metric(&self, key: ThemeMetricKey) -> Px
pub fn color_by_key(&self, key: &str) -> Option<Color>
pub fn color_required(&self, key: &str) -> Color
Sourcepub fn color_token(&self, key: &str) -> Color
pub fn color_token(&self, key: &str) -> Color
Non-panicking theme token access with diagnostics + fallback behavior.
Sourcepub fn syntax_color(&self, highlight: &str) -> Option<Color>
pub fn syntax_color(&self, highlight: &str) -> Option<Color>
Resolve a syntax highlight tag (e.g. keyword.operator) into a theme color.
Lookup order:
color.syntax.<highlight>- prefix fallback:
color.syntax.keyword.operator->color.syntax.keyword - built-in semantic fallbacks for common highlight roots
Sourcepub fn named_color(&self, key: ThemeNamedColorKey) -> Color
pub fn named_color(&self, key: ThemeNamedColorKey) -> Color
Resolves a named (non-semantic) color token used by upstream ecosystems (e.g. text-white).
pub fn metric_by_key(&self, key: &str) -> Option<Px>
pub fn metric_required(&self, key: &str) -> Px
Sourcepub fn metric_token(&self, key: &str) -> Px
pub fn metric_token(&self, key: &str) -> Px
Non-panicking theme token access with diagnostics + fallback behavior.
pub fn corners_by_key(&self, key: &str) -> Option<Corners>
pub fn corners_required(&self, key: &str) -> Corners
Sourcepub fn corners_token(&self, key: &str) -> Corners
pub fn corners_token(&self, key: &str) -> Corners
Non-panicking theme token access with diagnostics + fallback behavior.
pub fn number_by_key(&self, key: &str) -> Option<f32>
pub fn number_required(&self, key: &str) -> f32
Sourcepub fn number_token(&self, key: &str) -> f32
pub fn number_token(&self, key: &str) -> f32
Non-panicking theme token access with diagnostics + fallback behavior.
pub fn duration_ms_by_key(&self, key: &str) -> Option<u32>
pub fn duration_ms_required(&self, key: &str) -> u32
Sourcepub fn duration_ms_token(&self, key: &str) -> u32
pub fn duration_ms_token(&self, key: &str) -> u32
Non-panicking theme token access with diagnostics + fallback behavior.
pub fn easing_by_key(&self, key: &str) -> Option<CubicBezier>
pub fn easing_required(&self, key: &str) -> CubicBezier
Sourcepub fn easing_token(&self, key: &str) -> CubicBezier
pub fn easing_token(&self, key: &str) -> CubicBezier
Non-panicking theme token access with diagnostics + fallback behavior.
pub fn text_style_by_key(&self, key: &str) -> Option<TextStyle>
pub fn text_style_required(&self, key: &str) -> TextStyle
Sourcepub fn text_style_token(&self, key: &str) -> TextStyle
pub fn text_style_token(&self, key: &str) -> TextStyle
Non-panicking theme token access with diagnostics + fallback behavior.
pub fn color_key_configured(&self, key: &str) -> bool
pub fn metric_key_configured(&self, key: &str) -> bool
pub fn corners_key_configured(&self, key: &str) -> bool
pub fn number_key_configured(&self, key: &str) -> bool
pub fn duration_ms_key_configured(&self, key: &str) -> bool
pub fn easing_key_configured(&self, key: &str) -> bool
pub fn text_style_key_configured(&self, key: &str) -> bool
pub fn snapshot(&self) -> ThemeSnapshot
pub fn global<H: UiHost>(app: &H) -> &Theme
pub fn with_global_mut<H: UiHost, R>( app: &mut H, f: impl FnOnce(&mut Theme) -> R, ) -> R
pub fn apply_config(&mut self, cfg: &ThemeConfig)
Sourcepub fn extend_tokens_from_config(&mut self, cfg: &ThemeConfig)
pub fn extend_tokens_from_config(&mut self, cfg: &ThemeConfig)
Merge additional tokens from a ThemeConfig into the current theme without resetting the
baseline theme (colors/metrics) or the configured-key tracking sets.
This is intended for ecosystem-driven design system presets (e.g. Material 3) that need to inject extra token kinds (motion/state/typography) on top of an existing theme preset (e.g. a shadcn color scheme in the gallery app).
Sourcepub fn apply_config_patch(&mut self, cfg: &ThemeConfig)
pub fn apply_config_patch(&mut self, cfg: &ThemeConfig)
Apply a ThemeConfig as a patch layered on top of the current theme.
Unlike Self::apply_config, this does not reset any existing token tables. This is
the intended API for app-level overrides (e.g. “compact editor” metric tweaks) layered on
top of an ecosystem preset (e.g. shadcn New York).
This updates the configured_* tracking sets by adding the keys present in cfg and
increments the theme revision when the effective token tables change.