vexide-slint 0.1.0

Slint for the vexide runtime
Documentation
# Slint for vexide

This crate exists to allow for the use of Slint-based UIs in [vexide]. It
provides an implementation of the Slint `Platform` trait that uses the V5 brain
to render the UI.

[vexide]: https://vexide.dev

## Usage

To use this crate, add it to your `Cargo.toml`:

```toml
[dependencies]
slint-vexide = "0.1.0"
```

Then, you must call `slint_vexide::initialize_slint_platform()` before creating
and running your Slint widget. This will set up Slint for software-rendering
your UI on the brain's display.

## Example

```rust
// Include the modules generated by Slint for your UI files.
// You will need to configure your `build.rs` to do this; see below.
slint::include_modules!();

#[vexide::main]
async fn main(peripherals: vexide::prelude::Peripherals) {
    let robot = Robot {
        // ...
    };

    // Since running the Slint UI is a blocking operation, we need to spawn the
    // competition task as a separate task that will run concurrently.
    // The Slint runtime internally polls all spawned futures.
    vexide::task::spawn(robot.compete()).detach();

    // Initialize the Slint platform with the V5 display-backed implementation.
    vexide_slint::initialize_slint_platform(peripherals.display);
    // Create and run the application. For more information on this, see the
    // Slint documentation.
    MyApplication::new()
        .expect("Failed to create application")
        .run()
        .expect("Failed to run application");
    // Since MyApplication::run() could return if the application is closed
    // programmatically, we need to convince the compiler that the return type
    // is `!` (never).
    vexide::program::exit();
}
```

You'll need to compile your UI code separately from your main application code
using a custom build script. Add the `slint-build` crate to your `Cargo.toml`:

```toml
[build-dependencies]
slint-build = "1.10.0"
```

Then, create a `build.rs` file in your project root with the following content:

```rust
fn main() {
    // Compile the Slint UI file with the appropriate configuration.
    slint_build::compile_with_config(
        "ui/YourFile.slint", // Path to your Slint UI file.
        slint_build::CompilerConfiguration::new()
            // Make sure to enable this configuration flag.
            .embed_resources(slint_build::EmbedResourcesKind::EmbedForSoftwareRenderer)
            // Optionally, you can specify a style to use for the UI.
            // Check the Slint documentation for more information.
            .with_style("style-name".into()),
    )
    .expect("Slint build failed");
}
```