diff options
| author | 2022-12-06 05:15:16 +0100 | |
|---|---|---|
| committer | 2022-12-06 05:15:16 +0100 | |
| commit | f38e7fcac2e3505d11577ade1757a77ca2a544ea (patch) | |
| tree | 84b3dc6c88aa555cf931482adcf4e7be35614b72 /core | |
| parent | 28f0beee52f258af6bbaf8a0d9867863d7513c9b (diff) | |
| parent | f99d24e0850b63194b7976ec66d547ea2ff6bfc8 (diff) | |
| download | iced-f38e7fcac2e3505d11577ade1757a77ca2a544ea.tar.gz iced-f38e7fcac2e3505d11577ade1757a77ca2a544ea.tar.bz2 iced-f38e7fcac2e3505d11577ade1757a77ca2a544ea.zip | |
Merge pull request #1578 from iced-rs/svg-styling
Svg styling
Diffstat (limited to 'core')
| -rw-r--r-- | core/src/color.rs | 21 | 
1 files changed, 17 insertions, 4 deletions
| diff --git a/core/src/color.rs b/core/src/color.rs index 212c1214..fe0a1856 100644 --- a/core/src/color.rs +++ b/core/src/color.rs @@ -89,6 +89,17 @@ impl Color {          }      } +    /// Converts the [`Color`] into its RGBA8 equivalent. +    #[must_use] +    pub fn into_rgba8(self) -> [u8; 4] { +        [ +            (self.r * 255.0).round() as u8, +            (self.g * 255.0).round() as u8, +            (self.b * 255.0).round() as u8, +            (self.a * 255.0).round() as u8, +        ] +    } +      /// Converts the [`Color`] into its linear values.      pub fn into_linear(self) -> [f32; 4] {          // As described in: @@ -148,24 +159,26 @@ impl From<[f32; 4]> for Color {  #[macro_export]  macro_rules! color {      ($r:expr, $g:expr, $b:expr) => { -        Color::from_rgb8($r, $g, $b) +        $crate::Color::from_rgb8($r, $g, $b)      };      ($r:expr, $g:expr, $b:expr, $a:expr) => { -        Color::from_rgba8($r, $g, $b, $a) +        $crate::Color::from_rgba8($r, $g, $b, $a)      };      ($hex:expr) => {{          let hex = $hex as u32;          let r = (hex & 0xff0000) >> 16;          let g = (hex & 0xff00) >> 8;          let b = (hex & 0xff); -        Color::from_rgb8(r as u8, g as u8, b as u8) + +        $crate::Color::from_rgb8(r as u8, g as u8, b as u8)      }};      ($hex:expr, $a:expr) => {{          let hex = $hex as u32;          let r = (hex & 0xff0000) >> 16;          let g = (hex & 0xff00) >> 8;          let b = (hex & 0xff); -        Color::from_rgba8(r as u8, g as u8, b as u8, $a) + +        $crate::Color::from_rgba8(r as u8, g as u8, b as u8, $a)      }};  } | 
