From c874590fb1bc63dd647a0d98a7afc477190355b8 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Mon, 25 Aug 2025 15:42:12 -0500 Subject: [PATCH] some testing on slide building --- src/ui/slide_editor.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/ui/slide_editor.rs b/src/ui/slide_editor.rs index fb12342..018e936 100644 --- a/src/ui/slide_editor.rs +++ b/src/ui/slide_editor.rs @@ -1,7 +1,7 @@ use std::{io, path::PathBuf}; use cosmic::{ - iced::{Color, Font, Length}, + iced::{Color, Font, Length, Size}, prelude::*, widget::{ self, @@ -50,7 +50,9 @@ pub enum SlideError { } #[derive(Debug, Default)] -struct EditorProgram {} +struct EditorProgram { + mouse_button_pressed: Option, +} impl SlideEditor { pub fn view<'a>( @@ -83,9 +85,14 @@ impl<'a> Program ) -> Vec> { // We prepare a new `Frame` let mut frame = canvas::Frame::new(renderer, bounds.size()); + let frame_rect = bounds.shrink(10); // We create a `Path` representing a simple circle let circle = canvas::Path::circle(frame.center(), 50.0); + let border = canvas::Path::rectangle( + cosmic::iced::Point { x: 10.0, y: 10.0 }, + Size::new(frame_rect.width, frame_rect.height), + ); // And fill it with some color frame.fill(&circle, Color::BLACK); @@ -95,6 +102,12 @@ impl<'a> Program .with_width(5.0) .with_color(Color::BLACK), ); + frame.stroke( + &border, + Stroke::default() + .with_width(5.0) + .with_color(Color::BLACK), + ); // Then, we produce the geometry vec![frame.into_geometry()] @@ -104,7 +117,7 @@ impl<'a> Program &self, _state: &mut Self::State, event: canvas::Event, - _bounds: cosmic::iced::Rectangle, + bounds: cosmic::iced::Rectangle, _cursor: cosmic::iced_core::mouse::Cursor, ) -> (canvas::event::Status, Option) { match event { @@ -117,8 +130,17 @@ impl<'a> Program } cosmic::iced::mouse::Event::CursorMoved { position, - } => debug!(?position, "cursor moved"), + } => { + if bounds.x < position.x + && bounds.y < position.y + && (bounds.width + bounds.x) > position.x + && (bounds.height + bounds.y) > position.y + { + debug!(?position, "cursor moved"); + } + } cosmic::iced::mouse::Event::ButtonPressed(button) => { + // self.mouse_button_pressed = Some(button); debug!(?button, "mouse button pressed") } cosmic::iced::mouse::Event::ButtonReleased(