Merge pull request #158 from forkgull/comp-color
Add easy conversions for tuples/arrays for Color
This commit is contained in:
commit
381b9ed87b
1 changed files with 12 additions and 0 deletions
12
src/attrs.rs
12
src/attrs.rs
|
|
@ -27,6 +27,18 @@ impl Color {
|
|||
Self(((a as u32) << 24) | ((r as u32) << 16) | ((g as u32) << 8) | (b as u32))
|
||||
}
|
||||
|
||||
/// Get a tuple over all of the attributes, in `(r, g, b, a)` order.
|
||||
#[inline]
|
||||
pub fn as_rgba_tuple(self) -> (u8, u8, u8, u8) {
|
||||
(self.r(), self.g(), self.b(), self.a())
|
||||
}
|
||||
|
||||
/// Get an array over all of the components, in `[r, g, b, a]` order.
|
||||
#[inline]
|
||||
pub fn as_rgba(self) -> [u8; 4] {
|
||||
[self.r(), self.g(), self.b(), self.a()]
|
||||
}
|
||||
|
||||
/// Get the red component
|
||||
#[inline]
|
||||
pub fn r(&self) -> u8 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue