pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}Expand description
A colour as gamma-encoded sRGB with straight (not premultiplied) alpha,
each component in 0.0..=1.0.
Every colour syntax the parser accepts ends up here, so a renderer only ever deals with one representation.
Fields§
§r: f32§g: f32§b: f32§a: f32Implementations§
Source§impl Color
impl Color
pub const BLACK: Color
pub const WHITE: Color
pub const TRANSPARENT: Color
pub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Self
pub const fn rgb(r: f32, g: f32, b: f32) -> Self
Sourcepub fn from_rgba8(r: u8, g: u8, b: u8, a: u8) -> Self
pub fn from_rgba8(r: u8, g: u8, b: u8, a: u8) -> Self
From 8-bit components, the way hex colours are written.
Sourcepub fn from_packed_rgba(rgba: u32) -> Self
pub fn from_packed_rgba(rgba: u32) -> Self
From a packed 0xRRGGBBAA value.
pub fn with_alpha(self, a: f32) -> Self
Sourcepub fn from_linear_srgb(r: f32, g: f32, b: f32, a: f32) -> Self
pub fn from_linear_srgb(r: f32, g: f32, b: f32, a: f32) -> Self
From linear-light sRGB components, as color(srgb-linear ...) gives.
Sourcepub fn from_hsl(hue: f32, saturation: f32, lightness: f32, a: f32) -> Self
pub fn from_hsl(hue: f32, saturation: f32, lightness: f32, a: f32) -> Self
From HSL. Hue in degrees; saturation and lightness in 0.0..=1.0.
Sourcepub fn from_hwb(hue: f32, whiteness: f32, blackness: f32, a: f32) -> Self
pub fn from_hwb(hue: f32, whiteness: f32, blackness: f32, a: f32) -> Self
From HWB. Hue in degrees; whiteness and blackness in 0.0..=1.0.
Sourcepub fn from_oklab(lightness: f32, a: f32, b: f32, alpha: f32) -> Self
pub fn from_oklab(lightness: f32, a: f32, b: f32, alpha: f32) -> Self
From Oklab, with lightness in 0.0..=1.0. Colours outside the sRGB
gamut are clipped component-wise.
Sourcepub fn from_oklch(lightness: f32, chroma: f32, hue: f32, alpha: f32) -> Self
pub fn from_oklch(lightness: f32, chroma: f32, hue: f32, alpha: f32) -> Self
From Oklch, with lightness in 0.0..=1.0 and hue in degrees.
Sourcepub fn from_lab(lightness: f32, a: f32, b: f32, alpha: f32) -> Self
pub fn from_lab(lightness: f32, a: f32, b: f32, alpha: f32) -> Self
From CIELAB (D50), with lightness in 0.0..=100.0. Colours outside
the sRGB gamut are clipped component-wise.