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
impl Palette
Sourcepub const fn with(self, role: ColorRole, light: Color, dark: Color) -> Self
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.
Sourcepub const fn with_light(self, role: ColorRole, light: Color) -> Self
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.
Sourcepub const fn with_dark(self, role: ColorRole, dark: Color) -> Self
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.
Sourcepub const fn get(&self, role: ColorRole, scheme: ColorScheme) -> Option<Color>
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.
Sourcepub fn entries(&self) -> impl Iterator<Item = PaletteEntry> + '_
pub fn entries(&self) -> impl Iterator<Item = PaletteEntry> + '_
Every value this palette gives, in role order with light before dark.
pub fn is_empty(&self) -> bool
Sourcepub fn write_into(&self, out: &mut Vec<u8>)
pub fn write_into(&self, out: &mut Vec<u8>)
Writes the entries as the wire carries them, eight bytes each.
Sourcepub fn resolve(&self, system: DesignSystem, scheme: ColorScheme) -> [Color; 45]
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.
Sourcepub fn check(&self, system: DesignSystem) -> Vec<PaletteViolation>
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.