From 2c7c59820e9bd74863d8cd7a578eca0bdbf3b7c9 Mon Sep 17 00:00:00 2001 From: Brian Janssen Date: Wed, 16 Aug 2023 12:52:36 +0200 Subject: [PATCH] Expose area::State's Rect in Memory (#3161) --- crates/egui/src/containers/area.rs | 2 ++ crates/egui/src/containers/window.rs | 3 +++ crates/egui/src/memory.rs | 5 +++++ 3 files changed, 10 insertions(+) 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