Skip to content

Commit

Permalink
Fix iOS support in eframe (#3241)
Browse files Browse the repository at this point in the history
* Fix the app only taking up half the screen size on iPad

* Fix request_repaint not working on iOS

* Always use run_and_exit on iOS since run_and_return is not supported by winit on iOS right now.

* Fix typo

* Fix eframe glow on ios

* Handle more cases
  • Loading branch information
lucasmerlin authored Aug 22, 2023
1 parent 2c7c598 commit 461328f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ pub fn window_builder<E>(

window_builder = window_builder_drag_and_drop(window_builder, *drag_and_drop_support);

// Always use the default window size / position on iOS. Trying to restore the previous position
// causes the window to be shown too small.
#[cfg(not(target_os = "ios"))]
let inner_size_points = if let Some(mut window_settings) = window_settings {
// Restore pos/size from previous session

Expand All @@ -163,6 +166,7 @@ pub fn window_builder<E>(
*initial_window_size
};

#[cfg(not(target_os = "ios"))]
if *centered {
if let Some(monitor) = event_loop.available_monitors().next() {
let monitor_size = monitor.size().to_logical::<f64>(monitor.scale_factor());
Expand Down
22 changes: 22 additions & 0 deletions crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ fn with_event_loop<R>(
})
}

#[cfg(not(target_os = "ios"))]
fn run_and_return(
event_loop: &mut EventLoop<UserEvent>,
mut winit_app: impl WinitApp,
Expand Down Expand Up @@ -332,6 +333,11 @@ fn run_and_exit(event_loop: EventLoop<UserEvent>, mut winit_app: impl WinitApp +
next_repaint_time = extremely_far_future();
ControlFlow::Poll
} else {
// WaitUntil seems to not work on iOS
#[cfg(target_os = "ios")]
if let Some(window) = winit_app.window() {
window.request_redraw();
}
ControlFlow::WaitUntil(next_repaint_time)
};
})
Expand Down Expand Up @@ -1052,6 +1058,7 @@ mod glow_integration {
mut native_options: epi::NativeOptions,
app_creator: epi::AppCreator,
) -> Result<()> {
#[cfg(not(target_os = "ios"))]
if native_options.run_and_return {
with_event_loop(native_options, |event_loop, native_options| {
let glow_eframe =
Expand All @@ -1063,6 +1070,13 @@ mod glow_integration {
let glow_eframe = GlowWinitApp::new(&event_loop, app_name, native_options, app_creator);
run_and_exit(event_loop, glow_eframe);
}

#[cfg(target_os = "ios")]
{
let event_loop = create_event_loop_builder(&mut native_options).build();
let glow_eframe = GlowWinitApp::new(&event_loop, app_name, native_options, app_creator);
run_and_exit(event_loop, glow_eframe);
}
}
}

Expand Down Expand Up @@ -1490,6 +1504,7 @@ mod wgpu_integration {
mut native_options: epi::NativeOptions,
app_creator: epi::AppCreator,
) -> Result<()> {
#[cfg(not(target_os = "ios"))]
if native_options.run_and_return {
with_event_loop(native_options, |event_loop, native_options| {
let wgpu_eframe =
Expand All @@ -1501,6 +1516,13 @@ mod wgpu_integration {
let wgpu_eframe = WgpuWinitApp::new(&event_loop, app_name, native_options, app_creator);
run_and_exit(event_loop, wgpu_eframe);
}

#[cfg(target_os = "ios")]
{
let event_loop = create_event_loop_builder(&mut native_options).build();
let wgpu_eframe = WgpuWinitApp::new(&event_loop, app_name, native_options, app_creator);
run_and_exit(event_loop, wgpu_eframe);
}
}
}

Expand Down

0 comments on commit 461328f

Please sign in to comment.