pub struct Theme {Show 21 fields
pub scheme: ColorScheme,
pub background: Color,
pub surface: Color,
pub primary: Color,
pub on_primary: Color,
pub on_surface: Color,
pub muted: Color,
pub border: Color,
pub focus: Color,
pub selection: Color,
pub primary_container: Color,
pub on_primary_container: Color,
pub error: Color,
pub on_error: Color,
pub outline_variant: Color,
pub text: TextTheme,
pub radius: f32,
pub spacing: f32,
pub direction: TextDirection,
pub widgets: WidgetThemes,
pub tap_target: TapTarget,
}Expand description
A set of style tokens.
The ColorScheme (theme.scheme) is the source of truth for the colors;
the “flat” fields (background, surface, primary, …) are convenience
views of the most used roles, derived from the scheme — the widgets’
historical API stays intact. focus/selection are interaction accents
specific to frus (outside the M3 roles).
Fields§
§scheme: ColorSchemeThe color roles (the source of truth).
background: ColorThe application’s background (= scheme.background).
surface: ColorThe surfaces’ background (= scheme.surface).
primary: ColorThe accent color (= scheme.primary).
on_primary: ColorText and content on primary (= scheme.on_primary).
on_surface: ColorThe default text on surfaces (= scheme.on_surface).
muted: ColorSecondary text and discreet elements (= scheme.on_surface_variant).
border: ColorBorders at rest (= scheme.outline).
focus: ColorThe focus accent (a frus interaction accent, outside the scheme).
selection: ColorThe text selection highlight (likewise).
primary_container: ColorThe tonal accent container (= scheme.primary_container).
on_primary_container: ColorContent on primary_container (= scheme.on_primary_container).
error: ColorThe error or danger color (= scheme.error).
on_error: ColorContent on error (= scheme.on_error).
outline_variant: ColorThe discreet outline variant (= scheme.outline_variant).
text: TextThemeThe named typographic scale (Material’s 15 steps).
radius: f32The default corner radius.
spacing: f32The base spacing unit.
direction: TextDirectionThe ambient reading and layout direction (LTR by default). In RTL, the
driver mirrors the layout horizontally. Carried here (an ambient context
threaded down to paint) pending a dedicated Env (§2).
widgets: WidgetThemesPer-widget defaults: what a widget looks like when the caller has not said,
resolved as caller ?? theme ?? framework. Empty by default — a theme that sets
nothing behaves exactly as if there were none. See
WidgetThemes.
tap_target: TapTargetHow much room the small controls reserve for a finger (TapTarget).
Padded by default, as it is over there: a switch, a
checkbox, a radio and an icon button each lay out inside at least
MIN_TAP_TARGET and paint what they paint in the middle of it.
Implementations§
Source§impl Theme
impl Theme
Sourcepub fn from_scheme(scheme: ColorScheme, focus: Color, selection: Color) -> Self
pub fn from_scheme(scheme: ColorScheme, focus: Color, selection: Color) -> Self
Builds a theme from a scheme: the flat fields are derived from the roles, so there is a single source of truth.
Sourcepub fn from_seed(seed: Color, dark: bool) -> Self
pub fn from_seed(seed: Color, dark: bool) -> Self
A theme generated from a seed color (see ColorScheme::from_seed). The
focus ring and the selection derive from the scheme’s primary (interaction
roles specific to frus, outside the M3 scheme).
Sourcepub fn brightness(&self) -> Brightness
pub fn brightness(&self) -> Brightness
Whether this theme is a light one or a dark one (ThemeData.brightness).
The scheme is the source of truth for the colours, so it is the source of truth for this too — a theme cannot be dark and hold a light scheme.
Widgets that have two sets of numbers, one per brightness, ask this. They used to compare the surface’s luminance against a half, which agrees with it nearly always and is a guess either way.
Sourcepub fn state_layer(&self, base: Color, on: Color, status: &Status) -> Color
pub fn state_layer(&self, base: Color, on: Color, status: &Status) -> Color
Applies the Material state layer over base: it overlays the content
color on at low opacity according to the interaction state — hover 8%,
focus 10%, press 12% — taking the animated progressions into account
(hover_progress/focus_progress/press_progress). This is the state rule
baked into the theme: widgets stay declarative (they pass their base color and
their content color, and the theme decides on the overlay).
All three terms are progressions, the press included. It read the flag until
milestone 441, which meant that term could only ever be 0 or 12%: the layer
arrived whole under a finger and vanished whole when it left. Reading
press_progress is what lets it fade, and reading the flag as well would defeat
that — the term would reach full on the first frame and the fade would never run.