emilk / egui

egui: an easy-to-use immediate mode GUI in Rust that runs on both web and native
https://www.egui.rs/
Apache License 2.0
22.46k stars 1.6k forks source link

Add iOS native target #3117

Open bogeyturn opened 1 year ago

bogeyturn commented 1 year ago

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?

emilk commented 1 year ago

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!

bogeyturn commented 1 year ago

@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.

lucasmerlin commented 1 year ago

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"}
bogeyturn commented 1 year ago

@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

lucasmerlin commented 1 year ago

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

bogeyturn commented 1 year ago

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

lucasmerlin commented 1 year ago

@bogeyturn sorry, should be public now

bogeyturn commented 1 year ago

@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

JustFrederik commented 1 year ago

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

simlay commented 1 year ago

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).

zaddok commented 1 month ago

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. :)

frederik-uni commented 1 month ago

@zaddok emilk/eframe_template#152 iOS build script

5211 black bar issue

4915 safe area

zaddok commented 1 month ago

Amazing, thank you!