From 77af1ebaf47783a4e66450cc2b8aeb81ab4f306d Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Wed, 20 Aug 2025 15:07:23 -0500 Subject: [PATCH] add slide_editor --- src/ui/mod.rs | 1 + src/ui/slide_editor.rs | 125 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 src/ui/slide_editor.rs diff --git a/src/ui/mod.rs b/src/ui/mod.rs index ff81e8c..0289c38 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -7,6 +7,7 @@ pub mod song_editor; pub mod text_svg; pub mod video; pub mod widgets; +pub mod slide_editor; pub enum EditorMode { Song, diff --git a/src/ui/slide_editor.rs b/src/ui/slide_editor.rs new file mode 100644 index 0000000..d05d2af --- /dev/null +++ b/src/ui/slide_editor.rs @@ -0,0 +1,125 @@ +use std::{io, path::PathBuf}; + +use cosmic::{ + iced::{Color, Font}, + widget::{ + self, + canvas::{self, Program, Stroke}, + }, + Renderer, +}; + +#[derive(Debug, Default)] +struct State { + cache: canvas::Cache, +} + +#[derive(Debug)] +struct SlideEditor<'a> { + state: &'a State, + font: &'a Font, +} + +#[derive(Debug, Clone)] +pub enum Message { + ChangeFont(String), + ChangeFontSize(usize), + ChangeTitle(String), + ChangeBackground(Result), + PickBackground, + Edit(bool), + None, +} + +pub struct Text { + text: String, +} + +pub enum SlideWidget { + Text(Text), +} + +#[derive(Debug, Clone)] +pub enum SlideError { + DialogClosed, + IOError(io::ErrorKind), +} + +impl State { + pub fn view<'a>( + &'a self, + font: &'a Font, + ) -> cosmic::iced::Element<'a, SlideWidget> { + widget::canvas(SlideEditor { state: self, font }).into() + } +} + +impl<'a> Program for SlideEditor<'a> { + type State = (); + + fn draw( + &self, + state: &Self::State, + renderer: &Renderer, + theme: &cosmic::iced_runtime::core::Theme, + bounds: cosmic::iced::Rectangle, + cursor: cosmic::iced_core::mouse::Cursor, + ) -> Vec> { + // We prepare a new `Frame` + let mut frame = canvas::Frame::new(renderer, bounds.size()); + + // We create a `Path` representing a simple circle + let circle = canvas::Path::circle(frame.center(), 50.0); + + // And fill it with some color + frame.fill(&circle, Color::BLACK); + frame.stroke( + &circle, + Stroke::default() + .with_width(5.0) + .with_color(Color::BLACK), + ); + + // Then, we produce the geometry + vec![frame.into_geometry()] + } + + fn update( + &self, + _state: &mut Self::State, + event: canvas::Event, + _bounds: cosmic::iced::Rectangle, + _cursor: cosmic::iced_core::mouse::Cursor, + ) -> (canvas::event::Status, Option) { + match event { + canvas::Event::Mouse(event) => match event { + cosmic::iced::mouse::Event::CursorEntered => todo!(), + cosmic::iced::mouse::Event::CursorLeft => todo!(), + cosmic::iced::mouse::Event::CursorMoved { + position, + } => todo!(), + cosmic::iced::mouse::Event::ButtonPressed(button) => { + todo!() + } + cosmic::iced::mouse::Event::ButtonReleased( + button, + ) => todo!(), + cosmic::iced::mouse::Event::WheelScrolled { + delta, + } => todo!(), + }, + canvas::Event::Touch(event) => todo!(), + canvas::Event::Keyboard(event) => todo!(), + } + (canvas::event::Status::Ignored, None) + } + + fn mouse_interaction( + &self, + _state: &Self::State, + _bounds: cosmic::iced::Rectangle, + _cursor: cosmic::iced_core::mouse::Cursor, + ) -> cosmic::iced_core::mouse::Interaction { + cosmic::iced_core::mouse::Interaction::default() + } +}