pub struct Theme {Show 27 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,
pub platform: TargetPlatform,
pub page_transitions: PageTransitionsTheme,
pub user_interface_level: CupertinoUserInterfaceLevelData,
pub cupertino_override_theme: Option<Box<CupertinoThemeData>>,
pub cupertino_theme: Option<Box<CupertinoThemeData>>,
pub visual_density: Option<VisualDensity>,
}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.
platform: TargetPlatformThe platform whose conventions the widgets follow: how a list scrolls past its
end, where a bar puts its title, how a page arrives. default_target_platform
unless said otherwise, so an application can show another platform’s behaviour,
for the whole of it or for a subtree, and a test can try each
(Theme::with_platform).
page_transitions: PageTransitionsThemeHow a page arrives and leaves, platform by platform: the reference’s defaults
unless said otherwise — the desktops zoom, Apple’s platforms slide, Android fades
forwards (milestone 620). The theme’s Theme::platform picks the builder.
user_interface_level: CupertinoUserInterfaceLevelDataHow high the subtree sits: on the window’s surface, or raised above it in a sheet
or a dialog. Base unless a subtree
says otherwise with
CupertinoUserInterfaceLevelData::around;
the adaptive colours read it (milestone 627).
cupertino_override_theme: Option<Box<CupertinoThemeData>>What the Apple-style widgets take differently from this theme — the reference’s
cupertinoOverrideTheme. Unset, they take this theme’s primary colour, the colour on
it, its background and its brightness, and Apple’s defaults for the rest (milestone
628). See CupertinoTheme::of.
cupertino_theme: Option<Box<CupertinoThemeData>>A subtree’s own Apple-style theme, which replaces the one above with Apple’s
defaults under it. Set by CupertinoTheme::around.
visual_density: Option<VisualDensity>How compact the controls are, if the application says
(Theme::with_visual_density). Unset, the theme’s platform decides: standard on
phones, compact on the desktops — see Theme::visual_density (milestone 631).
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 with_platform(self, platform: TargetPlatform) -> Self
pub fn with_platform(self, platform: TargetPlatform) -> Self
The same theme, following platform’s conventions (Theme::platform).
Sourcepub fn with_cupertino_override_theme(self, data: CupertinoThemeData) -> Self
pub fn with_cupertino_override_theme(self, data: CupertinoThemeData) -> Self
The same theme, its Apple-style widgets taking what data sets instead of what this
theme would give them (Theme::cupertino_override_theme).
Sourcepub fn with_visual_density(self, density: VisualDensity) -> Self
pub fn with_visual_density(self, density: VisualDensity) -> Self
The same theme, its controls at density whatever the platform.
Sourcepub fn visual_density(&self) -> VisualDensity
pub fn visual_density(&self) -> VisualDensity
How compact the controls are: the density the theme was given, else the one its
platform takes (the reference’s ThemeData.visualDensity,
theme_data.dart:412). Buttons, checkboxes, radios, chips, icon buttons and list
tiles grow or shrink by it.
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.