Skip to content

Commit

Permalink
refactor: replace mouse_area with canvas update fn
Browse files Browse the repository at this point in the history
  • Loading branch information
decipher3114 committed Sep 28, 2024
1 parent 1b2ad83 commit d507346
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions src/windows/crop.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use iced::{
advanced::graphics::geometry,
mouse::{Cursor, Interaction},
event::Status,
mouse::{Button, Cursor, Interaction},
widget::{
canvas::{Frame, Geometry, LineCap, LineDash, LineJoin, Path, Program, Stroke, Style},
canvas::{
Event, Frame, Geometry, LineCap, LineDash, LineJoin, Path, Program, Stroke, Style,
},
column, container, horizontal_space,
image::Handle,
mouse_area, row, stack, text, vertical_space, Canvas, Image,
row, stack, text, vertical_space, Canvas, Image,
},
Alignment::Center,
Color,
Expand Down Expand Up @@ -74,10 +77,7 @@ impl CropWindow {
horizontal_space().width(Fill)
]
],
mouse_area(Canvas::new(self).height(Fill).width(Fill))
.on_move(CropEvent::UpdateCurrentPosition)
.on_press(CropEvent::SetInitialPoint)
.on_release(CropEvent::SetFinalPoint)
Canvas::new(self).height(Fill).width(Fill)
]
.height(Fill)
.width(Fill)
Expand Down Expand Up @@ -189,6 +189,39 @@ impl Program<CropEvent, Theme> for CropWindow {
vec![frame.into_geometry()]
}

fn update(
&self,
_state: &mut Self::State,
event: Event,
_bounds: Rectangle,
_cursor: Cursor,
) -> (Status, Option<CropEvent>) {
match event {
iced::widget::canvas::Event::Mouse(event) => match event {
iced::mouse::Event::CursorMoved { position } => (
Status::Captured,
Some(CropEvent::UpdateCurrentPosition(position)),
),
iced::mouse::Event::ButtonPressed(button) => {
if button == Button::Left {
(Status::Captured, Some(CropEvent::SetInitialPoint))
} else {
(Status::Ignored, None)
}
}
iced::mouse::Event::ButtonReleased(button) => {
if button == Button::Left {
(Status::Captured, Some(CropEvent::SetFinalPoint))
} else {
(Status::Ignored, None)
}
}
_ => (Status::Ignored, None),
},
_ => (Status::Ignored, None),
}
}

fn mouse_interaction(
&self,
_state: &Self::State,
Expand Down

0 comments on commit d507346

Please sign in to comment.