pub struct Theme {
pub name: &'static str,
pub scheme: ColorScheme,
pub metrics: Metrics,
pub depth: u8,
/* private fields */
}Expand description
A complete set of colours and geometry.
Fields§
§name: &'static strHuman-readable name, for diagnostics and theme pickers.
scheme: ColorSchemeWhether this theme is light or dark.
metrics: MetricsGeometry tokens.
depth: u8Elevation emphasis, 0 for flat.
Not a blur. A widget honours this by lightening its top edge and darkening its bottom edge by roughly this much, which stays inside its own bounds and so costs the damage tracker nothing.
Implementations§
Source§impl Theme
impl Theme
Sourcepub const fn from_seeds(
name: &'static str,
scheme: ColorScheme,
base: Color,
primary: Color,
secondary: Color,
accent: Color,
neutral: Color,
info: Color,
success: Color,
warning: Color,
error: Color,
) -> Theme
pub const fn from_seeds( name: &'static str, scheme: ColorScheme, base: Color, primary: Color, secondary: Color, accent: Color, neutral: Color, info: Color, success: Color, warning: Color, error: Color, ) -> Theme
Builds a theme from nine seed colours, deriving the rest.
The two recessed base surfaces and all nine content colours are computed.
This is a const fn, so the built-in themes cost nothing at runtime and
cannot drift out of step with the derivation rules the way a hand-written
table would.
Sourcepub const fn from_seeds_at(
name: &'static str,
scheme: ColorScheme,
target: u32,
base: Color,
primary: Color,
secondary: Color,
accent: Color,
neutral: Color,
info: Color,
success: Color,
warning: Color,
error: Color,
) -> Theme
pub const fn from_seeds_at( name: &'static str, scheme: ColorScheme, target: u32, base: Color, primary: Color, secondary: Color, accent: Color, neutral: Color, info: Color, success: Color, warning: Color, error: Color, ) -> Theme
Theme::from_seeds at a chosen contrast target.
Derivation stops at the first mix that clears the target, so a theme built
at AA will generally not also satisfy AAA. A theme that exists to be
legible in glare should say so here rather than hope.
Sourcepub const fn content_of(self, role: Role) -> Color
pub const fn content_of(self, role: Role) -> Color
The colour to draw on top of role.
Sourcepub const fn pair(self, role: Role) -> (Color, Color)
pub const fn pair(self, role: Role) -> (Color, Color)
A surface and its readable foreground, in that order.
Sourcepub const fn radius(self, which: Radius) -> i32
pub const fn radius(self, which: Radius) -> i32
The corner radius for a widget class, in logical pixels.
Sourcepub const fn with_metrics(self, metrics: Metrics) -> Theme
pub const fn with_metrics(self, metrics: Metrics) -> Theme
This theme with different geometry.
Sourcepub fn scaled(self, scale: f32) -> Theme
pub fn scaled(self, scale: f32) -> Theme
This theme with its geometry at scale — the one theme call a
scale-aware application makes at construction.
Only the metrics scale; colours have no size. The layout rectangles and
text sizes are the application’s own numbers and scale through
Rect::scaled and TextStyle::scaled in the
same one place. See docs/design.md for why the application, not the
tree, does the multiplying.
Sourcepub const fn with_depth(self, depth: u8) -> Theme
pub const fn with_depth(self, depth: u8) -> Theme
This theme with a different elevation emphasis.
Sourcepub const fn with_color(self, role: Role, color: Color) -> Theme
pub const fn with_color(self, role: Role, color: Color) -> Theme
This theme with one role overridden.
Overriding a surface does not re-derive its content partner; override
that too, or run Theme::validate.
Sourcepub fn validate(self, target: u32) -> Result<(), ContrastFailure>
pub fn validate(self, target: u32) -> Result<(), ContrastFailure>
Checks every surface against its content partner at target.
Returns the worst offender. Worth calling at startup on a hand-written theme: grey-on-grey discovered on a factory floor is expensive, and discovered in a unit test is free.