From 5d0c71350dd72eb4e3844091fa7be7b22e99ff50 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 6 Mar 2021 11:17:24 +0100 Subject: [PATCH] Add `fn Memory::gained_kb_focus() -> bool` query --- egui/src/memory.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/egui/src/memory.rs b/egui/src/memory.rs index 5bfde7e1..8190c2c1 100644 --- a/egui/src/memory.rs +++ b/egui/src/memory.rs @@ -207,9 +207,18 @@ impl Memory { self.areas.layer_id_at(pos, resize_interact_radius_side) } + pub(crate) fn had_kb_focus_last_frame(&self, id: Id) -> bool { + self.interaction.kb_focus_id_previous_frame == Some(id) + } + /// True if the given widget had keyboard focus last frame, but not this one. pub fn lost_kb_focus(&self, id: Id) -> bool { - self.interaction.kb_focus_id_previous_frame == Some(id) && !self.has_kb_focus(id) + self.had_kb_focus_last_frame(id) && !self.has_kb_focus(id) + } + + /// True if the given widget has keyboard focus this frame, but didn't last frame. + pub fn gained_kb_focus(&self, id: Id) -> bool { + !self.had_kb_focus_last_frame(id) && self.has_kb_focus(id) } pub fn has_kb_focus(&self, id: Id) -> bool {