lvgl / lv_binding_rust

LVGL bindings for Rust. A powerful and easy-to-use embedded GUI with many widgets, advanced visual effects (opacity, antialiasing, animations) and low memory requirements (16K RAM, 64K Flash).
MIT License
687 stars 71 forks source link

Create example using WebAssembly #15

Closed rafaelcaricio closed 3 years ago

rafaelcaricio commented 4 years ago

Create a WebAssembly demo app using the web simulator of embedded_graphics library. It would be a great way to show the possibilities of lvgl-rs by compiling to WASM. The example can also be a quick start for many people.

FloVanGH commented 4 years ago

Does anyone managed to run it on WebAssembly? When I try to build it I get the following error:

_core/../lv_font/../lv_misc/lv_area.h:17:10: fatal error: 'string.h' file not found
  cargo:warning=#include <string.h>
rafaelcaricio commented 4 years ago

Hey @FloVanGH , I haven't tried yet. But I'd imagine that to compile to WebAssembly we would need to tweak our build.rs to handle cases like this one.

FloVanGH commented 4 years ago

Hey @rafaelcaricio.If you can adjust the build.rs I can contribute an example 🙂.

FloVanGH commented 4 years ago

I want to add an lvgl example to my crate: https://codeberg.org/morph/canvas-display. I have also a working desktop example for an other crate https://codeberg.org/morph/raqote-display.

rafaelcaricio commented 4 years ago

@FloVanGH I can work on updating the build.rs, but I'm pretty tight on free time right now so I cannot compromise when I can do it. I hope to get some time to work on lvgl-rs soon.

rafaelcaricio commented 4 years ago

Awesome work, btw! :)

FloVanGH commented 4 years ago

@FloVanGH I can work on updating the build.rs, but I'm pretty tight on free time right now so I cannot compromise when I can do it. I hope to get some time to work on lvgl-rs soon.

Ok I see. It's not urgent. But I hope you'll find some time. And I hope you can continue your work, it's really great 🙂.

FloVanGH commented 4 years ago

Awesome work, btw! :)

Thank you 🙂

rafaelcaricio commented 4 years ago

I've tried that this weekend and didn't work yet. I will continue trying to compile for the wasm32-unknown-emscripten target, that one may work (https://github.com/rustwasm/team/issues/291).

FloVanGH commented 4 years ago

Hey, ok thank you for your effort 🙂.

rafaelcaricio commented 4 years ago

@FloVanGH after many hours of trial and error, it's possible to compile lvgl-rs to WASM after those changes https://github.com/rafaelcaricio/lvgl-rs/pull/31

I have an example here: https://github.com/rafaelcaricio/lvgl-rs-wasm (needs Rust nightly)

It compiles, but doesn't work in the browser. It panics at some slice index that supposed to not happen. Works fine when compiled to local binary.

FloVanGH commented 4 years ago

@rafaelcaricio that's awesome :-) . Thank you. I will create an example for canvas-display.

rafaelcaricio commented 4 years ago

@FloVanGH No problem! Let me know if it works for you in the browser. As I said, even though I managed to make the example project compile successfully, it panics when running in the browser for some strange reason.

rafaelcaricio commented 4 years ago
Screenshot

This is the error I get... :/

FloVanGH commented 4 years ago

Ok thank you. I will check it.

rafaelcaricio commented 4 years ago

@FloVanGH I managed to make it work! 🥳 The example project is running here: https://rafaelcaricio.github.io/lvgl-rs-wasm/

Example code: https://github.com/rafaelcaricio/lvgl-rs-wasm

FloVanGH commented 4 years ago

🎉