wip new mouse region events

This commit is contained in:
K Simmons 2022-07-21 22:23:56 -07:00
parent 4b945f5694
commit 53add253b6
2 changed files with 30 additions and 0 deletions

View file

@ -273,10 +273,12 @@ impl HandlerSet {
pub enum MouseRegionEvent {
Move(MouseMovedEvent),
Drag(Vector2F, MouseMovedEvent),
DragOver(Vector2F, MouseMovedEvent),
Hover(bool, MouseMovedEvent),
Down(MouseButtonEvent),
Up(MouseButtonEvent),
Click(MouseButtonEvent),
UpOut(MouseButtonEvent),
DownOut(MouseButtonEvent),
ScrollWheel(ScrollWheelEvent),
}
@ -291,6 +293,12 @@ impl MouseRegionEvent {
Default::default(),
))
}
pub fn drag_over_disc() -> Discriminant<MouseRegionEvent> {
std::mem::discriminant(&MouseRegionEvent::DragOver(
Default::default(),
Default::default(),
))
}
pub fn hover_disc() -> Discriminant<MouseRegionEvent> {
std::mem::discriminant(&MouseRegionEvent::Hover(
Default::default(),
@ -303,6 +311,9 @@ impl MouseRegionEvent {
pub fn up_disc() -> Discriminant<MouseRegionEvent> {
std::mem::discriminant(&MouseRegionEvent::Up(Default::default()))
}
pub fn up_out_disc() -> Discriminant<MouseRegionEvent> {
std::mem::discriminant(&MouseRegionEvent::UpOut(Default::default()))
}
pub fn click_disc() -> Discriminant<MouseRegionEvent> {
std::mem::discriminant(&MouseRegionEvent::Click(Default::default()))
}
@ -319,6 +330,9 @@ impl MouseRegionEvent {
MouseRegionEvent::Drag(_, MouseMovedEvent { pressed_button, .. }) => {
(Self::drag_disc(), *pressed_button)
}
MouseRegionEvent::DragOver(_, MouseMovedEvent { pressed_button, .. }) => {
(Self::drag_over_disc(), *pressed_button)
}
MouseRegionEvent::Hover(_, _) => (Self::hover_disc(), None),
MouseRegionEvent::Down(MouseButtonEvent { button, .. }) => {
(Self::down_disc(), Some(*button))
@ -329,6 +343,9 @@ impl MouseRegionEvent {
MouseRegionEvent::Click(MouseButtonEvent { button, .. }) => {
(Self::click_disc(), Some(*button))
}
MouseRegionEvent::UpOut(MouseButtonEvent { button, .. }) => {
(Self::up_out_disc(), Some(*button))
}
MouseRegionEvent::DownOut(MouseButtonEvent { button, .. }) => {
(Self::down_out_disc(), Some(*button))
}

View file

@ -1022,6 +1022,19 @@ impl Pane {
cx.dispatch_action(ActivateItem(ix));
})
.on_click(MouseButton::Middle, close_tab_callback)
.on_drag(MouseButton::Left, |_, cx| {
cx.global::<DragAndDrop>().dragging(some view handle)
})
.on_mouse_up_out(MouseButton::Left, |_, cx| {
cx.global::<DragAndDrop>().stopped_dragging(some view handle)
})
.on_drag_over(MouseButton::Left, |started, _, cx| {
if started {
if let Some(tab) = cx.global::<DragAndDrop>().current_dragged::<Tab>() {
cx.dispatch_action(ReceivingTab)
}
}
})
.boxed()
})
}