pub struct Theme {
pub id: ThemeId,
pub appearance: ThemeAppearance,
pub colors: ColorTokens,
pub layout: LayoutTokens,
pub typography: TypographyTokens,
pub shape: ShapeTokens,
pub motion: MotionTokens,
pub input: InputTokens,
pub style_slots: ComponentStyleSlots,
pub extensions: ThemeExtensions,
}Fields§
§id: ThemeIdStable identity of this theme — see ThemeId. Serde-defaulted so
older serialized themes (which predate the field) still deserialize.
appearance: ThemeAppearance§colors: ColorTokens§layout: LayoutTokens§typography: TypographyTokens§shape: ShapeTokens§motion: MotionTokens§input: InputTokensInput and density tokens — target sizes, gesture slop, scroll physics
and the touch kill switch. See InputTokens and
docs/density-and-targets.md.
Serde-defaulted for the same reason Theme::id is: Theme
derives Deserialize, and a theme serialized before this field existed
must still load. The default is the Compact ladder — today’s behaviour.
style_slots: ComponentStyleSlotsTyped Rc<dyn FooStyle> slot bag for theme-wide style
installations. None per slot means “use the widget’s local
Recipe*Style default”; apps install per-theme overrides via
theme.style_slots.button = Some(Rc::new(MyButton)). Per-call
.style(...) on a widget always wins over the slot.
extensions: ThemeExtensionsImplementations§
Source§impl Theme
impl Theme
Sourcepub fn new(
appearance: ThemeAppearance,
colors: ColorTokens,
layout: LayoutTokens,
typography: TypographyTokens,
shape: ShapeTokens,
motion: MotionTokens,
input: InputTokens,
) -> Self
pub fn new( appearance: ThemeAppearance, colors: ColorTokens, layout: LayoutTokens, typography: TypographyTokens, shape: ShapeTokens, motion: MotionTokens, input: InputTokens, ) -> Self
Build a Theme from raw token data. Most apps go through a
preset constructor (e.g. teksilo_core::presets::intui::light)
rather than calling this directly — presets aggregate the
matching Recipe*Style defaults under the same call.
Sourcepub fn with_density_projection(
self,
project: fn(&Theme, TargetDensity) -> Theme,
) -> Self
pub fn with_density_projection( self, project: fn(&Theme, TargetDensity) -> Theme, ) -> Self
Register how this theme re-derives itself for another density. Preset
constructors call this; see DensityProjection.
Sourcepub fn with_id(self, id: impl Into<Cow<'static, str>>) -> Self
pub fn with_id(self, id: impl Into<Cow<'static, str>>) -> Self
Set this theme’s ThemeId and return self for chaining. Used by
preset constructors and apps building custom themes.
Sourcepub fn is_dark(&self) -> bool
pub fn is_dark(&self) -> bool
Whether this theme paints on a dark background. Convenience for
theme.appearance.is_dark().
Sourcepub fn for_inactive_window(&self) -> Theme
pub fn for_inactive_window(&self) -> Theme
A copy of this theme projected for an inactive window — the accent
family and focus indicators desaturated toward graphite (see
ColorTokens::for_inactive_window).
The paint walker swaps this in when the host window loses focus, so every
accent-coloured control greys out with no per-widget code. Only the
colours change; typography / layout / shape / motion are untouched, so
this never affects layout.
Sourcepub fn for_high_contrast(&self) -> Theme
pub fn for_high_contrast(&self) -> Theme
Project into a high-contrast variant (WCAG 1.4.6 Enhanced / EN 301 549
§11.7), applied at paint time when the OS “increase contrast” preference
is set. See
ColorTokens::for_high_contrast.
Sourcepub fn with_density(&self, density: TargetDensity) -> Theme
pub fn with_density(&self, density: TargetDensity) -> Theme
A copy of this theme projected onto another TargetDensity.
This is a token projection only: it replaces Self::input with
InputTokens::for_density and carries style_slots and extensions
across verbatim. It deliberately does not re-run any recipe
constructor, because there is nothing in such a theme to re-run — every
ComponentStyleSlots slot is None in a raw-token theme and in the
IntUI preset, and each
widget builds its Recipe*Style lazily at its own build site, in
teksilo-widgets, from ctx.theme().input. Changing the tokens here is
therefore sufficient; the widgets read the new values on their next
build.
A slot an app has installed itself is Some(..) and is preserved as it
is, so a custom Tier-3 style keeps whatever dimensions it was written
with. That is intentional (a hand-written style owns its own metrics)
but it means a custom style is not density-aware unless its author made
it so.
A theme that carries a DensityProjection — every shipped preset that
installs slots — takes that function’s answer instead, so its own chrome
does follow the density.
Use WidgetTree::set_input_density rather than calling this and
set_theme by hand: a density change must rebuild, not merely relayout.
Sourcepub fn extension<T: Any + Send + Sync>(&self) -> Option<&T>
pub fn extension<T: Any + Send + Sync>(&self) -> Option<&T>
Look up a typed theme extension. See ThemeExtensions.
Sourcepub fn with_extension<T: Any + Send + Sync>(self, value: T) -> Self
pub fn with_extension<T: Any + Send + Sync>(self, value: T) -> Self
Attach a typed extension and return self for chaining. See
ThemeExtensions.