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
The design-token vocabulary: the Theme bundle plus its
component token tables, flat-re-exported from frust-theme so app code
never names that crate directly. A root component reads the active theme via
use_context::<Theme>(); a widget reads it during paint/layout via
PaintCtx::theme_as/LayoutCtx::theme_as (or Theme::from_paint_ctx).
Includes the glass material tokens — this crate ships the opaque recipe, and a design system authors its own translucent one over the same types:
use frust::GlassScale;
let glass = GlassScale::opaque_material();
assert_eq!(glass.chrome.blur_radius_intent, 0.0);
assert!(glass.control.is_opaque());Also the composable-theming surface:
ThemeBuilder (defineTheme/copyWith analog), the no-lock-in typed
extension slot (ThemeExtensions) plus its first consumer
StatusPalette/StatusColors (success/warning/info), and the motion
vocabulary (MotionDurations/EasingSet) — all flat-re-exported so an
app (or a design-system plugin) authors a theme against frust::* alone.
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() -> Theme
pub fn neutral() -> Theme
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) -> Theme
pub fn with_brightness(self, brightness: Brightness) -> Theme
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>(&self) -> Option<&T>
pub fn extension<T>(&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).
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.