Skip to content

Commit

Permalink
Expose area::State's Rect in Memory
Browse files Browse the repository at this point in the history
  • Loading branch information
tosti007 committed Aug 16, 2023
1 parent f0addc3 commit c5f0cdb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crates/egui/src/containers/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions crates/egui/src/containers/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions crates/egui/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Id>) -> Option<Rect> {
self.areas.get(id.into()).map(|state| state.rect())
}
}

/// ## Popups
Expand Down

0 comments on commit c5f0cdb

Please sign in to comment.