utilizing the same video and now changing slides works
This commit is contained in:
parent
e1a397c192
commit
d9459d6336
2 changed files with 102 additions and 101 deletions
|
@ -6,7 +6,7 @@ use cosmic::{
|
|||
iced_widget::{row, stack, Stack},
|
||||
prelude::*,
|
||||
widget::{
|
||||
button, container, icon::Named, image, Container, Space,
|
||||
button, container, icon::Named, image, Container, Row, Space,
|
||||
},
|
||||
Task,
|
||||
};
|
||||
|
@ -14,7 +14,7 @@ use iced_video_player::{Video, VideoPlayer};
|
|||
use miette::{Context, IntoDiagnostic, Result};
|
||||
use tracing::{debug, error};
|
||||
|
||||
use crate::core::slide::Slide;
|
||||
use crate::{core::slide::Slide, BackgroundKind};
|
||||
|
||||
// #[derive(Default, Clone, Debug)]
|
||||
pub(crate) struct Presenter {
|
||||
|
@ -88,10 +88,20 @@ impl Presenter {
|
|||
match message {
|
||||
Message::NextSlide => {
|
||||
debug!("next slide");
|
||||
if let Some(video) = &mut self.video {
|
||||
let _ = video.restart_stream();
|
||||
}
|
||||
self.current_slide += 1;
|
||||
self.reset_video();
|
||||
Task::none()
|
||||
}
|
||||
Message::PrevSlide => {
|
||||
debug!("prev slide");
|
||||
if let Some(video) = &mut self.video {
|
||||
let _ = video.restart_stream();
|
||||
}
|
||||
self.current_slide -= 1;
|
||||
self.reset_video();
|
||||
Task::none()
|
||||
}
|
||||
Message::SlideChange(id) => {
|
||||
|
@ -135,6 +145,61 @@ impl Presenter {
|
|||
.height(Length::Fill)
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn slide_preview(&self) -> Element<Message> {
|
||||
let mut items = vec![];
|
||||
for slide in self.slides.iter() {
|
||||
items.push(Self::slide_delegate(slide));
|
||||
}
|
||||
Row::from_vec(items).spacing(10).padding(10).into()
|
||||
}
|
||||
|
||||
fn slide_delegate(slide: &Slide) -> Element<Message> {
|
||||
let text =
|
||||
text!("{}", slide.text()).size(slide.font_size() as u16);
|
||||
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::Video => {
|
||||
Container::new(Space::new(Length::Fill, Length::Fill))
|
||||
}
|
||||
};
|
||||
stack!(container, text)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn reset_video(&mut self) {
|
||||
if let Some(slide) =
|
||||
self.slides.get(self.current_slide as usize)
|
||||
{
|
||||
match slide.background().kind {
|
||||
BackgroundKind::Image => self.video = None,
|
||||
BackgroundKind::Video => {
|
||||
let path = slide.background().path.clone();
|
||||
if path.exists() {
|
||||
let url = Url::from_file_path(path).unwrap();
|
||||
let result = Video::new(&url);
|
||||
match result {
|
||||
Ok(v) => self.video = Some(v),
|
||||
Err(e) => {
|
||||
error!("Had an error creating the video object: {e}");
|
||||
self.video = None;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.video = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn slide_view<'a>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue