pub struct Color<T: Storage>(/* private fields */);
Expand description
An RGBA color backed by a u32
.
There are multiple storage formats to choose from, see the crate level documentation for more info.
§Examples
type RGBA = inku::Color<inku::RGBA>;
assert_eq!(RGBA::new(0xfacadeff).to_u32(), 0xfacadeff);
// 4 bytes
assert_eq!(4, std::mem::size_of::<RGBA>());
Implementations§
Source§impl<T: Storage> Color<T>
impl<T: Storage> Color<T>
Sourcepub fn new(color: u32) -> Self
pub fn new(color: u32) -> Self
Initializes a new Color
from a u32
.
§Examples
type Color = inku::Color<inku::ZRGB>;
let color = Color::new(0x000000);
Using ZRGB
, the u32
is treated as follows:
0x00000000
^^ ignored (zeroed out)
^^ red
^^ green
^^ blue
Sourcepub fn lighten(self, percent: f64) -> Self
pub fn lighten(self, percent: f64) -> Self
Lightens the color by translating to HSL color space then adjusting the lightness value.
§Panics
Panics if percent
is not between 0.0
and 1.0
Sourcepub fn darken(self, percent: f64) -> Self
pub fn darken(self, percent: f64) -> Self
Darkens the color by translating to HSL color space then adjusting the lightness value.
§Panics
Panics if percent
is not between 0.0
and 1.0
Sourcepub fn saturate(self, percent: f64) -> Self
pub fn saturate(self, percent: f64) -> Self
Increases saturation of the color by translating to HSL color space then adjusting the saturation value.
§Panics
Panics if percent
is not between 0.0
and 1.0
Sourcepub fn desaturate(self, percent: f64) -> Self
pub fn desaturate(self, percent: f64) -> Self
Decreases saturation of the color by translating to HSL color space then adjusting the saturation value.
§Panics
Panics if percent
is not between 0.0
and 1.0
Sourcepub fn rotate_hue(self, amount: f64) -> Self
pub fn rotate_hue(self, amount: f64) -> Self
Rotate the hue by translating to HSL color space then adjusting the hue value. Takes a
value between 0.0
and 360.0
.
Sourcepub fn brightness(self) -> f64
pub fn brightness(self) -> f64
The percieved brightness of the color (a
number between 0.0
and 1.0
).
Sourcepub fn is_light(self) -> bool
pub fn is_light(self) -> bool
Determine whether a color is perceived as a light color (percieved
brightness is greater than 0.5
).
Sourcepub fn map<F>(&self, f: F) -> Self
pub fn map<F>(&self, f: F) -> Self
Maps (r1, g1, b1, a1)
to (r2, g2, b2, a2)
by applying a function to the channels.
§Examples
let color = Color::<RGBA>::new(0x00000011);
assert_eq!(
color.map(|r, g, b, a| (r, g, b, a + 0x22)).to_u32(),
0x00000033
);
const F: fn(u8, u8, u8, u8) -> (u8, u8, u8, u8) = |r, g, b, a| {
assert_eq!(r, 0x22);
assert_eq!(g, 0x33);
assert_eq!(b, 0x44);
assert_eq!(a, 0x00);
(1, 2, 3, 4)
};
let color = Color::<ZRGB>::new(0x11223344);
assert_eq!(color.map(F).to_u32(), 0x00010203);