From bdbcf5da5608db51ffe43f24a3c318a6fa55599b Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Sat, 2 Nov 2024 13:37:33 -0500 Subject: [PATCH] using the slides backgrounds --- src/core/slide.rs | 4 ++-- src/main.rs | 8 +++++-- src/ui/presenter.rs | 54 +++++++++++++++++++++++++-------------------- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/core/slide.rs b/src/core/slide.rs index b89c5ff..47cd1f3 100644 --- a/src/core/slide.rs +++ b/src/core/slide.rs @@ -145,8 +145,8 @@ pub struct Slide { } impl Slide { - pub fn background(&self) -> &PathBuf { - &self.background.path + pub fn background(&self) -> &Background { + &self.background } pub fn text(&self) -> String { diff --git a/src/main.rs b/src/main.rs index 854b592..419d4eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -126,7 +126,11 @@ impl cosmic::Application for App { windows.push(core.main_window_id().unwrap()); } let initial_slide = SlideBuilder::new() - .background(PathBuf::from("/home/chris/vids/test/camprules2024.mp4")) + .background( + PathBuf::from("/home/chris/vids/test/chosensmol.mp4") + .canonicalize() + .unwrap(), + ) .expect("oops video") .text("Hello") .font("Quicksand") @@ -358,7 +362,7 @@ fn test_slide<'a>() -> Element<'a, Message> { { let font = Font::with_name("Noto Sans"); let stack = stack!( - image(slide.background()), + image(slide.background().path.clone()), text(slide.text()).size(slide.font_size() as u16).font(font) ); diff --git a/src/ui/presenter.rs b/src/ui/presenter.rs index f56369e..85fa4a9 100644 --- a/src/ui/presenter.rs +++ b/src/ui/presenter.rs @@ -5,7 +5,7 @@ use cosmic::{ iced::{widget::text, ContentFit, Length}, iced_widget::stack, prelude::*, - widget::{image, Container, Space}, + widget::{container, image, Container, Space}, Task, }; use iced_video_player::{Video, VideoPlayer}; @@ -31,12 +31,11 @@ pub(crate) enum Message { impl Presenter { pub fn with_initial_slide(slide: Slide) -> Self { Self { - slides: vec![slide], + slides: vec![slide.clone()], current_slide: 0, video: { - if let Ok(path) = - PathBuf::from("/home/chris/vids/test/chosensmol.mp4").canonicalize() - { + let path = slide.background().path.clone(); + if path.exists() { let url = Url::from_file_path(path).unwrap(); let result = Video::new(&url); match result { @@ -72,28 +71,35 @@ impl Presenter { } pub fn view(&self) -> Element { - // let window = self.windows.iter().position(|w| *w == id).unwrap(); - // if let Some(_window) = self.windows.get(window) {} let text = text!("This is frodo").size(50); let text = Container::new(text).center(Length::Fill); - let image = Container::new( - image("/home/chris/pics/frodo.jpg") - .content_fit(ContentFit::Cover) - .width(Length::Fill) - .height(Length::Fill), - ); - let vid_container; - if let Some(video) = &self.video { - vid_container = Container::new( - VideoPlayer::new(video) + let container = match self + .slides + .get(self.current_slide as usize) + .unwrap() + .background() + .kind + { + crate::BackgroundKind::Image => Container::new( + image("/home/chris/pics/frodo.jpg") + .content_fit(ContentFit::Cover) .width(Length::Fill) - .height(Length::Fill) - .content_fit(ContentFit::Cover), - ); - } else { - vid_container = Container::new(Space::new(0, 0)); - } - let stack = stack!(image, vid_container, text) + .height(Length::Fill), + ), + crate::BackgroundKind::Video => { + if let Some(video) = &self.video { + Container::new( + VideoPlayer::new(video) + .width(Length::Fill) + .height(Length::Fill) + .content_fit(ContentFit::Cover), + ) + } else { + Container::new(Space::new(0, 0)) + } + } + }; + let stack = stack!(container, text) .width(Length::Fill) .height(Length::Fill); stack.into()