This commit is contained in:
parent
abcb283a0d
commit
004eb60470
4 changed files with 78 additions and 28 deletions
|
@ -1,6 +1,7 @@
|
|||
use std::borrow::Cow;
|
||||
use std::cmp::Ordering;
|
||||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
|
||||
use cosmic::iced::clipboard::mime::{AllowedMimeTypes, AsMimeTypes};
|
||||
use crisp::types::{Keyword, Symbol, Value};
|
||||
|
@ -22,7 +23,7 @@ pub struct ServiceItem {
|
|||
pub title: String,
|
||||
pub database_id: i32,
|
||||
pub kind: ServiceItemKind,
|
||||
pub slides: Vec<Slide>,
|
||||
pub slides: Arc<[Slide]>,
|
||||
// pub item: Box<dyn ServiceTrait>,
|
||||
}
|
||||
|
||||
|
@ -121,7 +122,7 @@ impl Default for ServiceItem {
|
|||
title: String::default(),
|
||||
database_id: 0,
|
||||
kind: ServiceItemKind::Content(Slide::default()),
|
||||
slides: vec![],
|
||||
slides: Arc::new([]),
|
||||
// item: Box::new(Image::default()),
|
||||
}
|
||||
}
|
||||
|
@ -171,7 +172,7 @@ impl From<&Value> for ServiceItem {
|
|||
kind: ServiceItemKind::Content(
|
||||
slide.clone(),
|
||||
),
|
||||
slides: vec![slide],
|
||||
slides: Arc::new([slide]),
|
||||
}
|
||||
} else if let Some(background) =
|
||||
list.get(background_pos)
|
||||
|
@ -262,7 +263,7 @@ impl From<&Song> for ServiceItem {
|
|||
kind: ServiceItemKind::Song(song.clone()),
|
||||
database_id: song.id,
|
||||
title: song.title.clone(),
|
||||
slides,
|
||||
slides: slides.into(),
|
||||
..Default::default()
|
||||
}
|
||||
} else {
|
||||
|
@ -283,7 +284,7 @@ impl From<&Video> for ServiceItem {
|
|||
kind: ServiceItemKind::Video(video.clone()),
|
||||
database_id: video.id,
|
||||
title: video.title.clone(),
|
||||
slides,
|
||||
slides: slides.into(),
|
||||
..Default::default()
|
||||
}
|
||||
} else {
|
||||
|
@ -304,7 +305,7 @@ impl From<&Image> for ServiceItem {
|
|||
kind: ServiceItemKind::Image(image.clone()),
|
||||
database_id: image.id,
|
||||
title: image.title.clone(),
|
||||
slides,
|
||||
slides: slides.into(),
|
||||
..Default::default()
|
||||
}
|
||||
} else {
|
||||
|
@ -327,7 +328,7 @@ impl From<&Presentation> for ServiceItem {
|
|||
),
|
||||
database_id: presentation.id,
|
||||
title: presentation.title.clone(),
|
||||
slides,
|
||||
slides: slides.into(),
|
||||
..Default::default()
|
||||
}
|
||||
} else {
|
||||
|
|
51
src/main.rs
51
src/main.rs
|
@ -103,6 +103,7 @@ struct App {
|
|||
presenter: Presenter,
|
||||
windows: Vec<window::Id>,
|
||||
service: Vec<ServiceItem>,
|
||||
current_item: (usize, usize),
|
||||
presentation_open: bool,
|
||||
cli_mode: bool,
|
||||
library: Option<Library>,
|
||||
|
@ -214,6 +215,7 @@ impl cosmic::Application for App {
|
|||
editor_mode: None,
|
||||
song_editor,
|
||||
searching: false,
|
||||
current_item: (0, 0),
|
||||
};
|
||||
|
||||
let mut batch = vec![];
|
||||
|
@ -569,12 +571,49 @@ impl cosmic::Application for App {
|
|||
}
|
||||
}
|
||||
match self.presenter.update(message) {
|
||||
// debug!(?x);
|
||||
// cosmic::app::Message::App(Message::None)
|
||||
presenter::Action::Task(task) => task.map(|m| {
|
||||
cosmic::Action::App(Message::Present(m))
|
||||
}),
|
||||
presenter::Action::None => Task::none(),
|
||||
presenter::Action::NextSlide => {
|
||||
let slide_index = self.current_item.1;
|
||||
let item_index = self.current_item.0;
|
||||
if let Some(item) =
|
||||
self.service.get(item_index)
|
||||
{
|
||||
if item.slides.len() > slide_index + 1 {
|
||||
let slide_length = item.slides.len();
|
||||
debug!(
|
||||
slide_index,
|
||||
slide_length,
|
||||
?item,
|
||||
"Slides are longer"
|
||||
);
|
||||
let slide = item.slides
|
||||
[slide_index + 1]
|
||||
.clone();
|
||||
self.presenter.update(
|
||||
presenter::Message::SlideChange(
|
||||
slide,
|
||||
),
|
||||
);
|
||||
Task::none()
|
||||
} else {
|
||||
debug!("Slides are not longer");
|
||||
self.current_item =
|
||||
(item_index + 1, 0);
|
||||
if let Some(item) =
|
||||
self.service.get(item_index + 1)
|
||||
{
|
||||
self.presenter.update(presenter::Message::SlideChange(item.slides[0].clone()));
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
} else {
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
presenter::Action::PrevSlide => todo!(),
|
||||
}
|
||||
}
|
||||
Message::Library(message) => {
|
||||
|
@ -750,8 +789,14 @@ impl cosmic::Application for App {
|
|||
Task::none()
|
||||
}
|
||||
Message::ChangeServiceItem(index) => {
|
||||
if let Some(item) = self.service.get(index) {
|
||||
if let Some((index, item)) = self
|
||||
.service
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(id, _)| index == *id)
|
||||
{
|
||||
if let Some(slide) = item.slides.first() {
|
||||
self.current_item = (index, 0);
|
||||
self.presenter.update(
|
||||
presenter::Message::SlideChange(
|
||||
slide.clone(),
|
||||
|
|
|
@ -61,6 +61,8 @@ pub(crate) struct Presenter {
|
|||
|
||||
pub(crate) enum Action {
|
||||
Task(Task<Message>),
|
||||
NextSlide,
|
||||
PrevSlide,
|
||||
None,
|
||||
}
|
||||
|
||||
|
@ -177,23 +179,25 @@ impl Presenter {
|
|||
pub fn update(&mut self, message: Message) -> Action {
|
||||
match message {
|
||||
Message::NextSlide => {
|
||||
debug!("next slide");
|
||||
if self.slides.len() as u16 - 1
|
||||
== self.current_slide_index
|
||||
{
|
||||
debug!("no more slides");
|
||||
return Action::None;
|
||||
}
|
||||
return Action::NextSlide;
|
||||
// debug!("next slide");
|
||||
// if self.slides.len() as u16 - 1
|
||||
// == self.current_slide_index
|
||||
// {
|
||||
// debug!("no more slides");
|
||||
// return Action::None;
|
||||
// }
|
||||
// return self.update(Message::SlideChange(
|
||||
// self.current_slide_index + 1,
|
||||
// ));
|
||||
}
|
||||
Message::PrevSlide => {
|
||||
debug!("prev slide");
|
||||
if 0 == self.current_slide_index {
|
||||
debug!("beginning slides");
|
||||
return Action::None;
|
||||
}
|
||||
return Action::PrevSlide;
|
||||
// debug!("prev slide");
|
||||
// if 0 == self.current_slide_index {
|
||||
// debug!("beginning slides");
|
||||
// return Action::None;
|
||||
// }
|
||||
// return self.update(Message::SlideChange(
|
||||
// self.current_slide_index - 1,
|
||||
// ));
|
||||
|
@ -383,7 +387,7 @@ impl Presenter {
|
|||
|
||||
pub fn view(&self) -> Element<Message> {
|
||||
slide_view(
|
||||
&self.current_slide,
|
||||
self.current_slide.clone(),
|
||||
&self.video,
|
||||
self.current_font,
|
||||
false,
|
||||
|
@ -393,7 +397,7 @@ impl Presenter {
|
|||
|
||||
pub fn view_preview(&self) -> Element<Message> {
|
||||
slide_view(
|
||||
&self.current_slide,
|
||||
self.current_slide.clone(),
|
||||
&self.video,
|
||||
self.current_font,
|
||||
false,
|
||||
|
@ -436,7 +440,7 @@ impl Presenter {
|
|||
as i32;
|
||||
|
||||
let container =
|
||||
slide_view(&slide, &self.video, font, true, false);
|
||||
slide_view(slide.clone(), &self.video, font, true, false);
|
||||
let delegate = mouse_area(
|
||||
Container::new(container)
|
||||
.style(move |t| {
|
||||
|
@ -543,7 +547,7 @@ fn scale_font(font_size: f32, width: f32) -> f32 {
|
|||
}
|
||||
|
||||
pub(crate) fn slide_view<'a>(
|
||||
slide: &'a Slide,
|
||||
slide: Slide,
|
||||
video: &'a Option<Video>,
|
||||
font: Font,
|
||||
delegate: bool,
|
||||
|
|
|
@ -289,12 +289,12 @@ impl SongEditor {
|
|||
if let Some(song) = &self.song {
|
||||
if let Ok(slides) = song.to_slides() {
|
||||
let slides = slides
|
||||
.into_iter()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, slide)| {
|
||||
container(
|
||||
slide_view(
|
||||
&slide,
|
||||
slide.clone(),
|
||||
if index == 0 {
|
||||
&self.video
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue