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.
Trait Implementations§
impl Copy for Ink
Source§impl From<SystemColor> for Ink
impl From<SystemColor> for Ink
Source§fn from(role: SystemColor) -> Ink
fn from(role: SystemColor) -> Ink
Source§impl IntoReactive<Ink, IntoMark<Animated<Color>>> for Animated<Color>
An animated color goes wherever an ink or a paint does: .background(fade).
impl IntoReactive<Ink, IntoMark<Animated<Color>>> for Animated<Color>
An animated color goes wherever an ink or a paint does: .background(fade).
fn into_reactive(self) -> Reactive<Ink>
Source§impl IntoReactive<Ink, IntoMark<Color>> for Color
impl IntoReactive<Ink, IntoMark<Color>> for Color
fn into_reactive(self) -> Reactive<Ink>
Source§impl IntoReactive<Ink, IntoMark<Signal<Color>>> for Signal<Color>
impl IntoReactive<Ink, IntoMark<Signal<Color>>> for Signal<Color>
fn into_reactive(self) -> Reactive<Ink>
Source§impl IntoReactive<Ink, IntoMark<Signal<SystemColor>>> for Signal<SystemColor>
impl IntoReactive<Ink, IntoMark<Signal<SystemColor>>> for Signal<SystemColor>
fn into_reactive(self) -> Reactive<Ink>
Source§impl IntoReactive<Ink, IntoMark<SystemColor>> for SystemColor
impl IntoReactive<Ink, IntoMark<SystemColor>> for SystemColor
fn into_reactive(self) -> Reactive<Ink>
Source§impl<F> IntoReactive<Ink, IntoMark<fn() -> Color>> for F
impl<F> IntoReactive<Ink, IntoMark<fn() -> Color>> for F
fn into_reactive(self) -> Reactive<Ink>
Source§impl<F> IntoReactive<Ink, IntoMark<fn() -> SystemColor>> for Fwhere
F: Fn() -> SystemColor + 'static,
impl<F> IntoReactive<Ink, IntoMark<fn() -> SystemColor>> for Fwhere
F: Fn() -> SystemColor + 'static,
fn into_reactive(self) -> Reactive<Ink>
Source§impl IntoReactive<Paint, IntoMark<Ink>> for Ink
impl IntoReactive<Paint, IntoMark<Ink>> for Ink
fn into_reactive(self) -> Reactive<Paint>
Source§impl Lerp for Ink
Inks blend per appearance (docs/color.md “Inks in motion”). Two fixed colors or two light/dark
pairs blend each side in OKLab, so the in-between value still follows an appearance switch. A
SystemColor role has no color of its own until the toolkit answers
it, so a blend that involves one resolves the role against Palette::both and blends the
pair.
The endpoints are exact: t == 1 is to itself, role and all, so the settled value follows
the platform again.
impl Lerp for Ink
Inks blend per appearance (docs/color.md “Inks in motion”). Two fixed colors or two light/dark
pairs blend each side in OKLab, so the in-between value still follows an appearance switch. A
SystemColor role has no color of its own until the toolkit answers
it, so a blend that involves one resolves the role against Palette::both and blends the
pair.
The endpoints are exact: t == 1 is to itself, role and all, so the settled value follows
the platform again.
impl StructuralPartialEq for Ink
Auto Trait Implementations§
impl Forget for Ink
impl Freeze for Ink
impl Move for Ink
impl RefUnwindSafe for Ink
impl Send for Ink
impl Sync for Ink
impl Unpin for Ink
impl UnsafeUnpin for Ink
impl UnwindSafe for Ink
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more