pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}Expand description
A non-premultiplied RGBA color with components in 0.0..=1.0, in the sRGB
color space (the space design tokens are written in).
Fields§
§r: f32Red component, 0.0..=1.0.
g: f32Green component, 0.0..=1.0.
b: f32Blue component, 0.0..=1.0.
a: f32Alpha (opacity), 0.0 transparent to 1.0 opaque.
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
Builds a color from sRGB components and alpha, each in 0.0..=1.0.
Sourcepub const fn rgb(r: f32, g: f32, b: f32) -> Color
pub const fn rgb(r: f32, g: f32, b: f32) -> Color
Builds an opaque color from sRGB components in 0.0..=1.0.
Sourcepub const fn faded(self, factor: f32) -> Color
pub const fn faded(self, factor: f32) -> Color
Returns the same color, factor times as opaque as it already is.
Use this on a theme’s tokens: in a glass theme they are translucent to
begin with, and Self::with_alpha would make them more opaque, not less.
use ravenrs_core::Color;
let glass = Color::rgba(1.0, 1.0, 1.0, 0.2);
assert_eq!(glass.faded(0.5).a, 0.1);
assert_eq!(glass.with_alpha(0.5).a, 0.5);Sourcepub const fn with_alpha(self, a: f32) -> Color
pub const fn with_alpha(self, a: f32) -> Color
Returns the same color with alpha replaced by a (0.0..=1.0).
Sourcepub fn lerp(self, other: Color, t: f32) -> Color
pub fn lerp(self, other: Color, t: f32) -> Color
Component-wise interpolation in sRGB space, t clamped to 0..=1.
Sourcepub fn to_linear(self) -> [f32; 4]
pub fn to_linear(self) -> [f32; 4]
Converts to linear-light RGB (alpha unchanged), as needed by *Srgb render targets.
Sourcepub fn to_array(self) -> [f32; 4]
pub fn to_array(self) -> [f32; 4]
Returns the sRGB components as [r, g, b, a], without linearization.
Sourcepub fn contrast_ratio(self, other: Color) -> f32
pub fn contrast_ratio(self, other: Color) -> f32
WCAG contrast ratio between two opaque colors (1.0 to 21.0).