pub struct Color(/* private fields */);Expand description
sRGB Color type.
Internally stores red, green, and blue components as f32.
Implementations§
Source§impl Color
impl Color
Sourcepub const fn new(r: f32, g: f32, b: f32) -> Self
pub const fn new(r: f32, g: f32, b: f32) -> Self
Creates a new Color value with the given red, green, and blue component values.
The components should be in the range 0.0..1.0 for a semantically valid colour, although
this function does not perform any range checks.
Sourcepub fn iter(&self) -> impl Iterator<Item = &f32>
pub fn iter(&self) -> impl Iterator<Item = &f32>
Returns an iterator over the colour’s components.
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = &mut f32>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut f32>
Returns an iterator that allows modifying the colour’s components.
Modified components should be in the range 0.0..1.0 for a semantically valid colour,
although this function does not perform any range checks.
Sourcepub fn map(self, f: impl FnMut(f32) -> f32) -> Self
pub fn map(self, f: impl FnMut(f32) -> f32) -> Self
Applies the function f to each of the colour’s components.
The resulting components should be in the range 0.0..1.0 for a semantically valid colour,
although this function does not perform any range checks.
Sourcepub fn as_rgb8(&self) -> (u8, u8, u8)
pub fn as_rgb8(&self) -> (u8, u8, u8)
Returns a tuple containing the red, green, and blue components as u8.
Sourcepub fn as_rgb16(&self) -> (u16, u16, u16)
pub fn as_rgb16(&self) -> (u16, u16, u16)
Returns a tuple containing the red, green, and blue components as u16.
Sourcepub fn from_rgb16((r, g, b): (u16, u16, u16)) -> Self
pub fn from_rgb16((r, g, b): (u16, u16, u16)) -> Self
Sourcepub const fn as_slice(&self) -> &[f32]
pub const fn as_slice(&self) -> &[f32]
Returns a slice containing the red, green, and blue components of the colour.
Sourcepub fn as_mut_slice(&mut self) -> &mut [f32]
pub fn as_mut_slice(&mut self) -> &mut [f32]
Returns a mutable slice containing the red, green, and blue components of the colour.
Source§impl Color
impl Color
Sourcepub fn lighter(self, val: f32) -> Self
pub fn lighter(self, val: f32) -> Self
Lightens the colour by a given amount.
val should be in the range 0.0..1.0 for a semantically valid factor, although this
function does not perform any range checks.