1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 22:00:03 -04:00

Track the global focus state of the UI (#1859)

* Track the global focus state of the UI

* Fix changelog entries

* Document the new difference between `Response::has_focus` and `Memory::has_focus`
This commit is contained in:
Matt Campbell
2022-07-29 06:15:26 -05:00
committed by GitHub
parent 36a49ffba9
commit c6c6d2dc5d
6 changed files with 31 additions and 3 deletions

View File

@@ -70,9 +70,14 @@ impl State {
}
pub fn new_with_wayland_display(wayland_display: Option<*mut c_void>) -> Self {
let egui_input = egui::RawInput {
has_focus: false, // winit will tell us when we have focus
..Default::default()
};
Self {
start_time: instant::Instant::now(),
egui_input: Default::default(),
egui_input,
pointer_pos_in_points: None,
any_pointer_button_down: false,
current_cursor_icon: egui::CursorIcon::Default,
@@ -214,7 +219,8 @@ impl State {
egui_ctx.wants_keyboard_input()
|| input.virtual_keycode == Some(winit::event::VirtualKeyCode::Tab)
}
WindowEvent::Focused(_) => {
WindowEvent::Focused(has_focus) => {
self.egui_input.has_focus = *has_focus;
// We will not be given a KeyboardInput event when the modifiers are released while
// the window does not have focus. Unset all modifier state to be safe.
self.egui_input.modifiers = egui::Modifiers::default();