From 1d2c85577cd538caa8edd24aa1ed4733debbbfea Mon Sep 17 00:00:00 2001 From: sak96 <26397224+sak96@users.noreply.github.com> Date: Sun, 21 Apr 2024 21:43:09 +0530 Subject: [PATCH] Add mouse leave event as well. --- src/app/mod.rs | 3 +++ src/app/tools.rs | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/app/mod.rs b/src/app/mod.rs index 9f7ffaa..d56ed36 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -44,6 +44,8 @@ pub fn app() -> Html { handle_canvas_by_tool! {onmousedown, canvas_ref, shapes, tools, cur_tool}; handle_canvas_by_tool! {onmouseup, canvas_ref, shapes, tools, cur_tool}; handle_canvas_by_tool! {onmousemove, canvas_ref, shapes, tools, cur_tool}; + handle_canvas_by_tool! {onmouseleave, canvas_ref, shapes, tools, cur_tool}; + let onresize = { move_to_current_scope!(canvas_ref, shapes); Callback::from(move |_| { @@ -79,6 +81,7 @@ pub fn app() -> Html { {onmouseup} {onmousemove} {onmousedown} + {onmouseleave} {onresize} /> diff --git a/src/app/tools.rs b/src/app/tools.rs index 27351b7..2eea713 100644 --- a/src/app/tools.rs +++ b/src/app/tools.rs @@ -30,6 +30,14 @@ pub trait Tool { shapes: &mut Vec>, ) { } + fn onmouseleave( + &mut self, + position: (f64, f64), + canvas: HtmlCanvasElement, + shapes: &mut Vec>, + ) { + self.onmouseup(position, canvas, shapes) + } } #[derive(Default)]