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