mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
Call logic even while browser tab is in background (#8257)
* Closes https://github.com/emilk/egui/issues/5112 --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,11 @@ pub(crate) fn seconds_since_midnight() -> f64 {
|
||||
pub trait DemoApp {
|
||||
fn demo_ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame);
|
||||
|
||||
/// Run background logic, called every frame even when the app is hidden.
|
||||
///
|
||||
/// See [`eframe::App::logic`].
|
||||
fn logic(&mut self, _ctx: &egui::Context) {}
|
||||
|
||||
#[cfg(feature = "glow")]
|
||||
fn on_exit(&mut self, _gl: Option<&eframe::glow::Context>) {}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,10 @@ impl DemoApp for DemoWindows {
|
||||
fn demo_ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
|
||||
self.ui(ui);
|
||||
}
|
||||
|
||||
fn logic(&mut self, ctx: &egui::Context) {
|
||||
self.logic(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -280,6 +284,14 @@ impl eframe::App for WrapApp {
|
||||
color.to_normalized_gamma_f32()
|
||||
}
|
||||
|
||||
fn logic(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
// Run background logic for every app, even the ones not currently shown,
|
||||
// so they keep working while the app is hidden (e.g. a backgrounded tab).
|
||||
for (_name, _anchor, app) in self.apps_iter_mut() {
|
||||
app.logic(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
if let Some(anchor) = frame
|
||||
|
||||
Reference in New Issue
Block a user