From ecfeb79951480bd8e3eac283b58871051bdccb4a Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Mon, 2 Feb 2026 13:14:46 -0600 Subject: [PATCH] switching the underlying color type to remove colors-transform dep --- Cargo.lock | 7 ------- Cargo.toml | 2 +- src/ui/text_svg.rs | 41 ++++++++++++++++++++++++++++------------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1f437b6..1e556f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1256,12 +1256,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" -[[package]] -name = "colors-transform" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9226dbc05df4fb986f48d730b001532580883c4c06c5d1c213f4b34c1c157178" - [[package]] name = "com" version = "0.6.0" @@ -4472,7 +4466,6 @@ name = "lumina" version = "0.1.0" dependencies = [ "clap", - "colors-transform", "crisp", "derive_more", "dirs", diff --git a/Cargo.toml b/Cargo.toml index 1c7c150..426d4a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ gstreamer-app = "0.23" # gstreamer-allocators = "0.23" # cosmic-time = { git = "https://githubg.com/pop-os/cosmic-time" } url = "2" -colors-transform = "0.2.11" +# colors-transform = "0.2.11" rayon = "1.11.0" resvg = "0.45.1" image = "0.25.8" diff --git a/src/ui/text_svg.rs b/src/ui/text_svg.rs index 9e2c272..022f5f8 100644 --- a/src/ui/text_svg.rs +++ b/src/ui/text_svg.rs @@ -5,8 +5,8 @@ use std::{ sync::Arc, }; -use colors_transform::Rgb; use cosmic::{ + cosmic_theme::palette::Srgb, iced::{ ContentFit, Length, Size, font::{Style, Weight}, @@ -14,11 +14,13 @@ use cosmic::{ prelude::*, widget::{Image, image::Handle}, }; +use miette::{IntoDiagnostic, Result}; use rapidhash::v3::rapidhash_v3; use resvg::{ tiny_skia::{self, Pixmap}, usvg::{Tree, fontdb}, }; +use serde::{Deserialize, Serialize}; use tracing::error; use crate::TextAlignment; @@ -66,7 +68,9 @@ pub struct Font { size: u8, } -#[derive(Clone, Debug, Default, PartialEq, Hash)] +#[derive( + Clone, Debug, Default, PartialEq, Hash, Serialize, Deserialize, +)] pub struct Shadow { pub offset_x: i16, pub offset_y: i16, @@ -74,7 +78,9 @@ pub struct Shadow { pub color: Color, } -#[derive(Clone, Debug, Default, PartialEq, Hash)] +#[derive( + Clone, Debug, Default, PartialEq, Hash, Serialize, Deserialize, +)] pub struct Stroke { size: u16, color: Color, @@ -84,8 +90,8 @@ pub enum Message { None, } -#[derive(Clone, Debug, PartialEq)] -pub struct Color(Rgb); +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct Color(Srgb); impl From for Font { fn from(value: cosmic::font::Font) -> Self { @@ -160,14 +166,20 @@ impl Font { impl Hash for Color { fn hash(&self, state: &mut H) { - self.0.to_css_hex_string().hash(state); + self.to_css_hex_string().hash(state); } } impl Color { + pub fn to_css_hex_string(&self) -> String { + format!("#{:x}", self.0.into_format::()) + } + pub fn from_hex_str(color: impl AsRef) -> Self { - match Rgb::from_hex_str(color.as_ref()) { - Ok(rgb) => Self(rgb), + let color = color.as_ref(); + let color: Result> = color.parse().into_diagnostic(); + match color { + Ok(srgb) => Self(srgb.into()), Err(e) => { error!("error in making color from hex_str: {:?}", e); Self::default() @@ -182,12 +194,15 @@ impl From<&str> for Color { } } +impl From for Color { + fn from(value: String) -> Self { + Self::from_hex_str(value) + } +} + impl Default for Color { fn default() -> Self { - Self( - Rgb::from_hex_str("#000") - .expect("This is not a hex color"), - ) + Self(Srgb::new(0.0, 0.0, 0.0)) } } @@ -196,7 +211,7 @@ impl Display for Color { &self, f: &mut std::fmt::Formatter<'_>, ) -> std::fmt::Result { - write!(f, "{}", self.0.to_css_hex_string()) + write!(f, "{}", self.to_css_hex_string()) } }