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: GlassScaleThe 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: ThemeExtensionsThe 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
impl Theme
Sourcepub fn neutral() -> Self
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.
Sourcepub fn scheme(&self) -> &ColorScheme
pub fn scheme(&self) -> &ColorScheme
The active ColorScheme — light or dark, selected by
self.brightness.
Sourcepub fn with_brightness(self, brightness: Brightness) -> Self
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.
Sourcepub fn from_paint_ctx<'a>(ctx: &'a PaintCtx<'_>) -> Option<&'a Theme>
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.
Sourcepub fn from_layout_ctx<'a>(ctx: &'a LayoutCtx<'_>) -> Option<&'a Theme>
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.
Sourcepub fn extension<T: Any + Send + Sync>(&self) -> Option<&T>
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.
Sourcepub fn builder(base: Theme) -> ThemeBuilder
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).