Skip to main content

Theme

Struct Theme 

Source
pub struct Theme {
    pub light: ColorScheme,
    pub dark: ColorScheme,
    pub type_scale: TypeScale,
    pub shape: ShapeScale,
    pub elevation: Elevation,
    pub motion: MotionScheme,
    pub glass: GlassScale,
    pub brightness: Brightness,
    pub design_language: DesignLanguage,
    pub extensions: ThemeExtensions,
}
Expand description

A full design-token bundle: paired light/dark color schemes, the type scale, shape scale, elevation table, and motion scheme, plus which brightness is currently active.

Fields§

§light: ColorScheme§dark: ColorScheme§type_scale: TypeScale§shape: ShapeScale§elevation: Elevation§motion: MotionScheme§glass: GlassScale

The glass material scale. GlassScale::opaque_material is the only recipe this crate constructs (and what Theme::neutral carries); a design system with translucent chrome supplies its own through ThemeBuilder::glass. Consumed by chrome widgets that branch on GlassMaterial::is_opaque.

§brightness: Brightness§design_language: DesignLanguage§extensions: ThemeExtensions

The no-lock-in typed extension slot (a Flutter ThemeExtension analog) — see crate::extensions and Theme::extension. Arc-backed internally, so cloning a Theme (required at both delivery paths — the process-global override slot and the reactive provide_context copy) stays cheap regardless of how many extensions are attached.

Implementations§

Source§

impl Theme

Source

pub fn neutral() -> Self

The neutral, design-language-free baseline theme — the only Theme this crate constructs, and the floor every shell falls back to when no design system seeded one via set_default_theme (see docs/ARCHITECTURE.md’s Theme delivery). Material, Cupertino, and Glyph each assemble their own baseline in their own plugin crate.

Composes: a plain grayscale surface/on-surface ramp plus one restrained slate-blue accent (ColorScheme::neutral_light/ColorScheme::neutral_dark); a numeric type scale resolved against a generic system-font stack with no bundled font bytes referenced (TypeScale::neutral); the ShapeScale::neutral/Elevation::neutral value tables — the M3 numbers reused rather than re-authored, since neither is actually M3-branded in value (Elevation::neutral’s own module docs call its shadow math “TUNABLE, not an M3-published spec”, and GlassScale::opaque_material already reuses Elevation::neutral the same way); a no-overshoot MotionScheme::neutral; and GlassScale::opaque_material (already neutral). Attaches StatusPalette::neutral, since success/warning/info are a functional signal, not a design-language “look” — the same reasoning neutral_light/neutral_dark use to keep error real red instead of grayscaling it too.

Starts in Brightness::Light.

Caveat — design_language is DesignLanguage::Material3 here, the derived default, despite this baseline carrying no Material identity: the enum has no neutral variant and is not reshaped by this constructor. Branch on the tokens you actually need, not on this field, when handed a neutral() theme.

Not const: ThemeExtensions’ HashMap construction isn’t const-evaluable.

Source

pub fn scheme(&self) -> &ColorScheme

The active ColorScheme — light or dark, selected by self.brightness.

Source

pub fn with_brightness(self, brightness: Brightness) -> Self

Force this theme’s Brightness while keeping every other token — a builder over the brightness field, meant to be chained onto a baseline constructor (which hardcodes Brightness::Light) before handing the result to set_app_theme.

Framework footgun this closes: set_app_theme stores its argument as the override-wins theme (the override-wins rule — an app-set theme always beats further OS appearance reports, intentionally). A caller that forces a design language via set_app_theme(some_baseline()) therefore also silently pins brightness to Light forever, discarding whatever OS night-mode state was live a moment before. some_baseline().with_brightness(live) forces the design language without discarding brightness.

Source

pub fn from_paint_ctx<'a>(ctx: &'a PaintCtx<'_>) -> Option<&'a Theme>

Recover the active theme from a widget’s PaintCtx, or None if none was threaded into the paint pass (a supported state — a pre-theme app or a bare-core test).

A one-line convenience wrapper over PaintCtx::theme_as::<Theme>() so a themed widget writes Theme::from_paint_ctx(ctx) in its paint.

Source

pub fn from_layout_ctx<'a>(ctx: &'a LayoutCtx<'_>) -> Option<&'a Theme>

Recover the active theme from a widget’s LayoutCtx, or None if none was threaded into the layout pass. The layout-pass mirror of Theme::from_paint_ctx.

Source

pub fn extension<T: Any + Send + Sync>(&self) -> Option<&T>

Recover a typed extension previously attached via self.extensions.insert::<T>(..), or None if nothing of that type was ever attached — see crate::extensions’ module docs for the no-lock-in rationale. A one-line convenience wrapper over ThemeExtensions::get.

Source

pub fn builder(base: Theme) -> ThemeBuilder

Start a crate::builder::ThemeBuilder over self as the baseline — the defineTheme/copyWith analog. See crate::builder’s module docs for the full layered-precedence contract (baseline → whole-group swaps → per-token closure edits → extensions).

Trait Implementations§

Source§

impl Clone for Theme

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Theme

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Theme

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Theme

Auto Trait Implementations§

§

impl !RefUnwindSafe for Theme

§

impl !UnwindSafe for Theme

§

impl Freeze for Theme

§

impl Send for Theme

§

impl Sync for Theme

§

impl Unpin for Theme

§

impl UnsafeUnpin for Theme

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> StorageAccess<T> for T

Source§

fn as_borrowed(&self) -> &T

Borrows the value.
Source§

fn into_taken(self) -> T

Takes the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.