pub enum Ink {
Fixed(Color),
Adaptive {
light: Color,
dark: Color,
},
System {
role: SystemColor,
alpha: Option<f64>,
},
}Expand description
The color a view is drawn in: a fixed color, a light/dark pair, or a platform role
(docs/color.md). Every color parameter of a view takes impl Into<Ink>, so
Color::rgb(..), SystemColor::Separator and Ink::adaptive(light, dark) go anywhere a
color does, and an Ink is a const:
use day_spec::{Color, Ink, SystemColor};
const INSET: Ink = Ink::adaptive(Color::rgba(0.0, 0.0, 0.0, 0.045), Color::rgba(0.0, 0.0, 0.0, 0.26));
const HAIRLINE: Ink = Ink::system(SystemColor::Separator);
const BRAND: Ink = Ink::Fixed(Color::hex(0x00e8_6a3c));A view keeps the ink, not a color resolved from it: the toolkit resolves it natively and
follows an appearance switch with no app code running. Code that needs the numbers (a
canvas, a contrast check) resolves an ink with day::resolve(ink), a tracked read that
re-runs the reader when the appearance changes.
Variants§
Fixed(Color)
The same color in every appearance.
Adaptive
light in the light appearance, dark in the dark one.
System
A platform role, resolved by the toolkit. alpha, when set, replaces the role’s own
opacity.
Implementations§
Source§impl Ink
impl Ink
Sourcepub const fn adaptive(light: Color, dark: Color) -> Ink
pub const fn adaptive(light: Color, dark: Color) -> Ink
light in the light appearance and dark in the dark one.
Sourcepub const fn system(role: SystemColor) -> Ink
pub const fn system(role: SystemColor) -> Ink
The platform’s color for role.
Sourcepub const fn with_alpha(self, alpha: f64) -> Ink
pub const fn with_alpha(self, alpha: f64) -> Ink
The same ink at opacity alpha in every appearance: both colors of a pair, and the
role’s color with its own alpha replaced.
Sourcepub const fn is_dynamic(self) -> bool
pub const fn is_dynamic(self) -> bool
Whether the ink depends on the appearance or the platform: a pair or a role.
Sourcepub fn resolve(self, palette: &Palette) -> Color
pub fn resolve(self, palette: &Palette) -> Color
The color this ink is in palette’s appearance.
Sourcepub fn resolved(self) -> Color
pub fn resolved(self) -> Color
The color this ink is right now, against the Palette::current Day keeps for the
app’s appearance. What a toolkit without dynamic colors applies, and re-applies when
the appearance changes (docs/color.md “How a toolkit follows the appearance”). Not
tracked: app code reads day::resolve(ink) instead.
Sourcepub fn wire(self) -> [u32; 3]
pub fn wire(self) -> [u32; 3]
The ink as three numbers for a shim in another language (Java, C++, JS): [kind, a, b].
| kind | a | b |
|---|---|---|
0 fixed | the color as 0xAARRGGBB | 0 |
1 pair | the light color as 0xAARRGGBB | the dark color |
2 role | the role’s wire number | the alpha override as 0..=255, or 256 for none |
Channels are rounded to 8 bits. Ink::from_wire reads it back.
Sourcepub fn from_wire(wire: [u32; 3]) -> Option<Ink>
pub fn from_wire(wire: [u32; 3]) -> Option<Ink>
The ink Ink::wire encoded, if the numbers are one.
Sourcepub fn pair(self, light: &Palette, dark: &Palette) -> (Color, Color)
pub fn pair(self, light: &Palette, dark: &Palette) -> (Color, Color)
The pair this ink resolves to in the light and the dark appearance, roles answered
from light and dark. What a toolkit builds one dynamic native color from.
Sourcepub fn map(self, f: impl Fn(Color) -> Color) -> Ink
pub fn map(self, f: impl Fn(Color) -> Color) -> Ink
A new ink made by applying f to this one’s color in each appearance: the readable
text color on a fill, a darker shade of a brand color. A fixed ink stays fixed; a pair
maps both sides; a role is resolved against Palette::both first, so the result is a
pair that no longer follows a later change of the system accent.