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.

Returns the underlying u32.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.