Skip to content

Commit

Permalink
Merge pull request #289 from hecrj/fix/cursor-events
Browse files Browse the repository at this point in the history
Produce and handle `CursorEntered` and `CursorLeft`
  • Loading branch information
hecrj authored Apr 13, 2020
2 parents e941eab + f652e84 commit bc70ba1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 9 additions & 2 deletions native/src/user_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions winit/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit bc70ba1

Please sign in to comment.