Skip to content

Commit

Permalink
Add mouse leave event as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
sak96 committed Apr 21, 2024
1 parent d2543bf commit 1d2c855
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 |_| {
Expand Down Expand Up @@ -79,6 +81,7 @@ pub fn app() -> Html {
{onmouseup}
{onmousemove}
{onmousedown}
{onmouseleave}
{onresize}
/>
</div>
Expand Down
8 changes: 8 additions & 0 deletions src/app/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ pub trait Tool {
shapes: &mut Vec<Box<dyn Draw>>,
) {
}
fn onmouseleave(
&mut self,
position: (f64, f64),
canvas: HtmlCanvasElement,
shapes: &mut Vec<Box<dyn Draw>>,
) {
self.onmouseup(position, canvas, shapes)
}
}

#[derive(Default)]
Expand Down

0 comments on commit 1d2c855

Please sign in to comment.