Allow clicking on commands in the command palette
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -101,6 +101,12 @@ pub struct FocusHandle {
|
||||
handles: Arc<RwLock<SlotMap<FocusId, AtomicUsize>>>,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for FocusHandle {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_fmt(format_args!("FocusHandle({:?})", self.id))
|
||||
}
|
||||
}
|
||||
|
||||
impl FocusHandle {
|
||||
pub(crate) fn new(handles: &Arc<RwLock<SlotMap<FocusId, AtomicUsize>>>) -> Self {
|
||||
let id = handles.write().insert(AtomicUsize::new(1));
|
||||
|
||||
Reference in New Issue
Block a user