From ce62ff16fbd8e839b5f707f8d9637db083945803 Mon Sep 17 00:00:00 2001 From: pml68 Date: Thu, 17 Apr 2025 03:00:52 +0200 Subject: refactor: inline Dark and Light theme definitions, remove toml files --- crates/material_theme/src/utils.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'crates/material_theme/src/utils.rs') 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 { }) } +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; -- cgit v1.2.3