text now fits the slide on both previews and real pres

This commit is contained in:
Chris Cochrun 2024-12-06 12:50:38 -06:00
parent 9695c8670f
commit 44aab37447
3 changed files with 47 additions and 14 deletions

View file

@ -8,3 +8,6 @@ clean:
RUST_LOG=debug cargo clean RUST_LOG=debug cargo clean
test: test:
RUST_LOG=debug cargo test --benches --tests --all-features -- --nocapture RUST_LOG=debug cargo test --benches --tests --all-features -- --nocapture
alias r := run
alias c := clean

View file

@ -550,6 +550,7 @@ impl cosmic::Application for App {
.slide_preview() .slide_preview()
.map(|m| Message::Present(m)) .map(|m| Message::Present(m))
) )
.width(Length::Fill)
.center_y(100) .center_y(100)
]; ];

View file

@ -2,10 +2,17 @@ use std::{path::PathBuf, rc::Rc, time::Duration};
use cosmic::{ use cosmic::{
dialog::ashpd::url::Url, 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, iced_widget::stack,
prelude::*, prelude::*,
widget::{container, image, Container, Row, Space}, widget::{
canvas::path::lyon_path::geom::euclid::num::Floor, container,
image, Container, Responsive, Row, Space,
},
Task, Task,
}; };
use iced_video_player::{Position, Video, VideoPlayer}; use iced_video_player::{Position, Video, VideoPlayer};
@ -161,13 +168,31 @@ impl Presenter {
} }
pub fn view(&self) -> Element<Message> { pub fn view(&self) -> Element<Message> {
let font_size = if self.current_slide.font_size() > 0 { let family = Family::Name("Quicksand");
self.current_slide.font_size() as u16 let weight = Weight::Normal;
} else { let stretch = Stretch::Normal;
50 let style = Style::Normal;
let font = Font {
family,
weight,
stretch,
style,
}; };
let text = text(self.current_slide.text()).size(font_size); let text = Responsive::new(move |size| {
let text = Container::new(text).center(Length::Fill); 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)) let black = Container::new(Space::new(0, 0))
.style(|_| { .style(|_| {
container::background(Background::Color(Color::BLACK)) container::background(Background::Color(Color::BLACK))
@ -223,12 +248,16 @@ impl Presenter {
let text = text(slide.text()).size(font_size); let text = text(slide.text()).size(font_size);
let text = Container::new(text).center(Length::Fill); let text = Container::new(text).center(Length::Fill);
let container = match slide.background().kind { let container = match slide.background().kind {
crate::BackgroundKind::Image => Container::new( crate::BackgroundKind::Image => {
image("/home/chris/pics/frodo.jpg") let path = slide.background().path.clone();
.content_fit(ContentFit::Cover)
.width(Length::Fill) Container::new(
.height(Length::Fill), image(path)
), .content_fit(ContentFit::Cover)
.width(Length::Fill)
.height(Length::Fill),
)
}
crate::BackgroundKind::Video => { crate::BackgroundKind::Video => {
Container::new(Space::new(Length::Fill, Length::Fill)) Container::new(Space::new(Length::Fill, Length::Fill))
} }