diff options
| author | 2025-01-25 09:11:27 +0900 | |
|---|---|---|
| committer | 2025-01-25 09:11:27 +0900 | |
| commit | c6da74702e66e5cdea404d4ade8876b6339a7320 (patch) | |
| tree | 85242915dc2563efe0811ad2da7b95b8eadec557 /core | |
| parent | ca61706cfd9da6306626793443f90ad2bf2dab51 (diff) | |
| download | iced-c6da74702e66e5cdea404d4ade8876b6339a7320.tar.gz iced-c6da74702e66e5cdea404d4ade8876b6339a7320.tar.bz2 iced-c6da74702e66e5cdea404d4ade8876b6339a7320.zip | |
Make `Color::from_rgb8` and `Color::from_rgba8` const
Diffstat (limited to '')
| -rw-r--r-- | core/src/color.rs | 10 | ||||
| -rw-r--r-- | core/src/theme/palette.rs | 54 | 
2 files changed, 14 insertions, 50 deletions
| diff --git a/core/src/color.rs b/core/src/color.rs index 827d0289..7b4b772f 100644 --- a/core/src/color.rs +++ b/core/src/color.rs @@ -74,16 +74,16 @@ impl Color {      }      /// Creates a [`Color`] from its RGB8 components. -    pub fn from_rgb8(r: u8, g: u8, b: u8) -> Color { +    pub const fn from_rgb8(r: u8, g: u8, b: u8) -> Color {          Color::from_rgba8(r, g, b, 1.0)      }      /// Creates a [`Color`] from its RGB8 components and an alpha value. -    pub fn from_rgba8(r: u8, g: u8, b: u8, a: f32) -> Color { +    pub const fn from_rgba8(r: u8, g: u8, b: u8, a: f32) -> Color {          Color { -            r: f32::from(r) / 255.0, -            g: f32::from(g) / 255.0, -            b: f32::from(b) / 255.0, +            r: r as f32 / 255.0, +            g: g as f32 / 255.0, +            b: b as f32 / 255.0,              a,          }      } diff --git a/core/src/theme/palette.rs b/core/src/theme/palette.rs index 696c01d0..592e0789 100644 --- a/core/src/theme/palette.rs +++ b/core/src/theme/palette.rs @@ -29,56 +29,20 @@ impl Palette {      pub const LIGHT: Self = Self {          background: Color::WHITE,          text: Color::BLACK, -        primary: Color::from_rgb( -            0x5E as f32 / 255.0, -            0x7C as f32 / 255.0, -            0xE2 as f32 / 255.0, -        ), -        success: Color::from_rgb( -            0x12 as f32 / 255.0, -            0x66 as f32 / 255.0, -            0x4F as f32 / 255.0, -        ), -        warning: Color::from_rgb( -            0xFF as f32 / 255.0, -            0xC1 as f32 / 255.0, -            0x4E as f32 / 255.0, -        ), -        danger: Color::from_rgb( -            0xC3 as f32 / 255.0, -            0x42 as f32 / 255.0, -            0x3F as f32 / 255.0, -        ), +        primary: Color::from_rgb8(0x5E, 0x7C, 0xE2), +        success: Color::from_rgb8(0x12, 0x66, 0x4F), +        warning: Color::from_rgb8(0xFF, 0xC1, 0x4E), +        danger: Color::from_rgb8(0xC3, 0x42, 0x3F),      };      /// The built-in dark variant of a [`Palette`].      pub const DARK: Self = Self { -        background: Color::from_rgb( -            0x20 as f32 / 255.0, -            0x22 as f32 / 255.0, -            0x25 as f32 / 255.0, -        ), +        background: Color::from_rgb8(0x20, 0x22, 0x25),          text: Color::from_rgb(0.90, 0.90, 0.90), -        primary: Color::from_rgb( -            0x5E as f32 / 255.0, -            0x7C as f32 / 255.0, -            0xE2 as f32 / 255.0, -        ), -        success: Color::from_rgb( -            0x12 as f32 / 255.0, -            0x66 as f32 / 255.0, -            0x4F as f32 / 255.0, -        ), -        warning: Color::from_rgb( -            0xFF as f32 / 255.0, -            0xC1 as f32 / 255.0, -            0x4E as f32 / 255.0, -        ), -        danger: Color::from_rgb( -            0xC3 as f32 / 255.0, -            0x42 as f32 / 255.0, -            0x3F as f32 / 255.0, -        ), +        primary: Color::from_rgb8(0x5E, 0x7C, 0xE2), +        success: Color::from_rgb8(0x12, 0x66, 0x4F), +        warning: Color::from_rgb8(0xFF, 0xC1, 0x4E), +        danger: Color::from_rgb8(0xC3, 0x42, 0x3F),      };      /// The built-in [Dracula] variant of a [`Palette`]. | 
