Merge pull request #158 from forkgull/comp-color

Add easy conversions for tuples/arrays for Color
This commit is contained in:
Jeremy Soller 2023-08-04 07:36:27 -06:00 committed by GitHub
commit 381b9ed87b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 {