egui icon indicating copy to clipboard operation
egui copied to clipboard

Add iOS native target

Open bogeyturn opened this issue 2 years ago • 13 comments

I want to build a mobile app with egui_bevy. Bevy has a mobile version for iOS, but egui does not have it. Is something like this planned or is the only way be wasm and wgpu?

bogeyturn avatar Jun 27 '23 13:06 bogeyturn

There is not much planning going on :)

A few people wanted Android support, so they opened a few PRs, and now we have Android support.

Getting eframe running on iOS should pose no theoretical obstacles - winit works on iOS as far as I know. So I suggest you try to get it running and see what issues you run in to!

emilk avatar Jun 27 '23 14:06 emilk

@emilk i tried running it with the bevy demo since they are using winit too. I ran into an error with glutin. It complains that no api backend is set. It seems like they support android, but no iOS. That seems to be the only problem when compiling. When using wgpu winit::platform::run_return::EventLoopExtRunReturn is imported which does not exist for iOS.

bogeyturn avatar Jun 27 '23 16:06 bogeyturn

I can report that I'm successfully using egui on iOS for my app. I had to make a couple of changes to get it working well, you can see them here on my egui fork: https://github.com/lucasmerlin/egui/commits/hp_improvements Also contains the fix for the run_return error.

I was even able to add basic keyboard support by making some changes to winit as well. I'll try to open a PR with improved iOS support soon!

@bogeyturn if you want to try my changes you can add the following to your Cargo.toml:

[patch.crates-io]
winit = { git = "https://github.com/lucasmerlin/winit", branch = "hp_fixes"}
egui = { git = "https://github.com/lucasmerlin/egui", branch = "hp_improvements"}
eframe = { git = "https://github.com/lucasmerlin/egui", branch = "hp_improvements"}
egui-wgpu = { git = "https://github.com/lucasmerlin/egui", branch = "hp_improvements"}

lucasmerlin avatar Jul 06 '23 15:07 lucasmerlin

@lucasmerlin thats awesome. I tested it originally with bevy’s demo. I used the macro from bevy so I could start it. Could you add a simple example how you got it running. I can’t test it right now and I believe bevy’s stuff will work fine, but a minimal example would be great

bogeyturn avatar Jul 17 '23 11:07 bogeyturn

This minimal example works on my iPad: https://github.com/lucasmerlin/egui-apple-example If I remember correctly it's basically just cargo mobile init (from tauri mobile) with the egui example and then adding the patch to the Cargo.toml file. If you checkout the repo you have to do cargo mobile init and add your development team id in mobile.toml (no idea where to find that, it prefilled it for me when i created the project with cargo mobile init).

You can also use eframe in the project (I do in my actual project) but the tauri mobile example doesn't use it. Should be easy to switch to eframe though.

I might eventually write a sophisticated blog post for my setup to compile my app for iOS, android, wasm, and desktop, but first I want to actually release my app lol

lucasmerlin avatar Jul 17 '23 14:07 lucasmerlin

@lucasmerlin this repo is private. It would be great if you could make it public.

bogeyturn avatar Jul 17 '23 15:07 bogeyturn

@bogeyturn sorry, should be public now

lucasmerlin avatar Jul 17 '23 16:07 lucasmerlin

@lucasmerlin that seems to be some boiler plate code. Wouldn’t it be possible to hide that behind a macro like this https://github.com/bevyengine/bevy/blob/main/crates/bevy_derive/src/bevy_main.rs

bogeyturn avatar Jul 17 '23 19:07 bogeyturn

I tried the latest version of egui/eframe on ios with the bevy template & the eframe template. It compiles and works for the most part. The keyboard input seems to not work on iphones & there is a black bar at the bottom. The black bar is probably just a problem with the default options.

Simulator Screenshot - iPhone 14 - 2023-08-27 at 18 38 39

JustFrederik avatar Aug 27 '23 16:08 JustFrederik

The keyboard input seems to not work on iphones & there is a black bar at the bottom.

I don't actually know fully what the context is on this example but over in https://github.com/iced-rs/iced/pull/631, to get keyboard input (the native OS keyboard), I actually used UITextView which had a Rust event handler function that sent events based on text change.

https://github.com/rust-windowing/winit/issues/2260 is the current state. There's some progress with android, not so much on iOS. Doing so requires getting one's hands dirty with the objc/objc2 crate in winit.

The black bar is probably just a problem with the default options.

Hmm. This sounds like a lack of field missing from the Info.plist. This was an issue in cargo-dinghy and cargo-bundle lacking a UILaunchStoryboardName key (value not needed IIRC).

simlay avatar Oct 29 '23 23:10 simlay

Just wondering if anyone got this working? Im thinking of trying some egui for some little mobile apps, but I don't want to get stuck at the first step of getting it to fill the screen. :)

zaddok avatar Sep 25 '24 13:09 zaddok

@zaddok emilk/eframe_template#152 iOS build script #5211 black bar issue #4915 safe area

frederik-uni avatar Oct 02 '24 15:10 frederik-uni

Amazing, thank you!

zaddok avatar Oct 03 '24 01:10 zaddok

I just found this thread and worked through it. I was able to get the example in https://github.com/frederik-uni/eframe_template/tree/ios-build-script running on a simulator, but ran into the no keyboard entry issue and black bar.

Has any progress been made with the keyboard issue?

ptliddle avatar Dec 08 '24 18:12 ptliddle

@ptliddle look up into the linked pull requests. has been fixed but not merged/merged but not released

frederik-uni avatar Dec 08 '24 18:12 frederik-uni

Also, keyboard support was merged but I don't think there was a winit release since. https://github.com/rust-windowing/winit/pull/3823

lucasmerlin avatar Dec 08 '24 18:12 lucasmerlin

the black bar should be fixed by [patch....]

frederik-uni avatar Dec 08 '24 18:12 frederik-uni

Thanks.

I managed to fix the black bar but couldn't get the keyboard working.

When i tried to use a newer version of winit i get dependency issues. It looks like eframe requires a winit version with the feature "rwh_06". I'll just wait until a new egui version is released and try again.

I was just exploring egui as an option for an internal app to run on macOS, Linux and iPhone. I decided to take a different path as it doesn't look like the egui ecosystem is quite there on a supportable level yet. Excited for the possibility in the future though.

ptliddle avatar Dec 16 '24 03:12 ptliddle

Hi,

It seems that you awesome guys have made great progress without facing much difficulties. Is it possible to have this merged?

Thanks!

SuperKenVery avatar Apr 12 '25 08:04 SuperKenVery