slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.

Home Page:https://slint.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Initial Android Support

ogoffart opened this issue · comments

This project is funded through NGIO Core via NLNet - https://nlnet.nl/project/SlintAndroid/

Here's a possible breakdown of tasks that we devised. We estimate this in the range of ~4 months of work.

  1. Base Android Port Milestone. This milestone covers the foundation of the port, to allow for the cross-compilation of a Rust based Slint application, deployment to a device, and showing primitive graphics on the screen, including text labels. Rendering is to be done with Skia, for GPU acceleration and native looking text rendering.
  1. Text Input Integration Milestone. This milestone covers the work to allow the user to interact with text input fields in Slint in a way that is consistent with other Android applications.
  • Show or hide the Android system virtual keyboard depending on focus on text input fields.
  • Ensure visibility of text input fields when focused and the virtual keyboard occupies a part of the screen. This includes scrolling and resizing the user interface.
  • Add support for text selection handles by rendering them at the correct location and allowing the user to interact with them way.
  1. Dialog and Menu Widgets. This milestone will add first-class support for Material Design Dialog and Menu components. Dialogs in general and Menus specifically are crucial for many application workflows on Android.
  • Add support for dialog components in the material design style and rendering them in a way that makes them appear like native dialogs.
  • Add support for declaring menu structures in the Slint language, rendering them with the material design style, and obtaining the user-selected menu item choice in native code.
  1. Date and Time Picker Widgets. This milestone will add support for Date and Time picker widgets, for use in dialogs. Both user interface elements represent complex controls and data models, due to different time zones and localization.
  • Add support for a widget in the material design style to allow the user to select a date, based on the system calendar and an optional provided input date.
  • Add support for a widget in the material design style for picking a time, based on the system time and an optional provided input time.

Update: Check the documentation to try the android backend: https://docs.rs/slint/latest/slint/android/index.html

Is there any progress here? I've found that both winit and glutin has Android support.

Not really. There is some work in progress to make it compile in the olivier/wip/android branch, but it doesn't work yet. Some more work will be needed to adjust the way the window is initialized.

Hi, I've forked @ogoffart 's repo and I've finally managed to build a working printerdemo example here by using cargo-apk.

The main issues I've had to solve are:

  1. delaying the initialisation of the window, until the event loop receives a InitWindow event (which means that Android is ready to create it):
    The fastest (and obviously not the most elegant) way is to block android_init using a loop. (the path I've taken)
    The best way would probably be to make surface, gl context and other stuff optional, as other projects have already done.

  2. disable fontconfig, as the ndk doesn't ship a bundled version and Android seems to ignore every self-compiled library one adds to the apk:
    If I've understood correctly the code I've read, the same thing is done for wasm32 builds.

Overall, everything seems to work decently (considering that this was a test), apart from the fact that, as soon as one tries to switch app, Android destroys context and surface and the application crashes (for the same reason of point 1.).
Screenshot_20230601_174645

I hope this will help to speed up the development. Thank you for your work!

Great work!

One aspect that might need support in the run-time library APIs or perhaps even the .slint language is first-class support for the Android Activity Lifecycle. The Android Activity Crate supports these state events, and we may want to integrate this with callbacks to the application - ideally in a platform independent way that the same API could be used also on iOS.

We've made an initial plan for how we'd like to break down the Android port and I'd like to share it here for further editing/discussion. I'll edit the current empty description of this issue for that purpose.

Is there a roadmap or plan with timetable for mobile support?

Is there a roadmap or plan with timetable for mobile support?

We have not made a plan beyond the breakdown and time estimate outlined in the description of this issue. We want to learn from the Android port first and then have a better idea about what additional functionality and features we need to support also iOS and mobile specific features in general. This initial work on Android is also limited to Rust as target programming language.