Simplify signatures of on_move and on_scroll for mouse_area

This commit is contained in:
Héctor Ramón Jiménez 2024-09-10 23:41:07 +02:00
parent c711750be7
commit 25e54a9acb
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -28,7 +28,7 @@ pub struct MouseArea<
on_middle_release: Option<Message>, on_middle_release: Option<Message>,
on_scroll: Option<Box<dyn Fn(mouse::ScrollDelta) -> Message + 'a>>, on_scroll: Option<Box<dyn Fn(mouse::ScrollDelta) -> Message + 'a>>,
on_enter: Option<Message>, on_enter: Option<Message>,
on_move: Option<Box<dyn Fn(Point) -> Message>>, on_move: Option<Box<dyn Fn(Point) -> Message + 'a>>,
on_exit: Option<Message>, on_exit: Option<Message>,
interaction: Option<mouse::Interaction>, interaction: Option<mouse::Interaction>,
} }
@ -78,10 +78,10 @@ impl<'a, Message, Theme, Renderer> MouseArea<'a, Message, Theme, Renderer> {
/// The message to emit when scroll wheel is used /// The message to emit when scroll wheel is used
#[must_use] #[must_use]
pub fn on_scroll<F>(mut self, on_scroll: F) -> Self pub fn on_scroll(
where mut self,
F: Fn(mouse::ScrollDelta) -> Message + 'static, on_scroll: impl Fn(mouse::ScrollDelta) -> Message + 'a,
{ ) -> Self {
self.on_scroll = Some(Box::new(on_scroll)); self.on_scroll = Some(Box::new(on_scroll));
self self
} }
@ -95,11 +95,8 @@ impl<'a, Message, Theme, Renderer> MouseArea<'a, Message, Theme, Renderer> {
/// The message to emit when the mouse moves in the area. /// The message to emit when the mouse moves in the area.
#[must_use] #[must_use]
pub fn on_move<F>(mut self, build_message: F) -> Self pub fn on_move(mut self, on_move: impl Fn(Point) -> Message + 'a) -> Self {
where self.on_move = Some(Box::new(on_move));
F: Fn(Point) -> Message + 'static,
{
self.on_move = Some(Box::new(build_message));
self self
} }