From 4b0cc178ddadcb93b1912928631327c3a23c24b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sun, 12 Apr 2020 00:37:13 +0200 Subject: [PATCH 1/2] Produce cursor events in `iced_winit::conversion` --- winit/src/conversion.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index eaa26ace..78686424 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -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::(scale_factor); From f652e84187336c8bdd9bee32c0afeda7b14796b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sun, 12 Apr 2020 00:38:18 +0200 Subject: [PATCH 2/2] Make cursor unavailable on leave in `iced_winit` For now, we just set the cursor position to some negative coordinates. This is a temporary hack until we are able to encode cursor availability. Layers and/or multi-window support will make this apparent. --- native/src/user_interface.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/native/src/user_interface.rs b/native/src/user_interface.rs index 5d9221e9..88ffd6d6 100644 --- a/native/src/user_interface.rs +++ b/native/src/user_interface.rs @@ -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(