Skip to main content

Crate slint_build

Crate slint_build 

Source
Expand description

This crate serves as a companion crate of the slint crate. It is meant to allow you to compile the .slint files from your build.rs script.

The main entry point of this crate is the compile() function

The generated code must be included in your crate by using the slint::include_modules!() macro.

§Example

In your Cargo.toml:

[package]
...
build = "build.rs"

[dependencies]
slint = "1.16.0"
...

[build-dependencies]
slint-build = "1.16.0"

In the build.rs file:

fn main() {
    slint_build::compile("ui/hello.slint").unwrap();
}

Then in your main file

slint::include_modules!();
fn main() {
    HelloWorld::new().run();
}

§Feature flags

  • compat-1-18 (enabled by default) — Mandatory feature: This feature is required to keep the compatibility with Slint 1.18. Newer patch versions may put current functionality behind a new feature that would be enabled by default only if this feature was added. More info in this blog post
  • renderer-software (enabled by default) — Embed images and fonts in a format optimized for the software renderer. Enables the EmbedResourcesKind::EmbedForSoftwareRenderer variant.
  • image-default-formats — Support additional image formats when embedding images for the renderer-software feature. Without this feature, only PNG and JPEG are supported. Not enabled by default: most projects embed a .slint UI’s own PNG/JPEG assets, and this feature’s decoder dependencies are only reachable when CompilerConfiguration::embed_resources is set to EmbedForSoftwareRenderer.
  • sdf-fonts — Enable the CompilerConfiguration::with_sdf_fonts function that encodes the fonts embedded for the software renderer as scalable signed distance fields, to reduce their size.

Structs§

CompilerConfiguration
The structure for configuring aspects of the compilation of .slint markup files to Rust.

Enums§

CompileError
Error returned by the compile function
DefaultTranslationContext
Argument of CompilerConfiguration::with_default_translation_context()
EmbedResourcesKind
How should the Slint compiler embed images and fonts

Functions§

compile
Compile the .slint file and generate rust code for it.
compile_with_config
Same as compile, but allow to specify a configuration.
compile_with_output_path
Similar to compile_with_config, but meant to be used independently of cargo.
print_rustc_flags
This function is for use the application’s build script, in order to print any device specific build flags reported by the backend