-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iOS safe area #4915
base: master
Are you sure you want to change the base?
iOS safe area #4915
Conversation
I think this should be part of |
@emilk so, I move the safe area insets function to eframe, but what about the safe area widget. I think it would be better to use something like this instead of a widget: fn safe_area<R>(ui: &mut Ui, inner: impl FnOnce(&mut Ui) -> R) -> R {
let insets = get_ios_safe_area_insets();
if let Some(insets) = insets {
let cursor = ui.cursor().min;
/*
let x = insets.left - cursor.x as f64;
if x > 0. {
let (id, rect) = ui.allocate_space(vec2(x as f32, ui.available_height()));
ui.interact(rect, id, Sense::hover());
}
*/
let y = insets.top - cursor.y as f64;
if y > 0. {
let (id, rect) = ui.allocate_space(vec2(ui.available_width(), y as f32));
ui.interact(rect, id, Sense::hover());
}
let max_height = ui.available_height() - insets.bottom as f32;
if max_height > 0.0 {
ui.set_max_height(max_height);
}
let max_width = ui.available_width() - insets.right as f32;
if max_width > 0.0 {
ui.set_max_width(max_width);
}
}
inner(ui)
} where should I put it? should this be part of egui/egui_extras. should this & the safe area insets function be hidden behind a feature or should it be enabled for every iOS build? its kinda essential and probably needed in every iOS build anyway. And this example above will not work when the inset is != 0 on the left. do you have any ideas how I could get this to work properly? Something like this would be great |
One approach would be to modify |
Seems like winit will soon have a safe area api: rust-windowing/winit#3890 |
Preview available at https://egui-pr-preview.github.io/pr/4915-iOS-safe-area-widget |
Im not quite sure when which events fires in winit. I guessed. theoretically WindowEvent::Resized(_) & ScaleFactorChanged should be enough, but im not sure if the events fire when the app is minimized or repopend in split screen or if the device was flipped while the screen was of so included Focused(true) & Occluded(false). Im not quite sure when the safe area gets merged into winit as it had no updates the last 3 weeks. Migrating from my implementation to the winit implementation should be quite easy anyway( |
I don't know how that got here
The winit PR was approved and is added to the 0.31 milestone so I think it makes sense to just wait for that and then update your PR with the winit implementation |
Before:
After: