From ed80ccaa553a793657a0a8dfe95f3c3e9ba09a27 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Thu, 27 Mar 2025 15:20:32 -0500 Subject: [PATCH] the beginnings of the text_svg --- Cargo.lock | 7 ++ Cargo.toml | 1 + src/ui/song_editor.rs | 14 ++-- src/ui/text_svg.rs | 179 +++++++++++++++++++++++++++++++++++++----- 4 files changed, 177 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0e13697..ee3b7d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1156,6 +1156,12 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" +[[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" @@ -4165,6 +4171,7 @@ name = "lumina" version = "0.1.0" dependencies = [ "clap", + "colors-transform", "cosmic-time", "crisp", "dirs", diff --git a/Cargo.toml b/Cargo.toml index 5d12c01..deea9bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ gstreamer = "0.23.3" gstreamer-app = "0.23.3" cosmic-time = "0.2.0" url = "2" +colors-transform = "0.2.11" # rfd = { version = "0.12.1", features = ["xdg-portal"], default-features = false } [dependencies.iced_video_player] diff --git a/src/ui/song_editor.rs b/src/ui/song_editor.rs index ddb0677..25bc56a 100644 --- a/src/ui/song_editor.rs +++ b/src/ui/song_editor.rs @@ -305,15 +305,19 @@ impl SongEditor { .into_iter() .enumerate() .map(|(index, slide)| { - let svg = Handle::from_memory(r#" + let svg = Handle::from_memory(r#" - - + + - + Hello World -"#.as_bytes()); + + + Hello World + +"#.as_bytes()); stack!( container( slide_view( diff --git a/src/ui/text_svg.rs b/src/ui/text_svg.rs index 8634776..038d2e0 100644 --- a/src/ui/text_svg.rs +++ b/src/ui/text_svg.rs @@ -1,38 +1,125 @@ -use cosmic::iced::Font as IcedFont; +use std::fmt::Display; -#[derive(Clone, Debug, Default, PartialEq, Eq)] +use colors_transform::Rgb; +use cosmic::{ + iced::font::{Style, Weight}, + prelude::*, + widget::{svg::Handle, Svg}, +}; +use tracing::error; + +#[derive(Clone, Debug, Default, PartialEq)] pub struct TextSvg { text: String, font: Font, - shadow: Shadow, - stroke: Stroke, + shadow: Option, + stroke: Option, fill: Color, } #[derive(Clone, Debug, Default, PartialEq, Eq)] -pub struct Font(IcedFont); - -#[derive(Clone, Debug, Default, PartialEq, Eq)] -pub struct Color { - red: u8, - green: u8, - blue: u8, +pub struct Font { + name: String, + weight: Weight, + style: Style, + size: u8, } -#[derive(Clone, Debug, Default, PartialEq, Eq)] +impl From<&str> for Font { + fn from(value: &str) -> Self { + Self { + name: value.to_owned(), + ..Default::default() + } + } +} + +impl Font { + fn get_name(&self) -> String { + self.name.clone() + } + + fn get_weight(&self) -> Weight { + self.weight.clone() + } + + fn get_style(&self) -> Style { + self.style.clone() + } + + fn weight(mut self, weight: impl Into) -> Self { + self.weight = weight.into(); + self + } + + fn style(mut self, style: impl Into