From f27f312a1281380dad63b0f7b43a6c4aa0273655 Mon Sep 17 00:00:00 2001 From: Doublonmousse <115779707+Doublonmousse@users.noreply.github.com> Date: Thu, 11 Jul 2024 19:37:37 +0200 Subject: [PATCH 1/8] logic changes for selection cancellation --- crates/rnote-engine/src/pens/brush.rs | 23 +++++++++++++++++++ crates/rnote-engine/src/pens/eraser.rs | 7 ++++-- crates/rnote-engine/src/pens/penholder.rs | 8 ++++++- .../src/pens/pensconfig/brushconfig.rs | 8 +++++++ .../src/pens/selector/penevents.rs | 7 ++++++ crates/rnote-engine/src/pens/shaper.rs | 20 +++++++++------- .../rnote-engine/src/pens/typewriter/mod.rs | 16 ++++++++++++- crates/rnote-engine/src/store/mod.rs | 13 +++++++++++ 8 files changed, 90 insertions(+), 12 deletions(-) diff --git a/crates/rnote-engine/src/pens/brush.rs b/crates/rnote-engine/src/pens/brush.rs index d993bb898a..fb2d2d705e 100644 --- a/crates/rnote-engine/src/pens/brush.rs +++ b/crates/rnote-engine/src/pens/brush.rs @@ -16,6 +16,7 @@ use rnote_compose::builders::{ use rnote_compose::eventresult::{EventPropagation, EventResult}; use rnote_compose::penevent::{PenEvent, PenProgress}; use rnote_compose::penpath::{Element, Segment}; +use rnote_compose::shapes::Shapeable; use rnote_compose::Constraints; use std::time::Instant; @@ -229,6 +230,28 @@ impl PenBehaviour for Brush { ); } + // remove strokes that follow a selection cancellation if they are large + // hence we can write after selecting strokes but we won't leave tiny spots + // behind + let volume = engine_view + .store + .get_stroke_ref(*current_stroke_key) + .unwrap() + .bounds() + .volume(); + if engine_view.store.get_cancelled_state() + && volume + < 4.0 + * engine_view + .pens_config + .brush_config + .get_stroke_width() + .powi(2) + { + tracing::debug!("VOLUME {volume}"); + engine_view.store.remove_stroke(*current_stroke_key); + } + // Finish up the last stroke engine_view .store diff --git a/crates/rnote-engine/src/pens/eraser.rs b/crates/rnote-engine/src/pens/eraser.rs index 821ef5e92c..956de46a22 100644 --- a/crates/rnote-engine/src/pens/eraser.rs +++ b/crates/rnote-engine/src/pens/eraser.rs @@ -60,8 +60,11 @@ impl PenBehaviour for Eraser { let event_result = match (&mut self.state, event) { (EraserState::Up | EraserState::Proximity { .. }, PenEvent::Down { element, .. }) => { - widget_flags |= erase(element, engine_view); - self.state = EraserState::Down(element); + if !engine_view.store.get_cancelled_state() { + widget_flags |= erase(element, engine_view); + self.state = EraserState::Down(element); + // this means we need one more up/down event here to activate the eraser + } EventResult { handled: true, propagate: EventPropagation::Stop, diff --git a/crates/rnote-engine/src/pens/penholder.rs b/crates/rnote-engine/src/pens/penholder.rs index 66952fbe25..3a046e347b 100644 --- a/crates/rnote-engine/src/pens/penholder.rs +++ b/crates/rnote-engine/src/pens/penholder.rs @@ -248,11 +248,17 @@ impl PenHolder { widget_flags |= wf | self.handle_pen_progress(event_result.progress, engine_view); if !event_result.handled { - let (propagate, wf) = self.handle_pen_event_global(event, now, engine_view); + let (propagate, wf) = self.handle_pen_event_global(event.clone(), now, engine_view); event_result.propagate |= propagate; widget_flags |= wf; } + // reset the state + match event { + PenEvent::Up { .. } => engine_view.store.set_cancelled_state(false), + _ => (), + } + // Always redraw after handling a pen event widget_flags.redraw = true; diff --git a/crates/rnote-engine/src/pens/pensconfig/brushconfig.rs b/crates/rnote-engine/src/pens/pensconfig/brushconfig.rs index a9e868b737..82e9ac6c45 100644 --- a/crates/rnote-engine/src/pens/pensconfig/brushconfig.rs +++ b/crates/rnote-engine/src/pens/pensconfig/brushconfig.rs @@ -148,4 +148,12 @@ impl BrushConfig { } } } + + pub(crate) fn get_stroke_width(&self) -> f64 { + match &self.style { + BrushStyle::Marker => self.marker_options.stroke_width, + BrushStyle::Solid => self.solid_options.stroke_width, + BrushStyle::Textured => self.textured_options.stroke_width, + } + } } diff --git a/crates/rnote-engine/src/pens/selector/penevents.rs b/crates/rnote-engine/src/pens/selector/penevents.rs index 02b001a699..af54e5c153 100644 --- a/crates/rnote-engine/src/pens/selector/penevents.rs +++ b/crates/rnote-engine/src/pens/selector/penevents.rs @@ -180,9 +180,16 @@ impl Selector { }; } else { // when clicking outside the selection bounds, reset + tracing::debug!("cancelling the selection"); engine_view.store.set_selected_keys(selection, false); self.state = SelectorState::Idle; + // we create a new engine variable that indicates that the pen event is one from the same + // event sequence that the one that cancelled the selection + // this is done by setting this variable to true here and + // removing it on a pen up event (and doing more things if this variable is true on a pen up) + engine_view.store.set_cancelled_state(true); + progress = PenProgress::Finished; } } diff --git a/crates/rnote-engine/src/pens/shaper.rs b/crates/rnote-engine/src/pens/shaper.rs index c8834e7562..c83ee4b3da 100644 --- a/crates/rnote-engine/src/pens/shaper.rs +++ b/crates/rnote-engine/src/pens/shaper.rs @@ -67,15 +67,19 @@ impl PenBehaviour for Shaper { let event_result = match (&mut self.state, event) { (ShaperState::Idle, PenEvent::Down { element, .. }) => { - engine_view.pens_config.shaper_config.new_style_seeds(); + if !engine_view.store.get_cancelled_state() { + // here we need an additional up/down event after a selection + // cancellation + engine_view.pens_config.shaper_config.new_style_seeds(); - self.state = ShaperState::BuildShape { - builder: new_builder( - engine_view.pens_config.shaper_config.builder_type, - element, - now, - ), - }; + self.state = ShaperState::BuildShape { + builder: new_builder( + engine_view.pens_config.shaper_config.builder_type, + element, + now, + ), + }; + } EventResult { handled: true, diff --git a/crates/rnote-engine/src/pens/typewriter/mod.rs b/crates/rnote-engine/src/pens/typewriter/mod.rs index 418ee85b2f..4a5d0c44ac 100644 --- a/crates/rnote-engine/src/pens/typewriter/mod.rs +++ b/crates/rnote-engine/src/pens/typewriter/mod.rs @@ -13,6 +13,7 @@ use crate::{AudioPlayer, Camera, DrawableOnDoc, WidgetFlags}; use futures::channel::oneshot; use p2d::bounding_volume::{Aabb, BoundingVolume}; use piet::RenderContext; +use rnote_compose::eventresult::EventPropagation; use rnote_compose::ext::{AabbExt, Vector2Ext}; use rnote_compose::penevent::{KeyboardKey, PenEvent, PenProgress, PenState}; use rnote_compose::shapes::Shapeable; @@ -359,7 +360,20 @@ impl PenBehaviour for Typewriter { PenEvent::Down { element, modifier_keys, - } => self.handle_pen_event_down(element, modifier_keys, now, engine_view), + } => { + if !engine_view.store.get_cancelled_state() { + self.handle_pen_event_down(element, modifier_keys, now, engine_view) + } else { + ( + EventResult { + handled: true, + propagate: EventPropagation::Stop, + progress: PenProgress::InProgress, + }, + WidgetFlags::default(), + ) + } + } PenEvent::Up { element, modifier_keys, diff --git a/crates/rnote-engine/src/store/mod.rs b/crates/rnote-engine/src/store/mod.rs index 8b847cf754..06c883f740 100644 --- a/crates/rnote-engine/src/store/mod.rs +++ b/crates/rnote-engine/src/store/mod.rs @@ -90,6 +90,8 @@ pub struct StrokeStore { /// The index of the current live document in the history stack. #[serde(skip)] live_index: usize, + #[serde(skip)] + canceled_selection: bool, /// An rtree backed by the slotmap store, for faster spatial queries. /// /// Needs to be updated with `update_with_key()` when strokes changed their geometry or position! @@ -109,6 +111,7 @@ impl Default for StrokeStore { // Start off with state in the history history: VecDeque::from(vec![HistoryEntry::default()]), live_index: 0, + canceled_selection: false, key_tree: KeyTree::default(), @@ -367,4 +370,14 @@ impl StrokeStore { widget_flags } + + /// set the active state for the cancelled selection + pub fn set_cancelled_state(&mut self, state: bool) { + self.canceled_selection = state + } + + /// get the active state for the cancelled selection + pub fn get_cancelled_state(&self) -> bool { + self.canceled_selection + } } From ace0b25827342c95758b5fbc8daeb1299e7b2264 Mon Sep 17 00:00:00 2001 From: Doublonmousse <115779707+Doublonmousse@users.noreply.github.com> Date: Thu, 11 Jul 2024 21:19:29 +0200 Subject: [PATCH 2/8] prevent shapes that are too small to be visible --- .../src/pens/pensconfig/shaperconfig.rs | 7 ++++ crates/rnote-engine/src/pens/shaper.rs | 41 +++++++++++++------ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/crates/rnote-engine/src/pens/pensconfig/shaperconfig.rs b/crates/rnote-engine/src/pens/pensconfig/shaperconfig.rs index 1bf6846ee3..0ab8f1a49d 100644 --- a/crates/rnote-engine/src/pens/pensconfig/shaperconfig.rs +++ b/crates/rnote-engine/src/pens/pensconfig/shaperconfig.rs @@ -91,4 +91,11 @@ impl ShaperConfig { } } } + + pub(crate) fn get_stroke_width(&self) -> f64 { + match &self.style { + ShaperStyle::Smooth => self.smooth_options.stroke_width, + ShaperStyle::Rough => self.rough_options.stroke_width, + } + } } diff --git a/crates/rnote-engine/src/pens/shaper.rs b/crates/rnote-engine/src/pens/shaper.rs index c83ee4b3da..046099dc5a 100644 --- a/crates/rnote-engine/src/pens/shaper.rs +++ b/crates/rnote-engine/src/pens/shaper.rs @@ -6,6 +6,7 @@ use crate::strokes::ShapeStroke; use crate::strokes::Stroke; use crate::{DrawableOnDoc, WidgetFlags}; use p2d::bounding_volume::Aabb; +use p2d::bounding_volume::BoundingVolume; use piet::RenderContext; use rnote_compose::builders::buildable::{Buildable, BuilderCreator, BuilderProgress}; use rnote_compose::builders::{ArrowBuilder, GridBuilder, PolygonBuilder, PolylineBuilder}; @@ -16,6 +17,7 @@ use rnote_compose::builders::{ use rnote_compose::eventresult::{EventPropagation, EventResult}; use rnote_compose::penevent::{KeyboardKey, ModifierKey, PenEvent, PenProgress}; use rnote_compose::penpath::Element; +use rnote_compose::shapes::Shapeable; use rnote_compose::Shape; use std::time::Instant; @@ -157,18 +159,33 @@ impl PenBehaviour for Shaper { .shaper_config .gen_style_for_current_options(); - let shapes_emitted = !shapes.is_empty(); - for shape in shapes { - let key = engine_view.store.insert_stroke( - Stroke::ShapeStroke(ShapeStroke::new(shape, style.clone())), - None, - ); - style.advance_seed(); - engine_view.store.regenerate_rendering_for_stroke( - key, - engine_view.camera.viewport(), - engine_view.camera.image_scale(), - ); + // calculate the bounds + let bound_condition = shapes + .iter() + .map(|x| x.bounds()) + .reduce(|acc, x| acc.merged(&x)) + .unwrap_or(Aabb::new_invalid()) + .volume() + > engine_view + .pens_config + .shaper_config + .get_stroke_width() + .powi(2); + + let shapes_emitted = !shapes.is_empty() && bound_condition; + if shapes_emitted { + for shape in shapes { + let key = engine_view.store.insert_stroke( + Stroke::ShapeStroke(ShapeStroke::new(shape, style.clone())), + None, + ); + style.advance_seed(); + engine_view.store.regenerate_rendering_for_stroke( + key, + engine_view.camera.viewport(), + engine_view.camera.image_scale(), + ); + } } self.state = ShaperState::Idle; From 5d5d149a08771fb1bbab258100fcc2ba56dd640c Mon Sep 17 00:00:00 2001 From: Doublonmousse <115779707+Doublonmousse@users.noreply.github.com> Date: Sat, 13 Jul 2024 16:38:36 +0200 Subject: [PATCH 3/8] close selection tool when deleting in temporary mode --- crates/rnote-engine/src/engine/mod.rs | 10 ++++++++++ crates/rnote-ui/src/appwindow/actions.rs | 12 ++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/rnote-engine/src/engine/mod.rs b/crates/rnote-engine/src/engine/mod.rs index 0d4e4ff653..be3a05b5d0 100644 --- a/crates/rnote-engine/src/engine/mod.rs +++ b/crates/rnote-engine/src/engine/mod.rs @@ -857,6 +857,16 @@ impl Engine { | self.update_rendering_current_viewport() } + pub fn cancel_selection_temporary_pen(&self) -> bool { + let selection_keys = self.store.selection_keys_as_rendered(); + !selection_keys.is_empty() + && self + .penholder + .pen_mode_state() + .take_style_override() + .is_some() + } + pub fn trash_selection(&mut self) -> WidgetFlags { let selection_keys = self.store.selection_keys_as_rendered(); self.store.set_trashed_keys(&selection_keys, true); diff --git a/crates/rnote-ui/src/appwindow/actions.rs b/crates/rnote-ui/src/appwindow/actions.rs index dcf8237777..6d5be4a0df 100644 --- a/crates/rnote-ui/src/appwindow/actions.rs +++ b/crates/rnote-ui/src/appwindow/actions.rs @@ -7,7 +7,7 @@ use gtk4::{ UriLauncher, Window, }; use p2d::bounding_volume::BoundingVolume; -use rnote_compose::penevent::ShortcutKey; +use rnote_compose::penevent::{KeyboardKey, ShortcutKey}; use rnote_compose::SplitOrder; use rnote_engine::engine::StrokeContent; use rnote_engine::pens::PenStyle; @@ -406,7 +406,15 @@ impl RnAppWindow { // Trash Selection action_selection_trash.connect_activate(clone!(@weak self as appwindow => move |_, _| { let canvas = appwindow.active_tab_wrapper().canvas(); - let widget_flags = canvas.engine_mut().trash_selection(); + // check if we have a selector as a temporary tool and need to change the pen + let cancel_selection = canvas.engine_ref().cancel_selection_temporary_pen(); + let widget_flags = if cancel_selection { + // trigger an event for a KeyboardPress::Delete + let (_, widget_flags) = canvas.engine_mut().handle_pen_event(rnote_compose::PenEvent::KeyPressed { keyboard_key: KeyboardKey::Delete, modifier_keys: vec![] }, None, Instant::now()); + widget_flags + } else { + canvas.engine_mut().trash_selection() + }; appwindow.handle_widget_flags(widget_flags, &canvas); })); From 1f14479004ad82d12572fdbda2747c9ea153588b Mon Sep 17 00:00:00 2001 From: Doublonmousse <115779707+Doublonmousse@users.noreply.github.com> Date: Sat, 13 Jul 2024 16:40:05 +0200 Subject: [PATCH 4/8] fmt --- crates/rnote-ui/src/appwindow/actions.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/rnote-ui/src/appwindow/actions.rs b/crates/rnote-ui/src/appwindow/actions.rs index 6d5be4a0df..75925e8b22 100644 --- a/crates/rnote-ui/src/appwindow/actions.rs +++ b/crates/rnote-ui/src/appwindow/actions.rs @@ -410,7 +410,11 @@ impl RnAppWindow { let cancel_selection = canvas.engine_ref().cancel_selection_temporary_pen(); let widget_flags = if cancel_selection { // trigger an event for a KeyboardPress::Delete - let (_, widget_flags) = canvas.engine_mut().handle_pen_event(rnote_compose::PenEvent::KeyPressed { keyboard_key: KeyboardKey::Delete, modifier_keys: vec![] }, None, Instant::now()); + let (_, widget_flags) = canvas.engine_mut().handle_pen_event( + rnote_compose::PenEvent::KeyPressed { keyboard_key: KeyboardKey::Delete, modifier_keys: vec![] }, + None, + Instant::now() + ); widget_flags } else { canvas.engine_mut().trash_selection() From 5b9807c7a054786c036d560d2574bd6ada5b2bdc Mon Sep 17 00:00:00 2001 From: Doublonmousse <115779707+Doublonmousse@users.noreply.github.com> Date: Sun, 21 Jul 2024 18:41:16 +0200 Subject: [PATCH 5/8] remove unnecessary size check fixes bug where large vertical or horizontal elements would get cancelled --- .../src/pens/pensconfig/shaperconfig.rs | 7 ------- crates/rnote-engine/src/pens/shaper.rs | 17 +---------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/crates/rnote-engine/src/pens/pensconfig/shaperconfig.rs b/crates/rnote-engine/src/pens/pensconfig/shaperconfig.rs index 0ab8f1a49d..1bf6846ee3 100644 --- a/crates/rnote-engine/src/pens/pensconfig/shaperconfig.rs +++ b/crates/rnote-engine/src/pens/pensconfig/shaperconfig.rs @@ -91,11 +91,4 @@ impl ShaperConfig { } } } - - pub(crate) fn get_stroke_width(&self) -> f64 { - match &self.style { - ShaperStyle::Smooth => self.smooth_options.stroke_width, - ShaperStyle::Rough => self.rough_options.stroke_width, - } - } } diff --git a/crates/rnote-engine/src/pens/shaper.rs b/crates/rnote-engine/src/pens/shaper.rs index 046099dc5a..433e3c6c40 100644 --- a/crates/rnote-engine/src/pens/shaper.rs +++ b/crates/rnote-engine/src/pens/shaper.rs @@ -6,7 +6,6 @@ use crate::strokes::ShapeStroke; use crate::strokes::Stroke; use crate::{DrawableOnDoc, WidgetFlags}; use p2d::bounding_volume::Aabb; -use p2d::bounding_volume::BoundingVolume; use piet::RenderContext; use rnote_compose::builders::buildable::{Buildable, BuilderCreator, BuilderProgress}; use rnote_compose::builders::{ArrowBuilder, GridBuilder, PolygonBuilder, PolylineBuilder}; @@ -17,7 +16,6 @@ use rnote_compose::builders::{ use rnote_compose::eventresult::{EventPropagation, EventResult}; use rnote_compose::penevent::{KeyboardKey, ModifierKey, PenEvent, PenProgress}; use rnote_compose::penpath::Element; -use rnote_compose::shapes::Shapeable; use rnote_compose::Shape; use std::time::Instant; @@ -159,20 +157,7 @@ impl PenBehaviour for Shaper { .shaper_config .gen_style_for_current_options(); - // calculate the bounds - let bound_condition = shapes - .iter() - .map(|x| x.bounds()) - .reduce(|acc, x| acc.merged(&x)) - .unwrap_or(Aabb::new_invalid()) - .volume() - > engine_view - .pens_config - .shaper_config - .get_stroke_width() - .powi(2); - - let shapes_emitted = !shapes.is_empty() && bound_condition; + let shapes_emitted = !shapes.is_empty(); if shapes_emitted { for shape in shapes { let key = engine_view.store.insert_stroke( From 3cca2872fd7a971ed8a647fc18445b74e400481c Mon Sep 17 00:00:00 2001 From: Doublonmousse <115779707+Doublonmousse@users.noreply.github.com> Date: Sat, 2 Nov 2024 15:59:44 +0000 Subject: [PATCH 6/8] apply corrections - move actions logic into `trash_selection` - small rename of canceled* to have coherent naming between variables and functions getters/settesr - move comment closer to the `canceled_state` variable (variable-level docstring) - constant added as such --- crates/rnote-engine/src/engine/mod.rs | 28 ++++++++++++++----- crates/rnote-engine/src/pens/brush.rs | 12 ++++++-- .../src/pens/selector/penevents.rs | 6 ++-- crates/rnote-engine/src/store/mod.rs | 12 +++++--- crates/rnote-ui/src/appwindow/actions.rs | 16 ++--------- 5 files changed, 43 insertions(+), 31 deletions(-) diff --git a/crates/rnote-engine/src/engine/mod.rs b/crates/rnote-engine/src/engine/mod.rs index be3a05b5d0..801c00782c 100644 --- a/crates/rnote-engine/src/engine/mod.rs +++ b/crates/rnote-engine/src/engine/mod.rs @@ -28,7 +28,7 @@ use futures::channel::{mpsc, oneshot}; use p2d::bounding_volume::{Aabb, BoundingVolume}; use rnote_compose::eventresult::EventPropagation; use rnote_compose::ext::AabbExt; -use rnote_compose::penevent::{PenEvent, ShortcutKey}; +use rnote_compose::penevent::{KeyboardKey, PenEvent, ShortcutKey}; use rnote_compose::{Color, SplitOrder}; use serde::{Deserialize, Serialize}; use std::path::PathBuf; @@ -868,12 +868,26 @@ impl Engine { } pub fn trash_selection(&mut self) -> WidgetFlags { - let selection_keys = self.store.selection_keys_as_rendered(); - self.store.set_trashed_keys(&selection_keys, true); - self.current_pen_update_state() - | self.doc_resize_autoexpand() - | self.record(Instant::now()) - | self.update_rendering_current_viewport() + // check if we have a selector as a temporary tool and need to change the pen + let cancel_selection = self.cancel_selection_temporary_pen(); + if cancel_selection { + let (_, widget_flags) = self.handle_pen_event( + rnote_compose::PenEvent::KeyPressed { + keyboard_key: KeyboardKey::Delete, + modifier_keys: vec![], + }, + None, + Instant::now(), + ); + widget_flags + } else { + let selection_keys = self.store.selection_keys_as_rendered(); + self.store.set_trashed_keys(&selection_keys, true); + self.current_pen_update_state() + | self.doc_resize_autoexpand() + | self.record(Instant::now()) + | self.update_rendering_current_viewport() + } } pub fn nothing_selected(&self) -> bool { diff --git a/crates/rnote-engine/src/pens/brush.rs b/crates/rnote-engine/src/pens/brush.rs index fb2d2d705e..ec6e5c727c 100644 --- a/crates/rnote-engine/src/pens/brush.rs +++ b/crates/rnote-engine/src/pens/brush.rs @@ -42,6 +42,15 @@ impl Default for Brush { } } +impl Brush { + /// Threshold for the ratio of stroke bounds volume over + /// stroke width**2 over which we consider that strokes + /// or shapes that are left by pressing the pen down when + /// cancelling a selection should be kept. Smaller ratio + /// are deleted + const VOLUME_RATIO_THRESHOLD: f64 = 5.0; +} + impl PenBehaviour for Brush { fn init(&mut self, _engine_view: &EngineView) -> WidgetFlags { WidgetFlags::default() @@ -241,14 +250,13 @@ impl PenBehaviour for Brush { .volume(); if engine_view.store.get_cancelled_state() && volume - < 4.0 + < Self::VOLUME_RATIO_THRESHOLD * engine_view .pens_config .brush_config .get_stroke_width() .powi(2) { - tracing::debug!("VOLUME {volume}"); engine_view.store.remove_stroke(*current_stroke_key); } diff --git a/crates/rnote-engine/src/pens/selector/penevents.rs b/crates/rnote-engine/src/pens/selector/penevents.rs index af54e5c153..c506b4e45d 100644 --- a/crates/rnote-engine/src/pens/selector/penevents.rs +++ b/crates/rnote-engine/src/pens/selector/penevents.rs @@ -184,10 +184,8 @@ impl Selector { engine_view.store.set_selected_keys(selection, false); self.state = SelectorState::Idle; - // we create a new engine variable that indicates that the pen event is one from the same - // event sequence that the one that cancelled the selection - // this is done by setting this variable to true here and - // removing it on a pen up event (and doing more things if this variable is true on a pen up) + // This event is in the same sequence than the one that + // cancelled the selection. We thus set the variable to true here engine_view.store.set_cancelled_state(true); progress = PenProgress::Finished; diff --git a/crates/rnote-engine/src/store/mod.rs b/crates/rnote-engine/src/store/mod.rs index 06c883f740..aff9dd0e80 100644 --- a/crates/rnote-engine/src/store/mod.rs +++ b/crates/rnote-engine/src/store/mod.rs @@ -90,8 +90,12 @@ pub struct StrokeStore { /// The index of the current live document in the history stack. #[serde(skip)] live_index: usize, + /// Boolean that indicates the pen event is one from the same + /// event sequence than the one that cancelled the selection + /// Events that cancel a selection should set this to true + /// and this should be set back to false on a pen up event #[serde(skip)] - canceled_selection: bool, + canceled_state: bool, /// An rtree backed by the slotmap store, for faster spatial queries. /// /// Needs to be updated with `update_with_key()` when strokes changed their geometry or position! @@ -111,7 +115,7 @@ impl Default for StrokeStore { // Start off with state in the history history: VecDeque::from(vec![HistoryEntry::default()]), live_index: 0, - canceled_selection: false, + canceled_state: false, key_tree: KeyTree::default(), @@ -373,11 +377,11 @@ impl StrokeStore { /// set the active state for the cancelled selection pub fn set_cancelled_state(&mut self, state: bool) { - self.canceled_selection = state + self.canceled_state = state } /// get the active state for the cancelled selection pub fn get_cancelled_state(&self) -> bool { - self.canceled_selection + self.canceled_state } } diff --git a/crates/rnote-ui/src/appwindow/actions.rs b/crates/rnote-ui/src/appwindow/actions.rs index 75925e8b22..dcf8237777 100644 --- a/crates/rnote-ui/src/appwindow/actions.rs +++ b/crates/rnote-ui/src/appwindow/actions.rs @@ -7,7 +7,7 @@ use gtk4::{ UriLauncher, Window, }; use p2d::bounding_volume::BoundingVolume; -use rnote_compose::penevent::{KeyboardKey, ShortcutKey}; +use rnote_compose::penevent::ShortcutKey; use rnote_compose::SplitOrder; use rnote_engine::engine::StrokeContent; use rnote_engine::pens::PenStyle; @@ -406,19 +406,7 @@ impl RnAppWindow { // Trash Selection action_selection_trash.connect_activate(clone!(@weak self as appwindow => move |_, _| { let canvas = appwindow.active_tab_wrapper().canvas(); - // check if we have a selector as a temporary tool and need to change the pen - let cancel_selection = canvas.engine_ref().cancel_selection_temporary_pen(); - let widget_flags = if cancel_selection { - // trigger an event for a KeyboardPress::Delete - let (_, widget_flags) = canvas.engine_mut().handle_pen_event( - rnote_compose::PenEvent::KeyPressed { keyboard_key: KeyboardKey::Delete, modifier_keys: vec![] }, - None, - Instant::now() - ); - widget_flags - } else { - canvas.engine_mut().trash_selection() - }; + let widget_flags = canvas.engine_mut().trash_selection(); appwindow.handle_widget_flags(widget_flags, &canvas); })); From 32573edf4b066165af8d5b8d09107ade4b929134 Mon Sep 17 00:00:00 2001 From: Doublonmousse <115779707+Doublonmousse@users.noreply.github.com> Date: Sat, 2 Nov 2024 16:13:15 +0000 Subject: [PATCH 7/8] switch to hashset to fix type error --- crates/rnote-engine/src/engine/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/rnote-engine/src/engine/mod.rs b/crates/rnote-engine/src/engine/mod.rs index 6abed48f0f..af7917fe3e 100644 --- a/crates/rnote-engine/src/engine/mod.rs +++ b/crates/rnote-engine/src/engine/mod.rs @@ -34,6 +34,7 @@ use serde::{Deserialize, Serialize}; use std::path::PathBuf; use std::sync::Arc; use std::time::Instant; +use std::collections::HashSet; use tracing::error; /// An immutable view into the engine, excluding the penholder. @@ -875,7 +876,7 @@ impl Engine { let (_, widget_flags) = self.handle_pen_event( rnote_compose::PenEvent::KeyPressed { keyboard_key: KeyboardKey::Delete, - modifier_keys: vec![], + modifier_keys: HashSet::new(), }, None, Instant::now(), From 430c77f8802b19f545f09314ba7bdedcba2129f1 Mon Sep 17 00:00:00 2001 From: Doublonmousse <115779707+Doublonmousse@users.noreply.github.com> Date: Sat, 2 Nov 2024 16:20:31 +0000 Subject: [PATCH 8/8] fmt check --- crates/rnote-engine/src/engine/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rnote-engine/src/engine/mod.rs b/crates/rnote-engine/src/engine/mod.rs index af7917fe3e..cb735d97a1 100644 --- a/crates/rnote-engine/src/engine/mod.rs +++ b/crates/rnote-engine/src/engine/mod.rs @@ -31,10 +31,10 @@ use rnote_compose::ext::AabbExt; use rnote_compose::penevent::{KeyboardKey, PenEvent, ShortcutKey}; use rnote_compose::{Color, SplitOrder}; use serde::{Deserialize, Serialize}; +use std::collections::HashSet; use std::path::PathBuf; use std::sync::Arc; use std::time::Instant; -use std::collections::HashSet; use tracing::error; /// An immutable view into the engine, excluding the penholder.