using the slides backgrounds

This commit is contained in:
Chris Cochrun 2024-11-02 13:37:33 -05:00
parent db9e8430d9
commit bdbcf5da56
3 changed files with 38 additions and 28 deletions

View file

@ -145,8 +145,8 @@ pub struct Slide {
} }
impl Slide { impl Slide {
pub fn background(&self) -> &PathBuf { pub fn background(&self) -> &Background {
&self.background.path &self.background
} }
pub fn text(&self) -> String { pub fn text(&self) -> String {

View file

@ -126,7 +126,11 @@ impl cosmic::Application for App {
windows.push(core.main_window_id().unwrap()); windows.push(core.main_window_id().unwrap());
} }
let initial_slide = SlideBuilder::new() 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") .expect("oops video")
.text("Hello") .text("Hello")
.font("Quicksand") .font("Quicksand")
@ -358,7 +362,7 @@ fn test_slide<'a>() -> Element<'a, Message> {
{ {
let font = Font::with_name("Noto Sans"); let font = Font::with_name("Noto Sans");
let stack = stack!( let stack = stack!(
image(slide.background()), image(slide.background().path.clone()),
text(slide.text()).size(slide.font_size() as u16).font(font) text(slide.text()).size(slide.font_size() as u16).font(font)
); );

View file

@ -5,7 +5,7 @@ use cosmic::{
iced::{widget::text, ContentFit, Length}, iced::{widget::text, ContentFit, Length},
iced_widget::stack, iced_widget::stack,
prelude::*, prelude::*,
widget::{image, Container, Space}, widget::{container, image, Container, Space},
Task, Task,
}; };
use iced_video_player::{Video, VideoPlayer}; use iced_video_player::{Video, VideoPlayer};
@ -31,12 +31,11 @@ pub(crate) enum Message {
impl Presenter { impl Presenter {
pub fn with_initial_slide(slide: Slide) -> Self { pub fn with_initial_slide(slide: Slide) -> Self {
Self { Self {
slides: vec![slide], slides: vec![slide.clone()],
current_slide: 0, current_slide: 0,
video: { video: {
if let Ok(path) = let path = slide.background().path.clone();
PathBuf::from("/home/chris/vids/test/chosensmol.mp4").canonicalize() if path.exists() {
{
let url = Url::from_file_path(path).unwrap(); let url = Url::from_file_path(path).unwrap();
let result = Video::new(&url); let result = Video::new(&url);
match result { match result {
@ -72,28 +71,35 @@ impl Presenter {
} }
pub fn view(&self) -> Element<Message> { pub fn view(&self) -> Element<Message> {
// 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 = text!("This is frodo").size(50);
let text = Container::new(text).center(Length::Fill); let text = Container::new(text).center(Length::Fill);
let image = Container::new( let container = match self
image("/home/chris/pics/frodo.jpg") .slides
.content_fit(ContentFit::Cover) .get(self.current_slide as usize)
.width(Length::Fill) .unwrap()
.height(Length::Fill), .background()
); .kind
let vid_container; {
if let Some(video) = &self.video { crate::BackgroundKind::Image => Container::new(
vid_container = Container::new( image("/home/chris/pics/frodo.jpg")
VideoPlayer::new(video) .content_fit(ContentFit::Cover)
.width(Length::Fill) .width(Length::Fill)
.height(Length::Fill) .height(Length::Fill),
.content_fit(ContentFit::Cover), ),
); crate::BackgroundKind::Video => {
} else { if let Some(video) = &self.video {
vid_container = Container::new(Space::new(0, 0)); Container::new(
} VideoPlayer::new(video)
let stack = stack!(image, vid_container, text) .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) .width(Length::Fill)
.height(Length::Fill); .height(Length::Fill);
stack.into() stack.into()