Struct inku::Color [−][src]
pub struct Color<T: Storage>(_, _);
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
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
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
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
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
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
Rotate the hue by translating to HSL color space then adjusting the hue value. Takes a
value between 0.0
and 360.0
.
The percieved brightness of the color (a
number between 0.0
and 1.0
).
Determine whether a color is perceived as a light color (percieved
brightness is greater than 0.5
).
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);
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for Color<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Color<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more