From 25d4a7e11e924408afcd4b640277518cc56d826a Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 7 Mar 2021 19:44:17 +0100 Subject: [PATCH] Fix gained kb focus event on shift-tab --- egui/src/memory.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/egui/src/memory.rs b/egui/src/memory.rs index 7da269d4..4b411325 100644 --- a/egui/src/memory.rs +++ b/egui/src/memory.rs @@ -118,6 +118,9 @@ pub(crate) struct KbFocus { /// What had keyboard focus previous frame? id_previous_frame: Option, + /// Give focus to this widget next frame + id_next_frame: Option, + /// If set, the next widget that is interested in kb_focus will automatically get it. /// Probably because the user pressed Tab. give_to_next: bool, @@ -167,6 +170,10 @@ impl KbFocus { fn begin_frame(&mut self, new_input: &crate::data::input::RawInput) { self.id_previous_frame = self.id; + if let Some(id) = self.id_next_frame.take() { + self.id = Some(id); + } + self.pressed_tab = false; self.pressed_shift_tab = false; for event in &new_input.events { @@ -223,7 +230,7 @@ impl KbFocus { self.give_to_next = true; self.pressed_tab = false; } else if self.pressed_shift_tab { - self.id = self.last_interested; + self.id_next_frame = self.last_interested; // frame-delay so gained_focus works self.pressed_shift_tab = false; } } else if self.pressed_tab && self.id == None && !self.give_to_next {