Skip to main content

Palette

Struct Palette 

Source
pub struct Palette { /* private fields */ }
Expand description

The colours one application gives some of the roles, per scheme.

A role the application did not give keeps the design system’s value, separately in each scheme: giving Primary for light only leaves dark Primary to the system.

Built in a const, so a theme that carries it stays Copy and can be a const too:

use compose_rust::{Color, ColorRole, DesignSystem, Palette, Theme};

const EMBER: Palette = Palette::new()
    .with(ColorRole::Primary, Color::rgb(0xE8590C), Color::rgb(0xFF8A4C))
    .with(ColorRole::OnPrimary, Color::rgb(0xFFFFFF), Color::rgb(0x2B0E00))
    .with(ColorRole::Background, Color::rgb(0xFFFBF8), Color::rgb(0x141110));

const THEME: Theme = Theme::adaptive(DesignSystem::Material3).with_palette(&EMBER);

Implementations§

Source§

impl Palette

Source

pub const fn new() -> Self

A palette that changes nothing.

Source

pub const fn with(self, role: ColorRole, light: Color, dark: Color) -> Self

Gives a role its colour in both schemes.

Two values rather than one, because one colour used for both is almost always wrong in one of them: a deep orange chosen for a light page sinks into a dark one.

Source

pub const fn with_light(self, role: ColorRole, light: Color) -> Self

Gives a role its colour in the light scheme only. Dark keeps the system’s.

Source

pub const fn with_dark(self, role: ColorRole, dark: Color) -> Self

Gives a role its colour in the dark scheme only. Light keeps the system’s.

Source

pub const fn get(&self, role: ColorRole, scheme: ColorScheme) -> Option<Color>

The colour this palette gives a role in a scheme, or None where it leaves the system’s. FollowSystem is not a scheme and has no answer.

Source

pub fn entries(&self) -> impl Iterator<Item = PaletteEntry> + '_

Every value this palette gives, in role order with light before dark.

Source

pub fn len(&self) -> usize

How many values this palette gives.

Source

pub fn is_empty(&self) -> bool

Source

pub fn write_into(&self, out: &mut Vec<u8>)

Writes the entries as the wire carries them, eight bytes each.

Source

pub fn resolve(&self, system: DesignSystem, scheme: ColorScheme) -> [Color; 45]

Every role’s colour in one scheme of one design system, with this palette on top.

This is the Renderer’s resolution, written out where a test can reach it. A role the palette gives is that value. A role it does not give is the system’s, except for one case: a fill the palette gives whose ink it does not. The system’s ink is kept if it still holds the contrast that pair is held to on the new fill, and otherwise the ink is white or black, whichever holds more. Orange takes the system’s white where white reads on it, and a yellow brand takes black.

Only that direction. An ink given without its fill was meant, and if it does not read the thing to correct is the palette.

Source

pub fn check(&self, system: DesignSystem) -> Vec<PaletteViolation>

The pairs this palette, laid over a design system’s table, leaves short of the contrast or the separation they are held to. Empty where nothing is.

The bounds are the ones the system tables themselves are tested against: accent inks 3:1 on their fills, reading inks and container inks 4.5:1, every syntax ink 4.5:1 on the code panel, each diff ink 4.5:1 on its own line background and the body ink 4.5:1 on both, and a container, a line background or a word background that has to be told apart from what is behind it actually is. An application calls this from its own tests, once for each of the seven systems.

Trait Implementations§

Source§

impl Clone for Palette

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 Palette

Source§

impl Debug for Palette

Source§

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

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

impl Default for Palette

Source§

fn default() -> Self

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

impl Eq for Palette

Source§

impl PartialEq for Palette

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 Palette

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