Skip to main content

Theme

Struct Theme 

Source
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 str

Human-readable name, for diagnostics and theme pickers.

§scheme: ColorScheme

Whether this theme is light or dark.

§metrics: Metrics

Geometry tokens.

§depth: u8

Elevation 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

Source

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.

Source

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.

Source

pub const fn color(self, role: Role) -> Color

The colour for a role.

Source

pub const fn content_of(self, role: Role) -> Color

The colour to draw on top of role.

Source

pub const fn pair(self, role: Role) -> (Color, Color)

A surface and its readable foreground, in that order.

Source

pub const fn radius(self, which: Radius) -> i32

The corner radius for a widget class, in logical pixels.

Source

pub const fn with_metrics(self, metrics: Metrics) -> Theme

This theme with different geometry.

Source

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.

Source

pub const fn with_depth(self, depth: u8) -> Theme

This theme with a different elevation emphasis.

Source

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.

Source

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.

Source§

impl Theme

Source

pub const DARK: Theme = DARK

See DARK.

Source

pub const LIGHT: Theme = LIGHT

See LIGHT.

Source

pub const HIGH_CONTRAST: Theme = HIGH_CONTRAST

Source

pub const BUILT_IN: [Theme; 3]

Every theme that ships with Denise.

Trait Implementations§

Source§

impl Clone for Theme

Source§

fn clone(&self) -> Theme

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 Theme

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

Source§

impl PartialEq for Theme

Source§

fn eq(&self, other: &Theme) -> 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<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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.