making presentation_editor only need one page at a time
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Chris Cochrun 2025-09-30 05:51:33 -05:00
parent ee45a11a0f
commit 19e8fbcc35
2 changed files with 100 additions and 42 deletions

View file

@ -1182,10 +1182,43 @@ impl cosmic::Application for App {
Message::AddServiceItem(index, item) => {
let item_index = item.0 .1;
let kind = item.0 .0;
let mut item;
match kind {
core::model::LibraryKind::Song => todo!(),
core::model::LibraryKind::Video => todo!(),
core::model::LibraryKind::Image => todo!(),
core::model::LibraryKind::Song => {
let Some(library) = self.library.as_mut()
else {
return Task::none();
};
let Some(song) = library.get_song(item_index)
else {
return Task::none();
};
item = song.to_service_item();
}
core::model::LibraryKind::Video => {
let Some(library) = self.library.as_mut()
else {
return Task::none();
};
let Some(video) =
library.get_video(item_index)
else {
return Task::none();
};
item = video.to_service_item();
}
core::model::LibraryKind::Image => {
let Some(library) = self.library.as_mut()
else {
return Task::none();
};
let Some(image) =
library.get_image(item_index)
else {
return Task::none();
};
item = image.to_service_item();
}
core::model::LibraryKind::Presentation => {
let Some(library) = self.library.as_mut()
else {
@ -1196,23 +1229,22 @@ impl cosmic::Application for App {
else {
return Task::none();
};
let mut item = presentation.to_service_item();
item.slides = item
.slides
.into_par_iter()
.map(|mut slide| {
let fontdb = Arc::clone(&self.fontdb);
text_svg::text_svg_generator(
&mut slide, fontdb,
);
slide
})
.collect();
self.service.insert(index, item);
self.presenter
.update_items(self.service.clone());
item = presentation.to_service_item();
}
}
item.slides = item
.slides
.into_par_iter()
.map(|mut slide| {
let fontdb = Arc::clone(&self.fontdb);
text_svg::text_svg_generator(
&mut slide, fontdb,
);
slide
})
.collect();
self.service.insert(index, item);
self.presenter.update_items(self.service.clone());
Task::none()
}
Message::RemoveServiceItem(index) => {

View file

@ -10,20 +10,25 @@ use cosmic::{
iced_widget::{column, row},
theme,
widget::{
button, container, horizontal_space, icon, image, text,
text_input, Space,
self, button, container, horizontal_space, icon,
image::{self, Handle},
text, text_input, Space,
},
Element, Task,
};
use miette::IntoDiagnostic;
use mupdf::{Colorspace, Document, Matrix};
use tracing::{debug, error, warn};
#[derive(Debug)]
pub struct PresentationEditor {
pub presentation: Option<Presentation>,
slides: Option<Vec<Slide>>,
document: Option<Document>,
current_slide: Option<Handle>,
page_count: Option<i32>,
current_slide_index: Option<i32>,
title: String,
editing: bool,
current_slide: i16,
}
pub enum Action {
@ -46,10 +51,12 @@ impl PresentationEditor {
pub fn new() -> Self {
Self {
presentation: None,
slides: None,
document: None,
title: "Death was Arrested".to_string(),
editing: false,
current_slide: 0,
current_slide: None,
current_slide_index: None,
page_count: None,
}
}
pub fn update(&mut self, message: Message) -> Action {
@ -57,12 +64,40 @@ impl PresentationEditor {
Message::ChangePresentation(presentation) => {
self.presentation = Some(presentation.clone());
self.title = presentation.title.clone();
self.document =
Document::open(&presentation.path.as_path()).ok();
self.page_count = self
.document
.as_ref()
.and_then(|doc| doc.page_count().ok());
warn!("changing presentation");
let Ok(slides) = presentation.to_slides() else {
return Action::None;
};
self.slides = Some(slides);
self.current_slide = 0;
self.current_slide =
self.document.as_ref().and_then(|doc| {
let page = doc.load_page(0).ok()?;
let matrix = Matrix::IDENTITY;
let colorspace = Colorspace::device_rgb();
let Ok(pixmap) = page
.to_pixmap(
&matrix,
&colorspace,
true,
true,
)
.into_diagnostic()
else {
error!(
"Can't turn this page into pixmap"
);
return None;
};
debug!(?pixmap);
Some(Handle::from_rgba(
pixmap.width(),
pixmap.height(),
pixmap.samples().to_vec(),
))
});
self.current_slide_index = Some(0);
return self.update(Message::Update(presentation));
}
Message::ChangeTitle(title) => {
@ -110,19 +145,10 @@ impl PresentationEditor {
}
pub fn view(&self) -> Element<Message> {
let container = if let Some(slides) = &self.slides {
if let Some(slide) =
slides.get(self.current_slide as usize)
{
container(
image(slide.pdf_page().unwrap_or(
image::Handle::from_path("res/chad.png"),
))
.content_fit(ContentFit::Cover),
)
} else {
container(Space::new(0, 0))
}
let container = if let Some(slide) = &self.current_slide {
container(
widget::image(slide).content_fit(ContentFit::Cover),
)
} else {
container(Space::new(0, 0))
};