Introduce InteractiveElement::capture_any_mouse_{down,up}

This commit is contained in:
Antonio Scandurra 2023-12-20 14:00:12 +01:00
parent 5781cf6604
commit 8273865fa3

View File

@ -62,6 +62,18 @@ impl Interactivity {
}));
}
pub fn capture_any_mouse_down(
&mut self,
listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,
) {
self.mouse_down_listeners
.push(Box::new(move |event, bounds, phase, cx| {
if phase == DispatchPhase::Capture && bounds.visibly_contains(&event.position, cx) {
(listener)(event, cx)
}
}));
}
pub fn on_any_mouse_down(
&mut self,
listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,
@ -90,6 +102,18 @@ impl Interactivity {
}));
}
pub fn capture_any_mouse_up(
&mut self,
listener: impl Fn(&MouseUpEvent, &mut WindowContext) + 'static,
) {
self.mouse_up_listeners
.push(Box::new(move |event, bounds, phase, cx| {
if phase == DispatchPhase::Capture && bounds.visibly_contains(&event.position, cx) {
(listener)(event, cx)
}
}));
}
pub fn on_any_mouse_up(
&mut self,
listener: impl Fn(&MouseUpEvent, &mut WindowContext) + 'static,
@ -384,6 +408,14 @@ pub trait InteractiveElement: Sized {
self
}
fn capture_any_mouse_down(
mut self,
listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,
) -> Self {
self.interactivity().capture_any_mouse_down(listener);
self
}
fn on_any_mouse_down(
mut self,
listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,
@ -401,6 +433,14 @@ pub trait InteractiveElement: Sized {
self
}
fn capture_any_mouse_up(
mut self,
listener: impl Fn(&MouseUpEvent, &mut WindowContext) + 'static,
) -> Self {
self.interactivity().capture_any_mouse_up(listener);
self
}
fn on_mouse_down_out(
mut self,
listener: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,