From 004eb60470abde64e5390919c55873d0a04c036e Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Sat, 16 Aug 2025 22:51:26 -0500 Subject: [PATCH] changing slides works better now --- src/core/service_items.rs | 15 ++++++------ src/main.rs | 51 ++++++++++++++++++++++++++++++++++++--- src/ui/presenter.rs | 36 +++++++++++++++------------ src/ui/song_editor.rs | 4 +-- 4 files changed, 78 insertions(+), 28 deletions(-) diff --git a/src/core/service_items.rs b/src/core/service_items.rs index 1d24cee..b0b9da5 100644 --- a/src/core/service_items.rs +++ b/src/core/service_items.rs @@ -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, + pub slides: Arc<[Slide]>, // pub item: Box, } @@ -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 { diff --git a/src/main.rs b/src/main.rs index dd53574..d0e4eb0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -103,6 +103,7 @@ struct App { presenter: Presenter, windows: Vec, service: Vec, + current_item: (usize, usize), presentation_open: bool, cli_mode: bool, library: Option, @@ -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(), diff --git a/src/ui/presenter.rs b/src/ui/presenter.rs index 4768c4b..f732019 100644 --- a/src/ui/presenter.rs +++ b/src/ui/presenter.rs @@ -61,6 +61,8 @@ pub(crate) struct Presenter { pub(crate) enum Action { Task(Task), + 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 { 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 { 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