This commit is contained in:
Antonio Scandurra
2022-05-05 15:15:58 +02:00
parent 6b22c47d47
commit 61346f734d
16 changed files with 39 additions and 27 deletions
@@ -15,7 +15,7 @@ pub struct MouseEventHandler {
child: ElementBox,
cursor_style: Option<CursorStyle>,
mouse_down_handler: Option<Box<dyn FnMut(&mut EventContext)>>,
click_handler: Option<Box<dyn FnMut(&mut EventContext)>>,
click_handler: Option<Box<dyn FnMut(usize, &mut EventContext)>>,
drag_handler: Option<Box<dyn FnMut(Vector2F, &mut EventContext)>>,
padding: Padding,
}
@@ -57,7 +57,7 @@ impl MouseEventHandler {
self
}
pub fn on_click(mut self, handler: impl FnMut(&mut EventContext) + 'static) -> Self {
pub fn on_click(mut self, handler: impl FnMut(usize, &mut EventContext) + 'static) -> Self {
self.click_handler = Some(Box::new(handler));
self
}
@@ -151,14 +151,18 @@ impl Element for MouseEventHandler {
handled_in_child
}
}
Event::LeftMouseUp { position, .. } => {
Event::LeftMouseUp {
position,
click_count,
..
} => {
state.prev_drag_position = None;
if !handled_in_child && state.clicked {
state.clicked = false;
cx.notify();
if let Some(handler) = click_handler {
if hit_bounds.contains_point(*position) {
handler(cx);
handler(*click_count, cx);
}
}
true
+2 -1
View File
@@ -28,6 +28,7 @@ pub enum Event {
},
LeftMouseUp {
position: Vector2F,
click_count: usize,
},
LeftMouseDragged {
position: Vector2F,
@@ -68,7 +69,7 @@ impl Event {
Event::KeyDown { .. } => None,
Event::ScrollWheel { position, .. }
| Event::LeftMouseDown { position, .. }
| Event::LeftMouseUp { position }
| Event::LeftMouseUp { position, .. }
| Event::LeftMouseDragged { position }
| Event::RightMouseDown { position, .. }
| Event::RightMouseUp { position }
+1
View File
@@ -129,6 +129,7 @@ impl Event {
native_event.locationInWindow().x as f32,
window_height - native_event.locationInWindow().y as f32,
),
click_count: native_event.clickCount() as usize,
}),
NSEventType::NSRightMouseDown => {
let modifiers = native_event.modifierFlags();
+2 -2
View File
@@ -119,7 +119,7 @@ impl View for Select {
.with_style(style.header)
.boxed()
})
.on_click(move |cx| cx.dispatch_action(ToggleSelect))
.on_click(move |_, cx| cx.dispatch_action(ToggleSelect))
.boxed(),
);
if self.is_open {
@@ -153,7 +153,7 @@ impl View for Select {
)
},
)
.on_click(move |cx| cx.dispatch_action(SelectItem(ix)))
.on_click(move |_, cx| cx.dispatch_action(SelectItem(ix)))
.boxed()
}))
},