Skip to content

Commit 461328f

Browse files
authored
Fix iOS support in eframe (#3241)
* 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
1 parent 2c7c598 commit 461328f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

crates/eframe/src/native/epi_integration.rs

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ pub fn window_builder<E>(
138138

139139
window_builder = window_builder_drag_and_drop(window_builder, *drag_and_drop_support);
140140

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

@@ -163,6 +166,7 @@ pub fn window_builder<E>(
163166
*initial_window_size
164167
};
165168

169+
#[cfg(not(target_os = "ios"))]
166170
if *centered {
167171
if let Some(monitor) = event_loop.available_monitors().next() {
168172
let monitor_size = monitor.size().to_logical::<f64>(monitor.scale_factor());

crates/eframe/src/native/run.rs

+22
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ fn with_event_loop<R>(
119119
})
120120
}
121121

122+
#[cfg(not(target_os = "ios"))]
122123
fn run_and_return(
123124
event_loop: &mut EventLoop<UserEvent>,
124125
mut winit_app: impl WinitApp,
@@ -332,6 +333,11 @@ fn run_and_exit(event_loop: EventLoop<UserEvent>, mut winit_app: impl WinitApp +
332333
next_repaint_time = extremely_far_future();
333334
ControlFlow::Poll
334335
} else {
336+
// WaitUntil seems to not work on iOS
337+
#[cfg(target_os = "ios")]
338+
if let Some(window) = winit_app.window() {
339+
window.request_redraw();
340+
}
335341
ControlFlow::WaitUntil(next_repaint_time)
336342
};
337343
})
@@ -1052,6 +1058,7 @@ mod glow_integration {
10521058
mut native_options: epi::NativeOptions,
10531059
app_creator: epi::AppCreator,
10541060
) -> Result<()> {
1061+
#[cfg(not(target_os = "ios"))]
10551062
if native_options.run_and_return {
10561063
with_event_loop(native_options, |event_loop, native_options| {
10571064
let glow_eframe =
@@ -1063,6 +1070,13 @@ mod glow_integration {
10631070
let glow_eframe = GlowWinitApp::new(&event_loop, app_name, native_options, app_creator);
10641071
run_and_exit(event_loop, glow_eframe);
10651072
}
1073+
1074+
#[cfg(target_os = "ios")]
1075+
{
1076+
let event_loop = create_event_loop_builder(&mut native_options).build();
1077+
let glow_eframe = GlowWinitApp::new(&event_loop, app_name, native_options, app_creator);
1078+
run_and_exit(event_loop, glow_eframe);
1079+
}
10661080
}
10671081
}
10681082

@@ -1490,6 +1504,7 @@ mod wgpu_integration {
14901504
mut native_options: epi::NativeOptions,
14911505
app_creator: epi::AppCreator,
14921506
) -> Result<()> {
1507+
#[cfg(not(target_os = "ios"))]
14931508
if native_options.run_and_return {
14941509
with_event_loop(native_options, |event_loop, native_options| {
14951510
let wgpu_eframe =
@@ -1501,6 +1516,13 @@ mod wgpu_integration {
15011516
let wgpu_eframe = WgpuWinitApp::new(&event_loop, app_name, native_options, app_creator);
15021517
run_and_exit(event_loop, wgpu_eframe);
15031518
}
1519+
1520+
#[cfg(target_os = "ios")]
1521+
{
1522+
let event_loop = create_event_loop_builder(&mut native_options).build();
1523+
let wgpu_eframe = WgpuWinitApp::new(&event_loop, app_name, native_options, app_creator);
1524+
run_and_exit(event_loop, wgpu_eframe);
1525+
}
15041526
}
15051527
}
15061528

0 commit comments

Comments
 (0)