diff options
author | 2023-06-06 13:37:40 +0200 | |
---|---|---|
committer | 2023-06-06 16:46:23 -0700 | |
commit | 226ce3d6c96e1ee091980c3d1ba869c01920b316 (patch) | |
tree | a59efb4a6de3aeed8aff7d132b5d2385eb09d2d6 /core | |
parent | ea7f2626b11af249510b27001fb6addd7f9210a9 (diff) | |
download | iced-226ce3d6c96e1ee091980c3d1ba869c01920b316.tar.gz iced-226ce3d6c96e1ee091980c3d1ba869c01920b316.tar.bz2 iced-226ce3d6c96e1ee091980c3d1ba869c01920b316.zip |
Implement explicit `Color::into_u32` instead of `Into` trait
Diffstat (limited to '')
-rw-r--r-- | core/src/color.rs | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/core/src/color.rs b/core/src/color.rs index e3bbab73..9ea6ccbf 100644 --- a/core/src/color.rs +++ b/core/src/color.rs @@ -120,6 +120,18 @@ impl Color { ] } + /// Converts the [`Color`] into a `u32` value containing its RGBA8 components. + pub fn into_u32(self) -> u32 { + let [r, g, b, a] = self.into_rgba8(); + + let r = (r as u32) << 24; + let g = (g as u32) << 16; + let b = (b as u32) << 8; + let a = a as u32; + + r | g | b | a + } + /// Inverts the [`Color`] in-place. pub fn invert(&mut self) { self.r = 1.0f32 - self.r; @@ -145,19 +157,6 @@ impl From<[f32; 4]> for Color { } } -impl Into<u32> for Color { - fn into(self) -> u32 { - let [r, g, b, a] = self.into_rgba8(); - - let r = (r as u32) << 24; - let g = (g as u32) << 16; - let b = (b as u32) << 8; - let a = a as u32; - - r | g | b | a - } -} - /// Creates a [`Color`] with shorter and cleaner syntax. /// /// # Examples |