diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 93db05e77..bda63b99f 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -460,7 +460,7 @@ impl ContextImpl { // If the window is minimized or occluded, the integration may still run passes // to keep app logic ticking, but without showing any ui. // We then skip all book-keeping that assumes ui was shown. - let is_visible = new_raw_input.viewport().visible().unwrap_or(true); + let is_visible = new_raw_input.is_visible(); self.memory.begin_pass(&new_raw_input, &all_viewport_ids); @@ -836,7 +836,7 @@ impl Context { fn run_dyn(&self, mut new_input: RawInput, run_ui: &mut dyn FnMut(&Self)) -> FullOutput { profiling::function_scope!(); let viewport_id = new_input.viewport_id; - let is_visible = new_input.viewport().visible().unwrap_or(true); + let is_visible = new_input.is_visible(); let max_passes = self.write(|ctx| ctx.memory.options.max_passes.get()); let mut output = FullOutput::default(); @@ -1751,7 +1751,7 @@ impl Context { /// /// See [`ViewportInfo::visible`]. pub fn is_visible(&self) -> bool { - self.input(|i| i.viewport().visible().unwrap_or(true)) + self.input(|i| i.is_visible()) } /// The total number of completed passes (usually there is one pass per rendered frame). @@ -2652,7 +2652,7 @@ impl ContextImpl { // If nothing was shown this pass we skip all book-keeping that assumes ui was shown. // See [`Context::is_visible`]. - let is_visible = viewport.input.viewport().visible().unwrap_or(true); + let is_visible = viewport.input.is_visible(); if is_visible { // A pass without any ui uses no images and no widget ids, diff --git a/crates/egui/src/data/input/raw_input.rs b/crates/egui/src/data/input/raw_input.rs index 7135e90e0..4fc1931b0 100644 --- a/crates/egui/src/data/input/raw_input.rs +++ b/crates/egui/src/data/input/raw_input.rs @@ -117,6 +117,17 @@ impl RawInput { self.viewports.get(&self.viewport_id).expect("Failed to find current viewport in egui RawInput. This is the fault of the egui backend") } + /// Is the active viewport visible, i.e. neither minimized nor occluded? + /// + /// Defaults to `true` if the integration doesn't report + /// [`ViewportInfo::minimized`] and [`ViewportInfo::occluded`]. + /// + /// See [`crate::Context::is_visible`]. + #[inline] + pub fn is_visible(&self) -> bool { + self.viewport().visible().unwrap_or(true) + } + /// Helper: move volatile (deltas and events), clone the rest. /// /// * [`Self::hovered_files`] is cloned. diff --git a/crates/egui/src/input_state/mod.rs b/crates/egui/src/input_state/mod.rs index 36d6f9bc9..140fd33f5 100644 --- a/crates/egui/src/input_state/mod.rs +++ b/crates/egui/src/input_state/mod.rs @@ -501,6 +501,17 @@ impl InputState { self.raw.viewport() } + /// Is the active viewport visible, i.e. neither minimized nor occluded? + /// + /// Defaults to `true` if the integration doesn't report + /// [`ViewportInfo::minimized`] and [`ViewportInfo::occluded`]. + /// + /// See [`crate::Context::is_visible`]. + #[inline] + pub fn is_visible(&self) -> bool { + self.raw.is_visible() + } + /// Returns the region of the screen that is safe for content rendering /// /// Returns the `viewport_rect` with the `safe_area_insets` removed. diff --git a/crates/egui/src/memory/mod.rs b/crates/egui/src/memory/mod.rs index 90d69d097..c3a640e7d 100644 --- a/crates/egui/src/memory/mod.rs +++ b/crates/egui/src/memory/mod.rs @@ -797,7 +797,7 @@ impl Memory { self.options.begin_pass(new_raw_input); - if new_raw_input.viewport().visible().unwrap_or(true) { + if new_raw_input.is_visible() { // When nothing is shown, no widget will ask for focus, // so leave the focus state alone. See [`crate::Context::is_visible`]. self.focus diff --git a/crates/egui_kittest/src/lib.rs b/crates/egui_kittest/src/lib.rs index ba57ddfac..1e4b8d1ca 100644 --- a/crates/egui_kittest/src/lib.rs +++ b/crates/egui_kittest/src/lib.rs @@ -259,7 +259,7 @@ impl<'a, State> Harness<'a, State> { fn _step(&mut self, sizing_pass: bool) { self.input.predicted_dt = self.step_dt; - let is_visible = self.input.viewport().visible().unwrap_or(true); + let is_visible = self.input.is_visible(); let mut output = self.ctx.run_ui(self.input.take(), |ui| { self.response = self.app.run(ui, &mut self.state, sizing_pass);