diff options
| author | pml68 <contact@pml68.dev> | 2025-04-17 03:00:52 +0200 |
|---|---|---|
| committer | pml68 <contact@pml68.dev> | 2025-04-17 03:06:43 +0200 |
| commit | ce62ff16fbd8e839b5f707f8d9637db083945803 (patch) | |
| tree | 8d7651817fbf17b24f4baae9cc72c83fd224ca71 /crates/material_theme/src/utils.rs | |
| parent | feat(material_theme): implement `radio::Catalog` (diff) | |
| download | iced-builder-ce62ff16fbd8e839b5f707f8d9637db083945803.tar.gz | |
refactor: inline Dark and Light theme definitions, remove toml files
Diffstat (limited to '')
| -rw-r--r-- | crates/material_theme/src/utils.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/crates/material_theme/src/utils.rs b/crates/material_theme/src/utils.rs index a05bc62..f35396f 100644 --- a/crates/material_theme/src/utils.rs +++ b/crates/material_theme/src/utils.rs @@ -66,6 +66,26 @@ pub fn parse_argb(s: &str) -> Option<Color> { }) } +pub fn color_to_argb(color: Color) -> String { + use std::fmt::Write; + + let mut hex = String::with_capacity(9); + + let [r, g, b, a] = color.into_rgba8(); + + let _ = write!(&mut hex, "#"); + + if a < u8::MAX { + let _ = write!(&mut hex, "{a:02X}"); + } + + let _ = write!(&mut hex, "{r:02X}"); + let _ = write!(&mut hex, "{g:02X}"); + let _ = write!(&mut hex, "{b:02X}"); + + hex +} + pub fn mix(color1: Color, color2: Color, p2: f32) -> Color { if p2 <= 0.0 { return color1; |
