Expose area::State's Rect in Memory (#3161)

This commit is contained in:
Brian Janssen 2023-08-16 12:52:36 +02:00 committed by GitHub
parent f0addc339c
commit 2c7c59820e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 0 deletions

View File

@ -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 {

View File

@ -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,

View File

@ -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