Better docs + deprecation for screen/content/viewport_rect (#7605)

This commit is contained in:
Emil Ernerfeldt 2025-10-08 10:43:11 +02:00 committed by GitHub
parent c3c08fa38a
commit 0d47abcaa0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 12 deletions

View File

@ -2670,6 +2670,8 @@ impl Context {
///
/// Returns [`Self::viewport_rect`] minus areas that might be partially covered by, for example,
/// the OS status bar or display notches.
///
/// If you want to render behind e.g. the dynamic island on iOS, use [`Self::viewport_rect`].
pub fn content_rect(&self) -> Rect {
self.input(|i| i.content_rect()).round_ui()
}
@ -2678,13 +2680,19 @@ impl Context {
///
/// This includes reas that might be partially covered by, for example, the OS status bar or
/// display notches. See [`Self::content_rect`] to get a rect that is safe for content.
///
/// This rectangle includes e.g. the dynamic island on iOS.
/// If you want to only render _below_ the that (not behind), then you should use
/// [`Self::content_rect`] instead.
///
/// See also [`RawInput::safe_area_insets`].
pub fn viewport_rect(&self) -> Rect {
self.input(|i| i.viewport_rect()).round_ui()
}
/// Position and size of the egui area.
#[deprecated(
note = "screen_rect has been renamed to viewport_rect. Consider switching to content_rect."
note = "screen_rect has been split into viewport_rect() and content_rect(). You likely should use content_rect()"
)]
pub fn screen_rect(&self) -> Rect {
self.input(|i| i.content_rect()).round_ui()

View File

@ -583,28 +583,35 @@ impl InputState {
self.raw.viewport()
}
/// Returns the full area available to egui, including parts that might be partially covered,
/// for example, by the OS status bar or notches (see [`Self::safe_area_insets`]).
///
/// Usually you want to use [`Self::content_rect`] instead.
pub fn viewport_rect(&self) -> Rect {
self.viewport_rect
}
/// Returns the region of the screen that is safe for content rendering
///
/// Returns the `viewport_rect` with the `safe_area_insets` removed.
///
/// If you want to render behind e.g. the dynamic island on iOS, use [`Self::viewport_rect`].
///
/// See also [`RawInput::safe_area_insets`].
#[inline(always)]
pub fn content_rect(&self) -> Rect {
self.viewport_rect - self.safe_area_insets
}
/// Returns the full area available to egui, including parts that might be partially
/// covered, for example, by the OS status bar or notches.
/// Returns the full area available to egui, including parts that might be partially covered,
/// for example, by the OS status bar or notches (see [`Self::safe_area_insets`]).
///
/// Usually you want to use [`Self::content_rect`] instead.
///
/// This rectangle includes e.g. the dynamic island on iOS.
/// If you want to only render _below_ the that (not behind), then you should use
/// [`Self::content_rect`] instead.
///
/// See also [`RawInput::safe_area_insets`].
pub fn viewport_rect(&self) -> Rect {
self.viewport_rect
}
/// Position and size of the egui area.
#[deprecated(
note = "screen_rect has been renamed to viewport_rect. Consider switching to content_rect."
note = "screen_rect has been split into viewport_rect() and content_rect(). You likely should use content_rect()"
)]
pub fn screen_rect(&self) -> Rect {
self.content_rect()