Merge pull request #289 from hecrj/fix/cursor-events

Produce and handle `CursorEntered` and `CursorLeft`
This commit is contained in:
Héctor Ramón 2020-04-13 04:33:39 +02:00 committed by GitHub
commit bc70ba12f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -188,8 +188,15 @@ where
let mut messages = Vec::new();
for event in events {
if let Event::Mouse(mouse::Event::CursorMoved { x, y }) = event {
self.cursor_position = Point::new(x, y);
match event {
Event::Mouse(mouse::Event::CursorMoved { x, y }) => {
self.cursor_position = Point::new(x, y);
}
Event::Mouse(mouse::Event::CursorLeft) => {
// TODO: Encode cursor availability
self.cursor_position = Point::new(-1.0, -1.0);
}
_ => {}
}
self.root.widget.on_event(

View File

@ -27,6 +27,12 @@ pub fn window_event(
height: logical_size.height,
}))
}
WindowEvent::CursorEntered { .. } => {
Some(Event::Mouse(mouse::Event::CursorEntered))
}
WindowEvent::CursorLeft { .. } => {
Some(Event::Mouse(mouse::Event::CursorLeft))
}
WindowEvent::CursorMoved { position, .. } => {
let position = position.to_logical::<f64>(scale_factor);