Magpie supports Hover and Drag cursor events
This commit is contained in:
parent
75fb80adf3
commit
87d70ee6d1
|
@ -27,6 +27,7 @@ pub struct Window {
|
|||
pub panel: Panel,
|
||||
pub last_update: Instant,
|
||||
pub cursor_pos: Vec2,
|
||||
pub cursor_down: bool,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
|
@ -44,6 +45,7 @@ impl Window {
|
|||
panel,
|
||||
last_update,
|
||||
cursor_pos: Vec2::ZERO,
|
||||
cursor_down: false,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -85,6 +87,14 @@ impl Window {
|
|||
let x = position.x as f32 * PX_PER_MM;
|
||||
let y = position.y as f32 * PX_PER_MM;
|
||||
self.cursor_pos = Vec2::new(x, y);
|
||||
|
||||
let event = if self.cursor_down {
|
||||
CursorEventKind::Drag
|
||||
} else {
|
||||
CursorEventKind::Hover
|
||||
};
|
||||
|
||||
self.panel.on_cursor_event(event, self.cursor_pos);
|
||||
}
|
||||
WindowEvent::MouseInput {
|
||||
state,
|
||||
|
@ -92,8 +102,14 @@ impl Window {
|
|||
..
|
||||
} => {
|
||||
let event = match state {
|
||||
ElementState::Pressed => CursorEventKind::Select,
|
||||
ElementState::Released => CursorEventKind::Deselect,
|
||||
ElementState::Pressed => {
|
||||
self.cursor_down = true;
|
||||
CursorEventKind::Select
|
||||
}
|
||||
ElementState::Released => {
|
||||
self.cursor_down = false;
|
||||
CursorEventKind::Deselect
|
||||
}
|
||||
};
|
||||
|
||||
self.panel.on_cursor_event(event, self.cursor_pos);
|
||||
|
|
Loading…
Reference in New Issue