trying to make the slide preview more composable
This commit is contained in:
parent
f81efdeef3
commit
029188d632
2 changed files with 75 additions and 19 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::path::PathBuf;
|
||||
use std::{path::PathBuf, rc::Rc};
|
||||
|
||||
use cosmic::{
|
||||
dialog::ashpd::url::Url,
|
||||
|
@ -11,14 +11,14 @@ use cosmic::{
|
|||
Task,
|
||||
};
|
||||
use iced_video_player::{Video, VideoPlayer};
|
||||
use miette::{Context, IntoDiagnostic};
|
||||
use miette::{Context, IntoDiagnostic, Result};
|
||||
use tracing::{debug, error};
|
||||
|
||||
use crate::core::slide::Slide;
|
||||
|
||||
// #[derive(Default, Clone, Debug)]
|
||||
pub(crate) struct Presenter<'a> {
|
||||
pub slides: &'a Vec<Slide>,
|
||||
pub(crate) struct Presenter {
|
||||
pub slides: Vec<Slide>,
|
||||
pub current_slide: i16,
|
||||
pub video: Option<Video>,
|
||||
}
|
||||
|
@ -30,12 +30,31 @@ pub(crate) enum Message {
|
|||
SlideChange(u8),
|
||||
}
|
||||
|
||||
impl<'a> Presenter<'a> {
|
||||
pub fn with_app_slides(slides: &'a Vec<Slide>) -> Self {
|
||||
impl Presenter {
|
||||
pub fn with_app_slides(slides: Vec<Slide>) -> Self {
|
||||
Self {
|
||||
slides: slides,
|
||||
slides: slides.clone(),
|
||||
current_slide: 0,
|
||||
video: None,
|
||||
video: {
|
||||
if let Some(slide) = slides.get(0) {
|
||||
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) => Some(v),
|
||||
Err(e) => {
|
||||
error!("Had an error creating the video object: {e}");
|
||||
None
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
// pub fn with_initial_slide(slide: Slide) -> Self {
|
||||
|
@ -117,3 +136,35 @@ impl<'a> Presenter<'a> {
|
|||
stack.into()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn slide_view<'a>(
|
||||
slide: &'a Slide,
|
||||
video: &'a Option<Video>,
|
||||
) -> Element<'a, Message> {
|
||||
let text = text!("{}", slide.text()).size(50);
|
||||
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 => {
|
||||
if let Some(video) = video {
|
||||
Container::new(
|
||||
VideoPlayer::new(video)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.content_fit(ContentFit::Cover),
|
||||
)
|
||||
} else {
|
||||
Container::new(Space::new(Length::Fill, Length::Fill))
|
||||
}
|
||||
}
|
||||
};
|
||||
let stack = stack!(container, text)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill);
|
||||
stack.into()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue