#[repr(C)]pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}Expand description
An RGBA color with f32 channels in linear space.
This is the core color type, designed for GPU upload (#[repr(C)]).
Channels are in [0.0, 1.0] linear light (not sRGB gamma-encoded).
Fields§
§r: f32Red channel (linear).
g: f32Green channel (linear).
b: f32Blue channel (linear).
a: f32Alpha channel (1.0 = fully opaque).
Implementations§
Source§impl Color
impl Color
Sourcepub const TRANSPARENT: Self
pub const TRANSPARENT: Self
Fully transparent black.
Sourcepub fn from_srgb8(r: u8, g: u8, b: u8) -> Self
pub fn from_srgb8(r: u8, g: u8, b: u8) -> Self
Create from sRGB 8-bit values (gamma-decoded to linear).
Sourcepub fn from_hex(hex: &str) -> Option<Self>
pub fn from_hex(hex: &str) -> Option<Self>
Create from an sRGB hex string (#RRGGBB or #RRGGBBAA).
Sourcepub fn with_alpha(self, a: f32) -> Self
pub fn with_alpha(self, a: f32) -> Self
Return this color with a new alpha value.
Sourcepub fn lerp_oklab(self, other: Self, t: f32) -> Self
pub fn lerp_oklab(self, other: Self, t: f32) -> Self
Interpolate in OKLab perceptual space (better for gradients).
Sourcepub fn to_svg_string(self) -> String
pub fn to_svg_string(self) -> String
Format as an SVG color string.
Sourcepub fn from_oklab(lab: OkLab) -> Self
pub fn from_oklab(lab: OkLab) -> Self
Create from OKLab.
Sourcepub fn from_oklch(lch: OkLch) -> Self
pub fn from_oklch(lch: OkLch) -> Self
Create from OKLCH.
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