Skip to main content

Theme

Struct Theme 

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

The color roles (the source of truth).

§background: Color

The application’s background (= scheme.background).

§surface: Color

The surfaces’ background (= scheme.surface).

§primary: Color

The accent color (= scheme.primary).

§on_primary: Color

Text and content on primary (= scheme.on_primary).

§on_surface: Color

The default text on surfaces (= scheme.on_surface).

§muted: Color

Secondary text and discreet elements (= scheme.on_surface_variant).

§border: Color

Borders at rest (= scheme.outline).

§focus: Color

The focus accent (a frus interaction accent, outside the scheme).

§selection: Color

The text selection highlight (likewise).

§primary_container: Color

The tonal accent container (= scheme.primary_container).

§on_primary_container: Color

Content on primary_container (= scheme.on_primary_container).

§error: Color

The error or danger color (= scheme.error).

§on_error: Color

Content on error (= scheme.on_error).

§outline_variant: Color

The discreet outline variant (= scheme.outline_variant).

§text: TextTheme

The named typographic scale (Material’s 15 steps).

§radius: f32

The default corner radius.

§spacing: f32

The base spacing unit.

§direction: TextDirection

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

Per-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: TapTarget

How 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

Source

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.

Source

pub fn rtl(self) -> Self

The same theme in right-to-left (Arabic, Hebrew…).

Source

pub fn dark() -> Self

The dark theme.

Source

pub fn light() -> Self

The light theme.

Source

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).

Source

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.

Source

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.

Source§

impl Theme

Source

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

Interpolates toward other at progress t (0 = self, 1 = other). Used for the theme fade when switching light and dark. The scheme is interpolated role by role and the flat fields are re-derived from it (a single source of truth, even mid-fade).

Trait Implementations§

Source§

impl Clone for Theme

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 Debug for Theme

Source§

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

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

impl Default for Theme

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Theme

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 Theme

Auto Trait Implementations§

§

impl Freeze for Theme

§

impl RefUnwindSafe for Theme

§

impl Send for Theme

§

impl Sync for Theme

§

impl Unpin for Theme

§

impl UnsafeUnpin for Theme

§

impl UnwindSafe for Theme

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> 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.