From 1451f488f39105daf0640b1e2a50b90cd6d9d30f Mon Sep 17 00:00:00 2001 From: Alex Saveau Date: Fri, 28 Jun 2024 22:12:12 -0700 Subject: [PATCH] Refresh UI on window focus Signed-off-by: Alex Saveau --- egui/src/main.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/egui/src/main.rs b/egui/src/main.rs index 2a49d0f..6d65d81 100644 --- a/egui/src/main.rs +++ b/egui/src/main.rs @@ -426,6 +426,9 @@ struct UiState { query: String, search_results: Vec, + + was_focused: bool, + skipped_first_focus: bool, } #[derive(Debug)] @@ -587,6 +590,16 @@ fn main_ui( .and_then(|()| requests.send(Command::LoadFirstPage)); }; + ui.input(|i| { + if !state.was_focused && i.focused && state.skipped_first_focus { + refresh(); + } + if i.focused { + state.skipped_first_focus = true; + } + state.was_focused = i.focused; + }); + if let Some(ref e) = state.fatal_error { ui.label(format!("Fatal error: {e:?}")); return;