winit: Fix bug where the cursor could get stuck using the wrong icon
This commit is contained in:
parent
628c84cbee
commit
d15ce22e2e
3 changed files with 18 additions and 12 deletions
|
@ -10,7 +10,9 @@ NOTE: [`egui-winit`](../egui-winit/CHANGELOG.md), [`egui_glium`](../egui_glium/C
|
|||
|
||||
#### Desktop/Native:
|
||||
* `eframe::run_native` now returns a `Result` ([#2433](https://github.com/emilk/egui/pull/2433)).
|
||||
* Fixed window position persistence for Windows ([#2583](https://github.com/emilk/egui/issues/2583)).
|
||||
* Update to `winit` 0.28, adding support for mac trackpad zoom ([#2654](https://github.com/emilk/egui/pull/2654)).
|
||||
* Fix bug where the cursor could get stuck using the wrong icon.
|
||||
|
||||
#### Web:
|
||||
* Prevent ctrl-P/cmd-P from opening the print dialog ([#2598](https://github.com/emilk/egui/pull/2598)).
|
||||
|
|
|
@ -6,6 +6,7 @@ All notable changes to the `egui-winit` integration will be noted in this file.
|
|||
* Fixed window position persistence for Windows ([#2583](https://github.com/emilk/egui/issues/2583)).
|
||||
* Update to `winit` 0.28, adding support for mac trackpad zoom ([#2654](https://github.com/emilk/egui/pull/2654)).
|
||||
* Remove the `screen_reader` feature. Use the `accesskit` feature flag instead ([#2669](https://github.com/emilk/egui/pull/2669)).
|
||||
* Fix bug where the cursor could get stuck using the wrong icon.
|
||||
|
||||
|
||||
## 0.20.1 - 2022-12-11
|
||||
|
|
|
@ -59,7 +59,7 @@ pub struct State {
|
|||
egui_input: egui::RawInput,
|
||||
pointer_pos_in_points: Option<egui::Pos2>,
|
||||
any_pointer_button_down: bool,
|
||||
current_cursor_icon: egui::CursorIcon,
|
||||
current_cursor_icon: Option<egui::CursorIcon>,
|
||||
/// What egui uses.
|
||||
current_pixels_per_point: f32,
|
||||
|
||||
|
@ -99,7 +99,7 @@ impl State {
|
|||
egui_input,
|
||||
pointer_pos_in_points: None,
|
||||
any_pointer_button_down: false,
|
||||
current_cursor_icon: egui::CursorIcon::Default,
|
||||
current_cursor_icon: None,
|
||||
current_pixels_per_point: 1.0,
|
||||
|
||||
clipboard: clipboard::Clipboard::new(wayland_display),
|
||||
|
@ -654,23 +654,26 @@ impl State {
|
|||
}
|
||||
|
||||
fn set_cursor_icon(&mut self, window: &winit::window::Window, cursor_icon: egui::CursorIcon) {
|
||||
if self.current_cursor_icon == Some(cursor_icon) {
|
||||
// Prevent flickering near frame boundary when Windows OS tries to control cursor icon for window resizing.
|
||||
// On other platforms: just early-out to save CPU.
|
||||
if self.current_cursor_icon == cursor_icon {
|
||||
return;
|
||||
}
|
||||
self.current_cursor_icon = cursor_icon;
|
||||
|
||||
if let Some(cursor_icon) = translate_cursor(cursor_icon) {
|
||||
window.set_cursor_visible(true);
|
||||
|
||||
let is_pointer_in_window = self.pointer_pos_in_points.is_some();
|
||||
if is_pointer_in_window {
|
||||
window.set_cursor_icon(cursor_icon);
|
||||
}
|
||||
self.current_cursor_icon = Some(cursor_icon);
|
||||
|
||||
if let Some(winit_cursor_icon) = translate_cursor(cursor_icon) {
|
||||
window.set_cursor_visible(true);
|
||||
window.set_cursor_icon(winit_cursor_icon);
|
||||
} else {
|
||||
window.set_cursor_visible(false);
|
||||
}
|
||||
} else {
|
||||
// Remember to set the cursor again once the cursor returns to the screen:
|
||||
self.current_cursor_icon = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue