pub struct ColorScheme {Show 49 fields
pub brightness: Brightness,
pub primary: Color,
pub on_primary: Color,
pub primary_container: Color,
pub on_primary_container: Color,
pub primary_fixed: Color,
pub primary_fixed_dim: Color,
pub on_primary_fixed: Color,
pub on_primary_fixed_variant: Color,
pub secondary: Color,
pub on_secondary: Color,
pub secondary_container: Color,
pub on_secondary_container: Color,
pub secondary_fixed: Color,
pub secondary_fixed_dim: Color,
pub on_secondary_fixed: Color,
pub on_secondary_fixed_variant: Color,
pub tertiary: Color,
pub on_tertiary: Color,
pub tertiary_container: Color,
pub on_tertiary_container: Color,
pub tertiary_fixed: Color,
pub tertiary_fixed_dim: Color,
pub on_tertiary_fixed: Color,
pub on_tertiary_fixed_variant: Color,
pub background: Color,
pub surface: Color,
pub on_surface: Color,
pub surface_variant: Color,
pub on_surface_variant: Color,
pub surface_container_lowest: Color,
pub surface_container_low: Color,
pub surface_container: Color,
pub surface_container_high: Color,
pub surface_container_highest: Color,
pub inverse_surface: Color,
pub on_inverse_surface: Color,
pub outline: Color,
pub outline_variant: Color,
pub error: Color,
pub on_error: Color,
pub error_container: Color,
pub on_error_container: Color,
pub inverse_primary: Color,
pub surface_tint: Color,
pub surface_dim: Color,
pub surface_bright: Color,
pub scrim: Color,
pub shadow: Color,
}Expand description
The color roles (Material 3) — the source of truth for the theme’s
colors. Widgets reference roles, never literal colors: changing scheme recolors
the whole app and guarantees the contrast of the X/on_X pairs. Written by
hand for light and dark; from_seed (HCT) comes after.
Fields§
§brightness: BrightnessWhether this scheme is a light one or a dark one (color_scheme.dart).
It is written down rather than worked out. The surface’s luminance is usually the same answer, and “usually” is the problem: a dim scheme built from a dark seed can sit either side of the halfway line, and a widget picking its opacities from a guess picks differently on two schemes a designer considers equally dark.
The reference’s scrollbar reads exactly this field to choose the opacity of its
thumb (scrollbar.dart:232); this framework’s was guessing at it.
primary: ColorThe app’s main accent: the colour of prominent controls, such as a filled button, and of active states.
on_primary: ColorWhat is legible on primary.
primary_container: ColorA quieter fill in the primary hue, for larger surfaces such as a tonal button.
on_primary_container: ColorWhat is legible on primary_container.
primary_fixed: ColorA container that does not change when the theme does (color_scheme.dart:90).
Every other accent role is answered twice: once for a light scheme and once for a dark one. These four are answered once, and both schemes give the same answer.
That is not a shortcut, it is the whole point. A card carrying a brand colour, a
header the marketing department chose, an onboarding page whose illustration was
drawn against one particular green — anything that has to keep its colour when
the reader turns the lights off has nowhere to sit in a scheme where every role
moves. primary_container is the right emphasis for those and the wrong
promise. This is the same emphasis with the promise attached.
Tone 90 of the primary palette, which is where a light scheme’s
primary_container already sits — so in a light theme it costs nothing, and in
a dark one it is the thing that stayed put.
primary_fixed_dim: ColorThe stronger of the pair, for what needs more emphasis than
primary_fixed without giving up the promise. Tone 80,
which is a dark scheme’s primary.
on_primary_fixed: ColorWhat is legible on both of them — tone 10, dark enough to read on the dimmer of the two.
on_primary_fixed_variant: ColorThe quieter of the two things that can be written there: a subtitle where
on_primary_fixed is the title. Tone 30.
secondary: ColorThe supporting accent, for the less prominent controls: a filter chip, say.
on_secondary: ColorWhat is legible on secondary.
secondary_container: ColorA quieter fill in the secondary hue, for larger surfaces.
on_secondary_container: ColorWhat is legible on secondary_container.
secondary_fixed: ColorThe supporting accent’s fixed container {em} see
primary_fixed for what “fixed” promises.
secondary_fixed_dim: ColorThe stronger of that pair.
on_secondary_fixed: ColorWhat is legible on both.
on_secondary_fixed_variant: ColorThe quieter thing that can be written there.
tertiary: ColorA third accent, for what is neither the app’s main colour nor its supporting one: a highlight that has to stand apart from both. Generated a sixth of the way round the wheel from the seed, which is what keeps it from reading as either.
on_tertiary: ColorWhat is legible on tertiary.
tertiary_container: ColorA quieter fill in the tertiary hue, for larger surfaces.
on_tertiary_container: ColorWhat is legible on tertiary_container.
tertiary_fixed: ColorThe third accent’s fixed container {em} see
primary_fixed for what “fixed” promises.
tertiary_fixed_dim: ColorThe stronger of that pair.
on_tertiary_fixed: ColorWhat is legible on both.
on_tertiary_fixed_variant: ColorThe quieter thing that can be written there.
background: ColorThe colour of the page behind everything.
surface: ColorThe base colour of the surfaces that sit on the page: cards, sheets, dialogs.
on_surface: ColorWhat is legible on surface and on the background: the main text and
icon colour.
surface_variant: ColorA discreet tonal surface (zone backgrounds, tracks).
on_surface_variant: ColorSecondary content on surfaces (the historical muted).
surface_container_lowest: ColorThe container ladder’s lowest rung: the least emphasis against the surface. Its neighbour rather than its opposite — in a dark scheme it is darker than the surface, as the reference’s is.
surface_container_low: ColorLess emphasis than Self::surface_container: cards off the page, banners,
drawers, sheets.
surface_container: ColorA distinct area within the surface: menus, navigation bars.
surface_container_high: ColorMore emphasis than Self::surface_container: dialogs, search views.
surface_container_highest: ColorThe most emphasis against the surface: filled cards, filled fields.
inverse_surface: ColorAn inverted surface (toasts and snackbars that stand out from the background).
on_inverse_surface: ColorWhat is legible on inverse_surface.
outline: ColorOutlines at rest.
outline_variant: ColorDiscreet outlines (thin separators).
error: ColorThe colour of errors: an invalid field, a failure.
on_error: ColorWhat is legible on error.
error_container: ColorThe quiet form of error: a field’s error surface, a warning that has to be
read rather than shouted. on_error_container is what is legible on it — and it
is what an errored field’s border, label and helper take, not error itself
(input_decorator.dart:5981).
on_error_container: ColorWhat is legible on error_container.
inverse_primary: ColorThe accent as it must be drawn on inverse_surface: a snack bar’s action
(snack_bar.dart:954). primary on an inverted surface is the pair the scheme
guarantees nothing about, which is exactly why this role exists.
surface_tint: ColorWhat a raised surface is tinted towards as it lifts — primary in Material 3.
The elevation model there is a tint, not a shadow, and this is the colour it tints
with (bottom_app_bar.dart:301).
surface_dim: ColorThe darkest surface in either theme, and the lightest — the two ends the container ladder runs between.
surface_bright: ColorThe lightest surface in either theme — the other end of the ladder from
surface_dim.
scrim: ColorThe scrim for modals and drawers (the alpha is applied at the point of use).
shadow: ColorThe color of drop shadows (the alpha is applied at the point of use).
Implementations§
Source§impl ColorScheme
impl ColorScheme
Sourcepub fn from_seed(seed: Color, dark: bool) -> Self
pub fn from_seed(seed: Color, dark: bool) -> Self
Generates a complete scheme from a seed color (Material 3 “dynamic
color”, through HCT). The seed’s hue feeds five tonal
palettes (primary, secondary, tertiary — not exposed for now — and the
neutrals); each role is a precise tone of its palette, which guarantees
the contrast of the X/on_X pairs.
Deliberate departures from the M3 spec: surface sits slightly apart from
background (our cards lay a surface over the background, tones 12/6 in
dark, 100/98 in light) — the 2023 spec conflates them.
The container ladder is anchored on that surface rather than on the
spec’s. Its five rungs keep the reference’s own tonal steps — going toward
more emphasis, −4, −2, −2, −2 in light and +6, +2, +5, +5 in dark — measured
from surface_container, so every rung stands off this scheme’s surface by
what it stands off the reference’s. In light the top rung lands on tone 100,
which is where this scheme’s surface already is: the departure showing
through.
Sourcepub fn lerp(&self, other: &ColorScheme, t: f32) -> ColorScheme
pub fn lerp(&self, other: &ColorScheme, t: f32) -> ColorScheme
Interpolates role by role toward other (the light/dark switch fade).