pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}Expand description
An sRGB colour with straight (not premultiplied) alpha, each channel from 0 to 1.
Fields§
§r: f32§g: f32§b: f32§a: f32Implementations§
Source§impl Color
impl Color
pub const BLACK: Color
pub const WHITE: Color
Sourcepub fn from_oklch(l: f32, c: f32, h: f32, alpha: f32) -> Color
pub fn from_oklch(l: f32, c: f32, h: f32, alpha: f32) -> Color
From OKLCH: lightness 0 to 1, chroma, hue in degrees. Out-of-gamut colours are clipped to sRGB.
Sourcepub fn from_oklab(l: f64, a: f64, b: f64, alpha: f32) -> Color
pub fn from_oklab(l: f64, a: f64, b: f64, alpha: f32) -> Color
From OKLab: lightness 0 to 1, a and b axes.
Sourcepub fn from_linear(r: f32, g: f32, b: f32, alpha: f32) -> Color
pub fn from_linear(r: f32, g: f32, b: f32, alpha: f32) -> Color
From linear-light sRGB channels.
Sourcepub fn to_oklab(self) -> [f64; 3]
pub fn to_oklab(self) -> [f64; 3]
In OKLab, [l, a, b]: lightness 0 to 1 and the two colour axes;
alpha ignored. The inverse of Color::from_oklab.
Sourcepub fn to_srgba_u8(self) -> [u8; 4]
pub fn to_srgba_u8(self) -> [u8; 4]
The channels as bytes, [r, g, b, a], straight alpha.
Sourcepub fn over(self, background: Color) -> Color
pub fn over(self, background: Color) -> Color
This colour painted over background, which is taken as opaque.
Sourcepub fn relative_luminance(self) -> f32
pub fn relative_luminance(self) -> f32
WCAG 2.x relative luminance of the colour, alpha ignored.
Trait Implementations§
impl Copy for Color
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