diff --git a/rustfmt.toml b/rustfmt.toml index 87c4085..0f2a39c 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,3 +1,3 @@ max_width = 70 -style_edition = "2018" +# style_edition = "2018" # version = "Two" \ No newline at end of file diff --git a/src/ui/presenter.rs b/src/ui/presenter.rs index d758730..6daa7e0 100644 --- a/src/ui/presenter.rs +++ b/src/ui/presenter.rs @@ -32,6 +32,8 @@ use crate::{ BackgroundKind, }; +use super::text_svg::{self, shadow, Font as SvgFont, TextSvg}; + const REFERENCE_WIDTH: f32 = 1920.0; const REFERENCE_HEIGHT: f32 = 1080.0; @@ -542,23 +544,15 @@ pub(crate) fn slide_view<'a>( responsive(move |size| { let width = size.height * 16.0 / 9.0; let font_size = scale_font(slide.font_size() as f32, width); + let font = SvgFont::from(font).size(font_size.floor() as u8); let slide_text = slide.text(); - let lines = slide_text.lines(); - let text: Vec> = lines - .map(|t| { - rich_text([span(format!("{}\n", t.to_string())) - .background( - Background::Color(Color::BLACK) - .scale_alpha(0.4), - ) - .padding(3)]) - .size(font_size) - .font(font) - .center() - .into() - }) - .collect(); - let text = Column::with_children(text).spacing(6); + let text = text_svg::TextSvg::new() + .fill("#fff") + .shadow(shadow(10, 10, 5, "#000000")) + .font(font) + .text(slide_text) + .view() + .map(|m| Message::None); let text_container = Container::new(text) .center(Length::Fill) .align_x(Horizontal::Left); diff --git a/src/ui/text_svg.rs b/src/ui/text_svg.rs index ea6f24c..decb3a3 100644 --- a/src/ui/text_svg.rs +++ b/src/ui/text_svg.rs @@ -2,11 +2,14 @@ use std::fmt::Display; use colors_transform::Rgb; use cosmic::{ - iced::font::{Style, Weight}, + iced::{ + font::{Style, Weight}, + Length, + }, prelude::*, - widget::{responsive, svg::Handle, Svg}, + widget::{container, responsive, svg::Handle, Svg}, }; -use tracing::error; +use tracing::{debug, error}; #[derive(Clone, Debug, Default, PartialEq)] pub struct TextSvg { @@ -25,6 +28,21 @@ pub struct Font { size: u8, } +impl From for Font { + fn from(value: cosmic::font::Font) -> Self { + Self { + name: match value.family { + cosmic::iced::font::Family::Name(name) => { + name.to_string() + } + _ => "Quicksand Bold".into(), + }, + size: 20, + ..Default::default() + } + } +} + impl From<&str> for Font { fn from(value: &str) -> Self { Self { @@ -35,32 +53,37 @@ impl From<&str> for Font { } impl Font { - fn get_name(&self) -> String { + pub fn get_name(&self) -> String { self.name.clone() } - fn get_weight(&self) -> Weight { + pub fn get_weight(&self) -> Weight { self.weight.clone() } - fn get_style(&self) -> Style { + pub fn get_style(&self) -> Style { self.style.clone() } - fn weight(mut self, weight: impl Into) -> Self { + pub fn weight(mut self, weight: impl Into) -> Self { self.weight = weight.into(); self } - fn style(mut self, style: impl Into