From 90eeb7663538a0a31696ee0b5dca34957ed01e70 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Sun, 1 Sep 2024 10:24:58 +0200 Subject: [PATCH] Make some `Memory` methods public (#5046) Adding the proposed changes from @SymmetricChaos * Closes https://github.com/emilk/egui/issues/5044 * [x] I have followed the instructions in the PR template * [x] I ran the check script --- crates/egui/src/memory.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/egui/src/memory.rs b/crates/egui/src/memory.rs index 2a919200976..94916007901 100644 --- a/crates/egui/src/memory.rs +++ b/crates/egui/src/memory.rs @@ -750,16 +750,20 @@ impl Memory { self.areas().order().iter().copied() } - pub(crate) fn had_focus_last_frame(&self, id: Id) -> bool { + /// Check if the layer had focus last frame. + /// returns `true` if the layer had focus last frame, but not this one. + pub fn had_focus_last_frame(&self, id: Id) -> bool { self.focus().and_then(|f| f.id_previous_frame) == Some(id) } - /// True if the given widget had keyboard focus last frame, but not this one. + /// Check if the layer lost focus last frame + /// returns `true` if the layer lost focus last frame, but not this one. pub(crate) fn lost_focus(&self, id: Id) -> bool { self.had_focus_last_frame(id) && !self.has_focus(id) } - /// True if the given widget has keyboard focus this frame, but didn't last frame. + /// Check if the layer gained focus this frame + /// returns `true` if the layer gained focus this frame, but not last one. pub(crate) fn gained_focus(&self, id: Id) -> bool { !self.had_focus_last_frame(id) && self.has_focus(id) }