mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 14:49:06 -04:00
Add ViewportInfo::occluded and visible (#7948)
* Part of https://github.com/emilk/egui/issues/5112 * Part of https://github.com/emilk/egui/issues/5113 * Part of https://github.com/emilk/egui/issues/5136 Once we support calling `App::logic` when an app is occluded or minimized, it is useful to know that it is, in fact, occluded or minimized. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
14
tests/test_background_logic/Cargo.toml
Normal file
14
tests/test_background_logic/Cargo.toml
Normal file
@@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "test_background_logic"
|
||||
version = "0.1.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
edition = "2024"
|
||||
rust-version = "1.92"
|
||||
publish = false
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
eframe = { workspace = true, features = ["default"] }
|
||||
env_logger = { workspace = true, features = ["auto-color", "humantime"] }
|
||||
64
tests/test_background_logic/src/main.rs
Normal file
64
tests/test_background_logic/src/main.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
#![expect(rustdoc::missing_crate_level_docs)]
|
||||
#![allow(clippy::print_stderr)]
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use eframe::egui::{self, ViewportInfo};
|
||||
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
|
||||
let _ = eframe::run_native(
|
||||
"Background Logic Test",
|
||||
eframe::NativeOptions {
|
||||
viewport: egui::ViewportBuilder::default().with_inner_size([400.0, 200.0]),
|
||||
..Default::default()
|
||||
},
|
||||
Box::new(|_cc| Ok(Box::new(App))),
|
||||
);
|
||||
}
|
||||
|
||||
struct App;
|
||||
|
||||
impl eframe::App for App {
|
||||
fn logic(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
eprintln!("App::logic called {}", viewport_info(ctx));
|
||||
ctx.request_repaint_after(Duration::from_secs(1));
|
||||
}
|
||||
|
||||
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
|
||||
eprintln!("App::ui called {}", viewport_info(ui.ctx()));
|
||||
ui.centered_and_justified(|ui| {
|
||||
ui.heading("Minimize this window");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn viewport_info(ctx: &egui::Context) -> String {
|
||||
ctx.input(|i| {
|
||||
let ViewportInfo {
|
||||
minimized,
|
||||
focused,
|
||||
occluded,
|
||||
..
|
||||
} = i.viewport();
|
||||
|
||||
let visible = i.viewport().visible();
|
||||
|
||||
let mut s = String::new();
|
||||
|
||||
let flags = [
|
||||
("focused", focused),
|
||||
("occluded", occluded),
|
||||
("minimized", minimized),
|
||||
("visible", &visible),
|
||||
];
|
||||
for (name, value) in flags {
|
||||
if let Some(value) = value {
|
||||
s += &format!(" {name}={value}");
|
||||
}
|
||||
}
|
||||
s
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user