Skip to main content

Ink

Enum Ink 

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

Fields

§light: Color
§dark: Color
§

System

A platform role, resolved by the toolkit. alpha, when set, replaces the role’s own opacity.

Fields

§alpha: Option<f64>

Implementations§

Source§

impl Ink

Source

pub const CLEAR: Ink

Transparent.

Source

pub const fn adaptive(light: Color, dark: Color) -> Ink

light in the light appearance and dark in the dark one.

Source

pub const fn system(role: SystemColor) -> Ink

The platform’s color for role.

Source

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.

Source

pub const fn fixed(self) -> Option<Color>

The color, when it is the same in every appearance.

Source

pub const fn is_dynamic(self) -> bool

Whether the ink depends on the appearance or the platform: a pair or a role.

Source

pub fn resolve(self, palette: &Palette) -> Color

The color this ink is in palette’s appearance.

Source

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.

Source

pub fn wire(self) -> [u32; 3]

The ink as three numbers for a shim in another language (Java, C++, JS): [kind, a, b].

kindab
0 fixedthe color as 0xAARRGGBB0
1 pairthe light color as 0xAARRGGBBthe dark color
2 rolethe role’s wire numberthe alpha override as 0..=255, or 256 for none

Channels are rounded to 8 bits. Ink::from_wire reads it back.

Source

pub fn from_wire(wire: [u32; 3]) -> Option<Ink>

The ink Ink::wire encoded, if the numbers are one.

Source

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.

Source

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§

Source§

impl Clone for Ink

Source§

fn clone(&self) -> Ink

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 Ink

Source§

impl Debug for Ink

Source§

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

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

impl Default for Ink

Source§

fn default() -> Ink

Transparent.

Source§

impl From<Color> for Ink

Source§

fn from(c: Color) -> Ink

Converts to this type from the input type.
Source§

impl From<Ink> for Paint

Source§

fn from(ink: Ink) -> Paint

Converts to this type from the input type.
Source§

impl From<SystemColor> for Ink

Source§

fn from(role: SystemColor) -> Ink

Converts to this type from the input type.
Source§

impl IntoReactive<Ink, IntoMark<Animated<Color>>> for Animated<Color>

An animated color goes wherever an ink or a paint does: .background(fade).

Source§

impl IntoReactive<Ink, IntoMark<Color>> for Color

Source§

impl IntoReactive<Ink, IntoMark<Signal<Color>>> for Signal<Color>

Source§

impl IntoReactive<Ink, IntoMark<Signal<SystemColor>>> for Signal<SystemColor>

Source§

impl IntoReactive<Ink, IntoMark<SystemColor>> for SystemColor

Source§

impl<F> IntoReactive<Ink, IntoMark<fn() -> Color>> for F
where F: Fn() -> Color + 'static,

Source§

impl<F> IntoReactive<Ink, IntoMark<fn() -> SystemColor>> for F
where F: Fn() -> SystemColor + 'static,

Source§

impl IntoReactive<Paint, IntoMark<Ink>> for Ink

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.

Source§

fn lerp(&self, to: &Ink, t: f64) -> Ink

Source§

impl PartialEq for Ink

Source§

fn eq(&self, other: &Ink) -> 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 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnyEq for T
where T: Any + PartialEq,

Source§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

Source§

fn as_any(&self) -> &(dyn Any + 'static)

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> ErasedDestructor for T
where T: 'static,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> IntoReactive<T, StaticMark> for T
where T: Clone + 'static,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.