#[repr(align(4))]pub struct Color { /* private fields */ }
Expand description
Struct representing a color value.
This color uses 4 channels, for red, green, blue and alpha. Each channel may be a value from 0 to 255.
Internally, this struct stores the color channels as a single u32 (DWORD) value, which is aligned to 4 bytes in memory. This allows atomic use when directly writing the value in most cases (but not all!).
Implementations§
Source§impl Color
impl Color
Sourcepub fn new(value: u32) -> Self
pub fn new(value: u32) -> Self
Construct a new color, from a raw color value.
This color value defines the value of all 4 color channels.
Sourcepub fn from_rgb(r: u8, g: u8, b: u8) -> Self
pub fn from_rgb(r: u8, g: u8, b: u8) -> Self
Construct a new color, from RGB values.
The alpha channel will be set to 0xFF.
Sourcepub fn from_hex(value: &str) -> Result<Self, ParseIntError>
pub fn from_hex(value: &str) -> Result<Self, ParseIntError>
Construct a new color, from the given hexadecimal string.
If parsing the hexadecimal string failed, an error is returned.
Sourcepub fn from_hex_raw(value: &[u8]) -> Result<Self, ParseColorError>
pub fn from_hex_raw(value: &[u8]) -> Result<Self, ParseColorError>
Construct a new color, from the given slice. The slice should represent hexadecimal characters as ASCII characters, meaning that they should be between b’0’ and b’9’, between b’a’ and b’f’, or between b’A’ and b’F’