mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -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:
@@ -253,9 +253,28 @@ pub struct ViewportInfo {
|
||||
///
|
||||
/// This should be the same as [`RawInput::focused`].
|
||||
pub focused: Option<bool>,
|
||||
|
||||
/// Is the window fully occluded (completely covered) by another window?
|
||||
///
|
||||
/// Not all platforms support this.
|
||||
/// On platforms that don't, this will be `None` or `Some(false)`.
|
||||
pub occluded: Option<bool>,
|
||||
}
|
||||
|
||||
impl ViewportInfo {
|
||||
/// Is the window considered visible for rendering purposes?
|
||||
///
|
||||
/// A window is not visible if it is minimized or occluded.
|
||||
/// When not visible, the UI is not painted and rendering is skipped,
|
||||
/// but application logic may still be executed by some integrations.
|
||||
pub fn visible(&self) -> Option<bool> {
|
||||
match (self.minimized, self.occluded) {
|
||||
(Some(true), _) | (_, Some(true)) => Some(false),
|
||||
(Some(false), Some(false)) => Some(true),
|
||||
(_, None) | (None, _) => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// This viewport has been told to close.
|
||||
///
|
||||
/// If this is the root viewport, the application will exit
|
||||
@@ -282,6 +301,7 @@ impl ViewportInfo {
|
||||
maximized: self.maximized,
|
||||
fullscreen: self.fullscreen,
|
||||
focused: self.focused,
|
||||
occluded: self.occluded,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,6 +318,7 @@ impl ViewportInfo {
|
||||
maximized,
|
||||
fullscreen,
|
||||
focused,
|
||||
occluded,
|
||||
} = self;
|
||||
|
||||
crate::Grid::new("viewport_info").show(ui, |ui| {
|
||||
@@ -345,6 +366,16 @@ impl ViewportInfo {
|
||||
ui.label(opt_as_str(focused));
|
||||
ui.end_row();
|
||||
|
||||
ui.label("Occluded:");
|
||||
ui.label(opt_as_str(occluded));
|
||||
ui.end_row();
|
||||
|
||||
let visible = self.visible();
|
||||
|
||||
ui.label("Visible:");
|
||||
ui.label(opt_as_str(&visible));
|
||||
ui.end_row();
|
||||
|
||||
fn opt_rect_as_string(v: &Option<Rect>) -> String {
|
||||
v.as_ref().map_or(String::new(), |r| {
|
||||
format!("Pos: {:?}, size: {:?}", r.min, r.size())
|
||||
|
||||
Reference in New Issue
Block a user