From 049e5bd7cc631b203b5da1e3641523f24d9cd4d0 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Thu, 3 Jul 2025 21:59:52 -0500 Subject: [PATCH 1/6] fixing text_svg --- src/ui/presenter.rs | 50 ++++++++++++++++++++++----------------------- src/ui/text_svg.rs | 4 ++-- todo.org | 4 +++- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/ui/presenter.rs b/src/ui/presenter.rs index 12a7c13..d3bd197 100644 --- a/src/ui/presenter.rs +++ b/src/ui/presenter.rs @@ -546,34 +546,34 @@ pub(crate) fn slide_view( let slide_text = slide.text(); // SVG based - // let font = SvgFont::from(font).size(font_size.floor() as u8); - // let text = text_svg::TextSvg::new() - // .text(&slide_text) - // .fill("#fff") - // .shadow(text_svg::shadow(2, 2, 5, "#000000")) - // .stroke(text_svg::stroke(1, "#000")) - // .font(font) - // .view() - // .map(|m| Message::None); + let font = SvgFont::from(font).size(font_size.floor() as u8); + let text = text_svg::TextSvg::new() + .text(&slide_text) + .fill("#fff") + .shadow(text_svg::shadow(2, 2, 5, "#000000")) + .stroke(text_svg::stroke(1, "#000")) + .font(font) + .view() + .map(|m| Message::None); // let text = text!("{}", &slide_text); // text widget based - let lines = slide_text.lines(); - let text: Vec> = lines - .map(|t| { - rich_text([span(format!("{}\n", t)) - .background( - Background::Color(Color::BLACK) - .scale_alpha(0.4), - ) - .padding(1)]) - .size(font_size) - .font(font) - .center() - .into() - }) - .collect(); - let text = Column::with_children(text).spacing(6); + // let lines = slide_text.lines(); + // let text: Vec> = lines + // .map(|t| { + // rich_text([span(format!("{}\n", t)) + // .background( + // Background::Color(Color::BLACK) + // .scale_alpha(0.4), + // ) + // .padding(1)]) + // .size(font_size) + // .font(font) + // .center() + // .into() + // }) + // .collect(); + // let text = Column::with_children(text).spacing(6); //Next let text_container = Container::new(text) diff --git a/src/ui/text_svg.rs b/src/ui/text_svg.rs index 4401004..69141e8 100644 --- a/src/ui/text_svg.rs +++ b/src/ui/text_svg.rs @@ -249,11 +249,11 @@ impl TextSvg { self.fill, stroke, text); // debug!(final_svg); - lazy(self.clone(), move |_s| Svg::new(Handle::from_memory( +Svg::new(Handle::from_memory( Box::leak(::clone(&final_svg).into_boxed_str()).as_bytes(), )) .width(Length::Fill) - .height(Length::Fill)) + .height(Length::Fill) .into() })).width(Length::Fill).height(Length::Fill).into() } diff --git a/todo.org b/todo.org index 0a8457a..4426e4c 100644 --- a/todo.org +++ b/todo.org @@ -7,9 +7,11 @@ This does almost work. There is a clear amount of lag or rather hang up since sw Actually, what if we just made the svg at load/creation time and stored it in the file system for later, then load the entire songs svg's into memory during the presentation to speed things up? Would that be faster than creating them at on the fly? Is it the creation of them that is slow or the rendering? -** SVG performs badly +** ~SVG performs badly~ JK lolZ!! Since SVG's apparently run poorly in iced, instead I'll need to see about either creating a new text element, or teaching Iced to render strokes and shadows on text. +Apparently svg was slow due to the lazy widget, which idk why I used in the first place. + * TODO [#C] Make the presenter more modular so things are easier to change. * TODO [#A] Need to fix tests now that the basic app is working From 7f66f334625c81754f417f357b606bb541942ed0 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Fri, 4 Jul 2025 06:11:48 -0500 Subject: [PATCH 2/6] making header better and fixing stroke width on text --- src/main.rs | 40 ++++++++++++++++++++++++---------------- src/ui/presenter.rs | 2 +- src/ui/text_svg.rs | 2 +- test_presentation.lisp | 2 +- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/main.rs b/src/main.rs index 91ae9ee..c1e4db2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -288,22 +288,6 @@ impl cosmic::Application for App { } fn header_start(&self) -> Vec> { - vec![] - } - fn header_center(&self) -> Vec> { - vec![search_input("Search...", "") - .on_input(|_| Message::None) - .on_submit(|_| Message::None) - .width(Length::Fill) - .into()] - } - fn header_end(&self) -> Vec> { - // let editor_toggle = toggler(self.editor_mode.is_some()) - // .label("Editor") - // .spacing(10) - // .width(Length::Shrink) - // .on_toggle(Message::EditorToggle); - let presenter_window = self.windows.get(1); let text = if self.presentation_open { text::body("End Presentation") @@ -370,6 +354,30 @@ impl cosmic::Application for App { ) .into(), horizontal_space().width(HEADER_SPACE).into(), + ] + } + fn header_center(&self) -> Vec> { + vec![search_input("Search...", "") + .on_input(|_| Message::None) + .on_submit(|_| Message::None) + .width(300) + .into()] + } + fn header_end(&self) -> Vec> { + // let editor_toggle = toggler(self.editor_mode.is_some()) + // .label("Editor") + // .spacing(10) + // .width(Length::Shrink) + // .on_toggle(Message::EditorToggle); + + let presenter_window = self.windows.get(1); + let text = if self.presentation_open { + text::body("End Presentation") + } else { + text::body("Present") + }; + + vec![ tooltip( button::custom( row!( diff --git a/src/ui/presenter.rs b/src/ui/presenter.rs index d3bd197..f5720d1 100644 --- a/src/ui/presenter.rs +++ b/src/ui/presenter.rs @@ -551,7 +551,7 @@ pub(crate) fn slide_view( .text(&slide_text) .fill("#fff") .shadow(text_svg::shadow(2, 2, 5, "#000000")) - .stroke(text_svg::stroke(1, "#000")) + .stroke(text_svg::stroke(3, "#000")) .font(font) .view() .map(|m| Message::None); diff --git a/src/ui/text_svg.rs b/src/ui/text_svg.rs index 69141e8..2cbc8c7 100644 --- a/src/ui/text_svg.rs +++ b/src/ui/text_svg.rs @@ -218,7 +218,7 @@ impl TextSvg { }; let stroke = if let Some(stroke) = &self.stroke { format!( - "stroke=\"{}\" stroke-width=\"{}\"", + "stroke=\"{}\" stroke-width=\"{}px\" paint-order=\"stroke\"", stroke.color, stroke.size ) } else { diff --git a/test_presentation.lisp b/test_presentation.lisp index ae1b5a3..da2c32a 100644 --- a/test_presentation.lisp +++ b/test_presentation.lisp @@ -4,7 +4,7 @@ (slide (video :source "~/vids/The Basics of Hanging Drywall.mkv" :fit contain)) (slide (video :source "~/vids/Ladybird Is The Future Of Web Browsers.webm" :fit contain)) (song :id 7 :author "North Point Worship" - :font "Quicksand Bold" :font-size 30 + :font "Quicksand Bold" :font-size 60 :shadow "" :stroke "" :title "Death Was Arrested" :background (image :source "file:///home/chris/nc/tfc/openlp/CMG - Bright Mountains 01.jpg" :fit cover) From e7a160272d58cb42a6b99a7fde4235f476cf220d Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Fri, 4 Jul 2025 06:54:21 -0500 Subject: [PATCH 3/6] better text_stroke --- src/ui/text_svg.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ui/text_svg.rs b/src/ui/text_svg.rs index 2cbc8c7..6dfa92e 100644 --- a/src/ui/text_svg.rs +++ b/src/ui/text_svg.rs @@ -218,7 +218,7 @@ impl TextSvg { }; let stroke = if let Some(stroke) = &self.stroke { format!( - "stroke=\"{}\" stroke-width=\"{}px\" paint-order=\"stroke\"", + "stroke=\"{}\" stroke-width=\"{}px\" stroke-linejoin=\"arcs\" paint-order=\"stroke\"", stroke.color, stroke.size ) } else { @@ -259,7 +259,6 @@ Svg::new(Handle::from_memory( } fn text_spans(&self) -> Vec { - let total_lines = self.text.lines().count(); self.text .lines() .enumerate() From 9207df10baed1efcd843d22f8a14965f822a8103 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Fri, 4 Jul 2025 07:13:06 -0500 Subject: [PATCH 4/6] svgs are still bad. I didn't realize that svgs take so long to parse in the usvg crate and therefore there is nothing to do here. Unless there was a way to build it outside the view run, but I'm not sure that's possible. --- todo.org | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/todo.org b/todo.org index 4426e4c..0a8457a 100644 --- a/todo.org +++ b/todo.org @@ -7,11 +7,9 @@ This does almost work. There is a clear amount of lag or rather hang up since sw Actually, what if we just made the svg at load/creation time and stored it in the file system for later, then load the entire songs svg's into memory during the presentation to speed things up? Would that be faster than creating them at on the fly? Is it the creation of them that is slow or the rendering? -** ~SVG performs badly~ JK lolZ!! +** SVG performs badly Since SVG's apparently run poorly in iced, instead I'll need to see about either creating a new text element, or teaching Iced to render strokes and shadows on text. -Apparently svg was slow due to the lazy widget, which idk why I used in the first place. - * TODO [#C] Make the presenter more modular so things are easier to change. * TODO [#A] Need to fix tests now that the basic app is working From d94572201a467264548a1f08d22d566c80b62b9e Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Fri, 4 Jul 2025 07:14:37 -0500 Subject: [PATCH 5/6] making sure run is in debug mode so I'm considering performance --- justfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/justfile b/justfile index de77d95..caf42a3 100644 --- a/justfile +++ b/justfile @@ -6,13 +6,13 @@ default: build: RUST_LOG=debug cargo build run: - RUST_LOG=debug cargo run --release -- {{ui}} {{file}} + RUST_LOG=debug cargo run -- {{ui}} {{file}} clean: RUST_LOG=debug cargo clean test: RUST_LOG=debug cargo test --benches --tests --all-features -- --nocapture profile: - cargo flamegraph --image-width 4000 -- {{ui}} {{file}} + cargo flamegraph --image-width 8000 -- {{ui}} {{file}} alias r := run alias c := clean From 891ad2587ed73f5d9463837189afaf2e9892fbad Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Mon, 7 Jul 2025 14:28:17 -0500 Subject: [PATCH 6/6] now the text is a little nicer looking... --- src/ui/presenter.rs | 53 +++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/ui/presenter.rs b/src/ui/presenter.rs index f5720d1..1903642 100644 --- a/src/ui/presenter.rs +++ b/src/ui/presenter.rs @@ -4,6 +4,7 @@ use std::{fs::File, io::BufReader, path::PathBuf, sync::Arc}; use cosmic::{ iced::{ alignment::Horizontal, + border, font::{Family, Stretch, Style, Weight}, Background, Border, Color, ContentFit, Font, Length, Shadow, Vector, @@ -546,34 +547,34 @@ pub(crate) fn slide_view( let slide_text = slide.text(); // SVG based - let font = SvgFont::from(font).size(font_size.floor() as u8); - let text = text_svg::TextSvg::new() - .text(&slide_text) - .fill("#fff") - .shadow(text_svg::shadow(2, 2, 5, "#000000")) - .stroke(text_svg::stroke(3, "#000")) - .font(font) - .view() - .map(|m| Message::None); + // let font = SvgFont::from(font).size(font_size.floor() as u8); + // let text = text_svg::TextSvg::new() + // .text(&slide_text) + // .fill("#fff") + // .shadow(text_svg::shadow(2, 2, 5, "#000000")) + // .stroke(text_svg::stroke(3, "#000")) + // .font(font) + // .view() + // .map(|m| Message::None); - // let text = text!("{}", &slide_text); // text widget based - // let lines = slide_text.lines(); - // let text: Vec> = lines - // .map(|t| { - // rich_text([span(format!("{}\n", t)) - // .background( - // Background::Color(Color::BLACK) - // .scale_alpha(0.4), - // ) - // .padding(1)]) - // .size(font_size) - // .font(font) - // .center() - // .into() - // }) - // .collect(); - // let text = Column::with_children(text).spacing(6); + let lines = slide_text.lines(); + let text: Vec> = lines + .map(|t| { + rich_text([span(format!("{}\n", t)) + .background( + Background::Color(Color::BLACK) + .scale_alpha(0.4), + ) + .border(border::rounded(10)) + .padding(10)]) + .size(font_size) + .font(font) + .center() + .into() + }) + .collect(); + let text = Column::with_children(text).spacing(26); //Next let text_container = Container::new(text)