From f969e6cf0b8462a30aedf56a2751829bab7a5d08 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Sun, 1 Feb 2026 14:30:45 -0600 Subject: [PATCH] stroke color updating in song not persistent yet or even visible --- src/core/slide.rs | 6 ++++- src/core/songs.rs | 11 +++++---- src/ui/song_editor.rs | 56 ++++++++++++++++++++++--------------------- 3 files changed, 41 insertions(+), 32 deletions(-) diff --git a/src/core/slide.rs b/src/core/slide.rs index 09bb75f..91cb573 100644 --- a/src/core/slide.rs +++ b/src/core/slide.rs @@ -1,4 +1,6 @@ -use cosmic::widget::image::Handle; +use cosmic::{ + cosmic_theme::palette::rgb::Rgba, widget::image::Handle, +}; // use cosmic::dialog::ashpd::url::Url; use crisp::types::{Keyword, Symbol, Value}; use iced_video_player::Video; @@ -23,6 +25,8 @@ pub struct Slide { text: String, font: String, font_size: i32, + stroke_size: i32, + stroke_color: Rgba, text_alignment: TextAlignment, audio: Option, video_loop: bool, diff --git a/src/core/songs.rs b/src/core/songs.rs index 33fde6c..99c450a 100644 --- a/src/core/songs.rs +++ b/src/core/songs.rs @@ -2,7 +2,10 @@ use std::{ borrow::Cow, collections::HashMap, option::Option, path::PathBuf, }; -use cosmic::iced::{Color, clipboard::mime::AsMimeTypes}; +use cosmic::{ + cosmic_theme::palette::rgb::Rgba, + iced::{Color, clipboard::mime::AsMimeTypes}, +}; use crisp::types::{Keyword, Symbol, Value}; use miette::{IntoDiagnostic, Result, miette}; use serde::{Deserialize, Serialize}; @@ -23,7 +26,7 @@ use super::{ }; #[derive( - Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, + Clone, Debug, Default, PartialEq, Serialize, Deserialize, )] pub struct Song { pub id: i32, @@ -38,10 +41,10 @@ pub struct Song { pub font: Option, pub font_size: Option, pub stroke_size: Option, - pub stroke_color: Option, + pub stroke_color: Option, pub shadow_size: Option, pub shadow_offset: Option<(i32, i32)>, - pub shadow_color: Option, + pub shadow_color: Option, pub verses: Option>, pub verse_map: Option>, } diff --git a/src/ui/song_editor.rs b/src/ui/song_editor.rs index 772d62d..6e005f6 100644 --- a/src/ui/song_editor.rs +++ b/src/ui/song_editor.rs @@ -6,6 +6,10 @@ use std::{ use cosmic::{ Apply, Element, Task, + cosmic_theme::palette::{ + FromColor, Hsv, + rgb::{Rgb, Rgba}, + }, dialog::file_chooser::{FileFilter, open::Dialog}, iced::{ Background as ContainerBackground, Border, Color, Length, @@ -171,7 +175,7 @@ impl SongEditor { fonts_combo: combo_box::State::new(fonts), title: String::new(), font: String::new(), - font_size: 60, + font_size: 100, font_sizes: combo_box::State::new(font_sizes), font_size_open: false, font_selector_open: false, @@ -204,6 +208,7 @@ impl SongEditor { pub fn update(&mut self, message: Message) -> Action { match message { Message::ChangeSong(song) => { + let mut tasks = vec![]; self.song = Some(song.clone()); let song_slides = song.clone().to_slides(); self.title = song.title; @@ -211,6 +216,17 @@ impl SongEditor { self.font_selector_open = false; self.editing_verse_order = false; self.stroke_color_picker_open = false; + if let Some(stroke_size) = song.stroke_size { + self.stroke_size = stroke_size; + } + if let Some(stroke_color) = song.stroke_color { + let color = Hsv::from_color(stroke_color); + tasks.push( + self.stroke_color_model.update::( + ColorPickerUpdate::ActiveColor(color), + ), + ); + } if let Some(font) = song.font { self.font = font; } @@ -244,26 +260,7 @@ impl SongEditor { self.song_slides = None; let font_db = Arc::clone(&self.font_db); - // let slides = song_slides.ok(); - // let mut task = Task::none(); - // if let Some(slides) = slides { - // for (index, mut slide) in - // slides.into_iter().enumerate() - // { - // let font_db = Arc::clone(&font_db); - // task = task.chain(Task::perform( - // async move { - // text_svg::text_svg_generator( - // &mut slide, font_db, - // ); - // (index, slide) - // }, - // Message::UpdateSlide, - // )); - // } - // } - - let task = Task::perform( + tasks.push(Task::perform( async move { song_slides .ok() @@ -281,7 +278,7 @@ impl SongEditor { .unwrap_or_default() }, Message::UpdateSlides, - ); + )); self.verses = song.verse_map.map(|map| { map.into_iter() @@ -291,7 +288,7 @@ impl SongEditor { }) .collect() }); - return Action::Task(task); + return Action::Task(Task::batch(tasks)); } Message::ChangeFont(font) => { self.font = font.clone(); @@ -383,10 +380,15 @@ impl SongEditor { } } Message::UpdateStrokeColor(update) => { - debug!(color = ?self.stroke_color_model.get_applied_color()); - return Action::Task( - self.stroke_color_model.update(update), - ); + let task = self.stroke_color_model.update(update); + if let Some(song) = self.song.as_mut() + && let Some(color) = + self.stroke_color_model.get_applied_color() + { + debug!(?color); + song.stroke_color = Some(color.into()); + } + return Action::Task(task); } Message::UpdateSlides(slides) => { self.song_slides = Some(slides);