pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}Expand description
sRGB color with straight (non-premultiplied) alpha, components in 0..=1.
Interpolation (Lerp) happens in OKLab.
Fields§
§r: f32Red, 0..=1 (sRGB-encoded).
g: f32Green, 0..=1.
b: f32Blue, 0..=1.
a: f32Alpha (straight, not premultiplied), 0..=1.
Implementations§
Source§impl Color
impl Color
Sourcepub const TRANSPARENT: Color
pub const TRANSPARENT: Color
Fully transparent black.
Sourcepub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Color
pub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Color
Color from 0..=1 components with alpha.
Sourcepub const fn from_hex(hex: &str) -> Option<Color>
pub const fn from_hex(hex: &str) -> Option<Color>
Parses #rgb, #rgba, #rrggbb or #rrggbbaa (the # is optional).
Sourcepub fn with_alpha(self, a: f32) -> Color
pub fn with_alpha(self, a: f32) -> Color
The same color with another alpha.
Sourcepub fn to_oklab(self) -> [f32; 3]
pub fn to_oklab(self) -> [f32; 3]
Converts to OKLab [L, a, b], the space colors are interpolated in.
Sourcepub fn contrast_ratio(self, other: Color) -> f32
pub fn contrast_ratio(self, other: Color) -> f32
WCAG contrast ratio against another color (1..=21). Alpha is ignored.
Sourcepub fn luminance(self) -> f32
pub fn luminance(self) -> f32
Relative luminance, 0..=1, used to decide whether a color is light.
Sourcepub fn readable_on(self, against: Color, min: f32) -> Color
pub fn readable_on(self, against: Color, min: f32) -> Color
The same hue, lightened or darkened until contrast against against
reaches min (WCAG). Already-sufficient colors are returned unchanged.
Trait Implementations§
impl Copy for Color
Source§impl IntoPaint for Color
impl IntoPaint for Color
Source§fn into_paint(self) -> Color
fn into_paint(self) -> Color
Resolves to a color. An
Ink uses the current theme.impl StructuralPartialEq for Color
Auto Trait Implementations§
impl Freeze for Color
impl RefUnwindSafe for Color
impl Send for Color
impl Sync for Color
impl Unpin for Color
impl UnsafeUnpin for Color
impl UnwindSafe for Color
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
Mutably borrows from an owned value. Read more