From 44aab37447a6e97fa52ccd2437cb3dafb5b32e73 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Fri, 6 Dec 2024 12:50:38 -0600 Subject: [PATCH] text now fits the slide on both previews and real pres --- justfile | 3 +++ src/main.rs | 1 + src/ui/presenter.rs | 57 ++++++++++++++++++++++++++++++++++----------- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/justfile b/justfile index b8589fd..d6e55c4 100644 --- a/justfile +++ b/justfile @@ -8,3 +8,6 @@ clean: RUST_LOG=debug cargo clean test: RUST_LOG=debug cargo test --benches --tests --all-features -- --nocapture + +alias r := run +alias c := clean diff --git a/src/main.rs b/src/main.rs index d8a449b..d29aa81 100644 --- a/src/main.rs +++ b/src/main.rs @@ -550,6 +550,7 @@ impl cosmic::Application for App { .slide_preview() .map(|m| Message::Present(m)) ) + .width(Length::Fill) .center_y(100) ]; diff --git a/src/ui/presenter.rs b/src/ui/presenter.rs index d64ef26..e4e3585 100644 --- a/src/ui/presenter.rs +++ b/src/ui/presenter.rs @@ -2,10 +2,17 @@ use std::{path::PathBuf, rc::Rc, time::Duration}; use cosmic::{ dialog::ashpd::url::Url, - iced::{widget::text, Background, Color, ContentFit, Length}, + iced::{ + font::{Family, Stretch, Style, Weight}, + widget::text, + Background, Color, ContentFit, Font, Length, + }, iced_widget::stack, prelude::*, - widget::{container, image, Container, Row, Space}, + widget::{ + canvas::path::lyon_path::geom::euclid::num::Floor, container, + image, Container, Responsive, Row, Space, + }, Task, }; use iced_video_player::{Position, Video, VideoPlayer}; @@ -161,13 +168,31 @@ impl Presenter { } pub fn view(&self) -> Element { - let font_size = if self.current_slide.font_size() > 0 { - self.current_slide.font_size() as u16 - } else { - 50 + let family = Family::Name("Quicksand"); + let weight = Weight::Normal; + let stretch = Stretch::Normal; + let style = Style::Normal; + let font = Font { + family, + weight, + stretch, + style, }; - let text = text(self.current_slide.text()).size(font_size); - let text = Container::new(text).center(Length::Fill); + let text = Responsive::new(move |size| { + let font_size = if self.current_slide.font_size() > 0 { + (size.width / self.current_slide.font_size() as f32) + * 3.0 + } else { + 50.0 + }; + debug!(size.width); + debug!(font_size); + let text = text(self.current_slide.text()) + .size(font_size) + .font(font); + let text = Container::new(text).center(Length::Fill); + text.into() + }); let black = Container::new(Space::new(0, 0)) .style(|_| { container::background(Background::Color(Color::BLACK)) @@ -223,12 +248,16 @@ impl Presenter { let text = text(slide.text()).size(font_size); let text = Container::new(text).center(Length::Fill); let container = match slide.background().kind { - crate::BackgroundKind::Image => Container::new( - image("/home/chris/pics/frodo.jpg") - .content_fit(ContentFit::Cover) - .width(Length::Fill) - .height(Length::Fill), - ), + crate::BackgroundKind::Image => { + let path = slide.background().path.clone(); + + Container::new( + image(path) + .content_fit(ContentFit::Cover) + .width(Length::Fill) + .height(Length::Fill), + ) + } crate::BackgroundKind::Video => { Container::new(Space::new(Length::Fill, Length::Fill)) }