Skip to main content

ColorScheme

Struct ColorScheme 

Source
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: Brightness

Whether 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: Color

The app’s main accent: the colour of prominent controls, such as a filled button, and of active states.

§on_primary: Color

What is legible on primary.

§primary_container: Color

A quieter fill in the primary hue, for larger surfaces such as a tonal button.

§on_primary_container: Color

What is legible on primary_container.

§primary_fixed: Color

A 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: Color

The 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: Color

What is legible on both of them — tone 10, dark enough to read on the dimmer of the two.

§on_primary_fixed_variant: Color

The quieter of the two things that can be written there: a subtitle where on_primary_fixed is the title. Tone 30.

§secondary: Color

The supporting accent, for the less prominent controls: a filter chip, say.

§on_secondary: Color

What is legible on secondary.

§secondary_container: Color

A quieter fill in the secondary hue, for larger surfaces.

§on_secondary_container: Color

What is legible on secondary_container.

§secondary_fixed: Color

The supporting accent’s fixed container {em} see primary_fixed for what “fixed” promises.

§secondary_fixed_dim: Color

The stronger of that pair.

§on_secondary_fixed: Color

What is legible on both.

§on_secondary_fixed_variant: Color

The quieter thing that can be written there.

§tertiary: Color

A 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: Color

What is legible on tertiary.

§tertiary_container: Color

A quieter fill in the tertiary hue, for larger surfaces.

§on_tertiary_container: Color

What is legible on tertiary_container.

§tertiary_fixed: Color

The third accent’s fixed container {em} see primary_fixed for what “fixed” promises.

§tertiary_fixed_dim: Color

The stronger of that pair.

§on_tertiary_fixed: Color

What is legible on both.

§on_tertiary_fixed_variant: Color

The quieter thing that can be written there.

§background: Color

The colour of the page behind everything.

§surface: Color

The base colour of the surfaces that sit on the page: cards, sheets, dialogs.

§on_surface: Color

What is legible on surface and on the background: the main text and icon colour.

§surface_variant: Color

A discreet tonal surface (zone backgrounds, tracks).

§on_surface_variant: Color

Secondary content on surfaces (the historical muted).

§surface_container_lowest: Color

The 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: Color

Less emphasis than Self::surface_container: cards off the page, banners, drawers, sheets.

§surface_container: Color

A distinct area within the surface: menus, navigation bars.

§surface_container_high: Color

More emphasis than Self::surface_container: dialogs, search views.

§surface_container_highest: Color

The most emphasis against the surface: filled cards, filled fields.

§inverse_surface: Color

An inverted surface (toasts and snackbars that stand out from the background).

§on_inverse_surface: Color

What is legible on inverse_surface.

§outline: Color

Outlines at rest.

§outline_variant: Color

Discreet outlines (thin separators).

§error: Color

The colour of errors: an invalid field, a failure.

§on_error: Color

What is legible on error.

§error_container: Color

The 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: Color

What is legible on error_container.

§inverse_primary: Color

The 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: Color

What 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: Color

The darkest surface in either theme, and the lightest — the two ends the container ladder runs between.

§surface_bright: Color

The lightest surface in either theme — the other end of the ladder from surface_dim.

§scrim: Color

The scrim for modals and drawers (the alpha is applied at the point of use).

§shadow: Color

The color of drop shadows (the alpha is applied at the point of use).

Implementations§

Source§

impl ColorScheme

Source

pub fn dark() -> Self

The dark scheme.

Source

pub fn light() -> Self

The light scheme.

Source

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.

Source

pub fn lerp(&self, other: &ColorScheme, t: f32) -> ColorScheme

Interpolates role by role toward other (the light/dark switch fade).

Trait Implementations§

Source§

impl Clone for ColorScheme

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ColorScheme

Source§

impl Debug for ColorScheme

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for ColorScheme

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ColorScheme

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<Msg> IntoMsg<Msg> for Msg

Source§

fn defer(work: impl Fn() -> Msg + 'static) -> Msg

The message that stands for work’s result.
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.