diff --git a/crates/egui/src/containers/area.rs b/crates/egui/src/containers/area.rs index 953391ca..f493c20c 100644 --- a/crates/egui/src/containers/area.rs +++ b/crates/egui/src/containers/area.rs @@ -55,6 +55,8 @@ impl State { /// }); /// # }); /// ``` +/// +/// The previous rectangle used by this area can be obtained through [`crate::Memory::area_rect()`]. #[must_use = "You should call .show()"] #[derive(Clone, Copy, Debug)] pub struct Area { diff --git a/crates/egui/src/containers/window.rs b/crates/egui/src/containers/window.rs index 2e4a9a3e..ca4f6190 100644 --- a/crates/egui/src/containers/window.rs +++ b/crates/egui/src/containers/window.rs @@ -21,6 +21,9 @@ use super::*; /// ui.label("Hello World!"); /// }); /// # }); +/// ``` +/// +/// The previous rectangle used by this window can be obtained through [`crate::Memory::area_rect()`]. #[must_use = "You should call .show()"] pub struct Window<'open> { title: WidgetText, diff --git a/crates/egui/src/memory.rs b/crates/egui/src/memory.rs index d89fd344..ede4fb70 100644 --- a/crates/egui/src/memory.rs +++ b/crates/egui/src/memory.rs @@ -487,6 +487,11 @@ impl Memory { pub fn reset_areas(&mut self) { self.areas = Default::default(); } + + /// Obtain the previous rectangle of an area. + pub fn area_rect(&self, id: impl Into) -> Option { + self.areas.get(id.into()).map(|state| state.rect()) + } } /// ## Popups