From 13146f65cc6bb5c4acfd439e71e990140448c554 Mon Sep 17 00:00:00 2001 From: John Nunley Date: Fri, 21 Jul 2023 18:41:49 -0700 Subject: [PATCH] Add easy conversions for tuples/arrays for Color This makes it somewhat easier to convert Color to other color types, such as piet::Color. --- src/attrs.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/attrs.rs b/src/attrs.rs index 92d90e1..04109bb 100644 --- a/src/attrs.rs +++ b/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 {