fix slide_editor not building
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Chris Cochrun 2025-08-21 11:58:03 -05:00
parent 77af1ebaf4
commit 53555087a7
2 changed files with 84 additions and 59 deletions

View file

@ -1,23 +1,27 @@
use std::{io, path::PathBuf};
use cosmic::{
iced::{Color, Font},
iced::{Color, Font, Length},
prelude::*,
widget::{
self,
canvas::{self, Program, Stroke},
container, Canvas,
},
Renderer,
};
use tracing::debug;
#[derive(Debug, Default)]
struct State {
cache: canvas::Cache,
}
#[derive(Debug)]
struct SlideEditor<'a> {
state: &'a State,
font: &'a Font,
#[derive(Debug, Default)]
pub struct SlideEditor {
state: State,
font: Font,
program: EditorProgram,
}
#[derive(Debug, Clone)]
@ -45,23 +49,33 @@ pub enum SlideError {
IOError(io::ErrorKind),
}
impl State {
#[derive(Debug, Default)]
struct EditorProgram {}
impl SlideEditor {
pub fn view<'a>(
&'a self,
font: &'a Font,
) -> cosmic::iced::Element<'a, SlideWidget> {
widget::canvas(SlideEditor { state: self, font }).into()
font: Font,
) -> cosmic::Element<'a, SlideWidget> {
container(
widget::canvas(&self.program)
.height(Length::Fill)
.width(Length::Fill),
)
.into()
}
}
impl<'a> Program<SlideWidget> for SlideEditor<'a> {
impl<'a> Program<SlideWidget, cosmic::Theme, cosmic::Renderer>
for EditorProgram
{
type State = ();
fn draw(
&self,
state: &Self::State,
renderer: &Renderer,
theme: &cosmic::iced_runtime::core::Theme,
theme: &cosmic::Theme,
bounds: cosmic::iced::Rectangle,
cursor: cosmic::iced_core::mouse::Cursor,
) -> Vec<canvas::Geometry<Renderer>> {
@ -93,23 +107,27 @@ impl<'a> Program<SlideWidget> for SlideEditor<'a> {
) -> (canvas::event::Status, Option<SlideWidget>) {
match event {
canvas::Event::Mouse(event) => match event {
cosmic::iced::mouse::Event::CursorEntered => todo!(),
cosmic::iced::mouse::Event::CursorLeft => todo!(),
cosmic::iced::mouse::Event::CursorEntered => {
debug!("cursor entered")
}
cosmic::iced::mouse::Event::CursorLeft => {
debug!("cursor left")
}
cosmic::iced::mouse::Event::CursorMoved {
position,
} => todo!(),
} => debug!(?position, "cursor moved"),
cosmic::iced::mouse::Event::ButtonPressed(button) => {
todo!()
debug!(?button, "mouse button pressed")
}
cosmic::iced::mouse::Event::ButtonReleased(
button,
) => todo!(),
) => debug!(?button, "mouse button released"),
cosmic::iced::mouse::Event::WheelScrolled {
delta,
} => todo!(),
} => debug!(?delta, "scroll wheel"),
},
canvas::Event::Touch(event) => todo!(),
canvas::Event::Keyboard(event) => todo!(),
canvas::Event::Touch(event) => debug!("test"),
canvas::Event::Keyboard(event) => debug!("test"),
}
(canvas::event::Status::Ignored, None)
}

View file

@ -21,6 +21,7 @@ use tracing::{debug, error};
use crate::{
core::{service_items::ServiceTrait, songs::Song},
ui::slide_editor::{self, SlideEditor},
Background, BackgroundKind,
};
@ -45,6 +46,7 @@ pub struct SongEditor {
video: Option<Video>,
current_font: Font,
ccli: String,
slide_state: SlideEditor,
}
pub enum Action {
@ -133,6 +135,7 @@ impl SongEditor {
video: None,
current_font: cosmic::font::default(),
ccli: "8".to_owned(),
slide_state: SlideEditor::default(),
}
}
pub fn update(&mut self, message: Message) -> Action {
@ -285,46 +288,50 @@ impl SongEditor {
}
fn slide_preview(&self) -> Element<Message> {
if let Some(song) = &self.song {
if let Ok(slides) = song.to_slides() {
let slides = slides
.iter()
.enumerate()
.map(|(index, slide)| {
container(
slide_view(
slide.clone(),
if index == 0 {
&self.video
} else {
&None
},
self.current_font,
false,
false,
)
.map(|_| Message::None),
)
.height(250)
.center_x(Length::Fill)
.padding([0, 20])
.clip(true)
.into()
})
.collect();
scrollable(
column::with_children(slides)
.spacing(theme::active().cosmic().space_l()),
)
.height(Length::Fill)
.width(Length::Fill)
.into()
} else {
horizontal_space().into()
}
} else {
horizontal_space().into()
}
// if let Some(song) = &self.song {
// if let Ok(slides) = song.to_slides() {
// let slides = slides
// .iter()
// .enumerate()
// .map(|(index, slide)| {
// container(
// slide_view(
// slide.clone(),
// if index == 0 {
// &self.video
// } else {
// &None
// },
// self.current_font,
// false,
// false,
// )
// .map(|_| Message::None),
// )
// .height(250)
// .center_x(Length::Fill)
// .padding([0, 20])
// .clip(true)
// .into()
// })
// .collect();
// scrollable(
// column::with_children(slides)
// .spacing(theme::active().cosmic().space_l()),
// )
// .height(Length::Fill)
// .width(Length::Fill)
// .into()
// } else {
// horizontal_space().into()
// }
// } else {
// horizontal_space().into()
// }
self.slide_state
.view(Font::with_name("Quicksand Bold"))
.map(|_s| Message::None)
.into()
}
fn left_column(&self) -> Element<Message> {