Allow clicking on commands in the command palette

This commit is contained in:
Conrad Irwin 2023-11-13 21:42:27 -07:00
parent 4ef95f05e8
commit ad017a5df5
5 changed files with 104 additions and 25 deletions

View file

@ -71,6 +71,40 @@ pub trait StatelessInteractive<V: 'static>: Element<V> {
self
}
fn on_any_mouse_down(
mut self,
handler: impl Fn(&mut V, &MouseDownEvent, &mut ViewContext<V>) + 'static,
) -> Self
where
Self: Sized,
{
self.stateless_interactivity()
.mouse_down_listeners
.push(Box::new(move |view, event, bounds, phase, cx| {
if phase == DispatchPhase::Bubble && bounds.contains_point(&event.position) {
handler(view, event, cx)
}
}));
self
}
fn on_any_mouse_up(
mut self,
handler: impl Fn(&mut V, &MouseUpEvent, &mut ViewContext<V>) + 'static,
) -> Self
where
Self: Sized,
{
self.stateless_interactivity()
.mouse_up_listeners
.push(Box::new(move |view, event, bounds, phase, cx| {
if phase == DispatchPhase::Bubble && bounds.contains_point(&event.position) {
handler(view, event, cx)
}
}));
self
}
fn on_mouse_up(
mut self,
button: MouseButton,
@ -111,7 +145,6 @@ pub trait StatelessInteractive<V: 'static>: Element<V> {
fn on_mouse_up_out(
mut self,
button: MouseButton,
handler: impl Fn(&mut V, &MouseUpEvent, &mut ViewContext<V>) + 'static,
) -> Self
where
@ -120,10 +153,7 @@ pub trait StatelessInteractive<V: 'static>: Element<V> {
self.stateless_interactivity()
.mouse_up_listeners
.push(Box::new(move |view, event, bounds, phase, cx| {
if phase == DispatchPhase::Capture
&& event.button == button
&& !bounds.contains_point(&event.position)
{
if phase == DispatchPhase::Capture && !bounds.contains_point(&event.position) {
handler(view, event, cx);
}
}));