BrainiumLLC / cargo-mobile

Rust on mobile made easy!
Apache License 2.0
1.23k stars 52 forks source link

added iced tour example template #4

Open matthieugayon opened 3 years ago

matthieugayon commented 3 years ago

Just the beginning of an iced template for cargo mobile :) It's based on the tour example https://github.com/hecrj/iced/tree/master/examples/tour and it's pointing to this version of iced https://github.com/hecrj/iced/pull/650 which is a pending PR to add basic mobile support to iced

francesca64 commented 3 years ago

This is super cool!

There's probably some way we could make Metal validation configurable, unless you think it's likely to only be a short-term issue.

It doesn't seem like I'm able to touch the Next button on iOS. Is that expected? Besides that, it renders perfectly, and the scroll bar works too. Of course, I'll accept this PR either way!

I also hit an ICE (!) when building for Android. Though, since this is originally based on simlay's work, I'm guessing iced only supports iOS so far? If so, adding this section to Cargo.toml.hbs will cause cargo-mobile to warn when trying to build for Android:

[package.metadata.cargo-android]
supported = false
francesca64 commented 3 years ago

Also, assets (like ferris.png) will only be available on mobile if they're in the assets directory. Either renaming the images dir to assets or moving the images dir into a new dir named assets would work.

Of course, the path of the asset directory can also be configured in mobile.toml; assets is just the fault. However, template packs don't have any control over the config in mobile.toml, so you have to stick with the default for now.

zeerooth commented 3 years ago

The PR you mentioned was merged to iced some time ago, so I locally merged the current master branch from cargo-mobile into iced-template, changed the iced version in Cargo.toml to

iced = { git = "https://github.com/hecrj/iced", branch = "master", features = ["image", "debug"] }

and tried running it on my Android device.

Unfortunately, there seems to be an issue with the current vulkan backend in gfx-backend-vulkan crate, because I get a panic:

RustStdoutStderr: thread '<unnamed>' panicked at 'AndroidSurface failed: ERROR_NATIVE_WINDOW_IN_USE_KHR', /home/radek/.cargo/registry/src/github.com-1ecc6299db9ec823/gfx-backend-vulkan-0.7.0/src/window.rs:133:69

I also tried enabling the glow feature to try an OpenGL backend, but this one won't even compile

error[E0615]: attempted to take value of method `SwapBuffersWithDamageKHR` on type `&api::egl::egl::Egl`
   --> /home/radek/.cargo/registry/src/github.com-1ecc6299db9ec823/glutin-0.26.0/src/api/egl/mod.rs:660:13
    |
660 |         egl.SwapBuffersWithDamageKHR.is_loaded()
    |             ^^^^^^^^^^^^^^^^^^^^^^^^ method, not a field
    |
help: use parentheses to call the method
    |
660 |         egl.SwapBuffersWithDamageKHR(_, _, _, _).is_loaded()
    | 

Now, it looks like Android is not really supported in glutin as per this PR And somebody had a similar issue but I don't think they managed to make it work in the end.

So that's the current status - I'll try to fix those issues and make some PRs if necessary, because currently iced is closest among all UI crates in Rust to being usable on Android and it would be so cool to have it included in cargo-mobile if possible.

Edit: Android Tracking Issue was opened in iced repo containing a list of things that need to be addressed before iced can be run on Android.