mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Add support for the safe area on iOS (#7578)
This PR is a continuation of #4915 by @frederik-uni and @lucasmerlin that introduces support for keeping egui content within the 'safe area' on iOS (avoiding the notch / dynamic island / menu bar etc.), with the following changes: - `SafeArea` now wraps `MarginF32` and has been renamed to `SafeAreaInsets` to clarify its purpose. - `InputState::screen_rect` is now marked as deprecated in favour of either `viewport_rect` (which contains the entire screen), or `content_rect` (which is the viewport rect with the safe area insets removed). - I added some comments to the safe area insets logic pointing out the [safe area API coming in winit v0.31](https://github.com/rust-windowing/winit/issues/3910). --------- Co-authored-by: frederik-uni <147479464+frederik-uni@users.noreply.github.com> Co-authored-by: Lucas Meurer <hi@lucasmerlin.me> Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
@@ -18,6 +18,7 @@ use egui::{Pos2, Rect, Theme, Vec2, ViewportBuilder, ViewportCommand, ViewportId
|
||||
pub use winit;
|
||||
|
||||
pub mod clipboard;
|
||||
mod safe_area;
|
||||
mod window_settings;
|
||||
|
||||
pub use window_settings::WindowSettings;
|
||||
@@ -274,6 +275,21 @@ impl State {
|
||||
}
|
||||
|
||||
use winit::event::WindowEvent;
|
||||
|
||||
#[cfg(target_os = "ios")]
|
||||
match &event {
|
||||
WindowEvent::Resized(_)
|
||||
| WindowEvent::ScaleFactorChanged { .. }
|
||||
| WindowEvent::Focused(true)
|
||||
| WindowEvent::Occluded(false) => {
|
||||
// Once winit v0.31 has been released this can be reworked to get the safe area from
|
||||
// `Window::safe_area`, and updated from a new event which is being discussed in
|
||||
// https://github.com/rust-windowing/winit/issues/3911.
|
||||
self.egui_input_mut().safe_area_insets = Some(safe_area::get_safe_area_insets());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
match event {
|
||||
WindowEvent::ScaleFactorChanged { scale_factor, .. } => {
|
||||
let native_pixels_per_point = *scale_factor as f32;
|
||||
|
||||
Reference in New Issue
Block a user