Skip to main content

ThemeExt

Trait ThemeExt 

Source
pub trait ThemeExt: Theme {
    // Provided methods
    fn tokens(&self) -> DesignTokens { ... }
    fn design_tokens(&self) -> &DesignTokens { ... }
    fn typography(&self) -> TypographyScale { ... }
    fn typography_ref(&self) -> &TypographyScale { ... }
    fn is_high_contrast(&self) -> bool { ... }
    fn effective_palette(&self) -> Palette { ... }
    fn extended_palette(&self) -> ExtendedPalette { ... }
}
Expand description

Extension trait adding design tokens, typography, and the extended palette to any Theme.

Implemented for every Theme via a blanket impl, returning the COOLJAPAN defaults. Concrete themes may override these methods for custom token sets.

Provided Methods§

Source

fn tokens(&self) -> DesignTokens

The theme’s design-token scale (spacing / radius / elevation / opacity).

Returns by value for flexibility; use ThemeExt::design_tokens for a reference-returning variant backed by a process-lifetime static.

Source

fn design_tokens(&self) -> &DesignTokens

Returns a reference to the DesignTokens for this theme.

The default implementation stores the default tokens in a OnceLock-backed static so that the reference lifetime is 'static. Override this method in concrete theme structs that own a DesignTokens field to return a reference to that field instead.

Source

fn typography(&self) -> TypographyScale

The theme’s typographic scale (returned by value).

Use ThemeExt::typography_ref for a reference-returning variant.

Source

fn typography_ref(&self) -> &TypographyScale

Returns a reference to the TypographyScale for this theme.

Backed by a OnceLock-bound static in the blanket impl. Override in concrete structs that carry a TypographyScale field.

Source

fn is_high_contrast(&self) -> bool

Returns true if this theme is designed for high-contrast display.

The default returns false. Override in high-contrast theme variants.

Source

fn effective_palette(&self) -> Palette

Returns the effective Palette, with contrast boosted if the OS or user has requested high-contrast mode via the OXIUI_HIGH_CONTRAST environment variable.

When the env var is set to "1" or "true" (case-insensitive) and the theme is not already a high-contrast theme, a simple contrast-boost is applied: the background and surface colours are blended slightly toward black to deepen dark tones.

Source

fn extended_palette(&self) -> ExtendedPalette

The extended semantic palette, derived from Theme::palette.

dark is inferred from the background luminance: backgrounds darker than mid-grey are treated as dark themes for status-colour selection.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: Theme + ?Sized> ThemeExt for T