32 releases (20 stable)

1.8.0 Sep 23, 2024
1.7.1 Jul 25, 2024
1.5.1 Mar 20, 2024
1.3.2 Dec 1, 2023
0.2.1 Mar 10, 2022

#971 in GUI

Download history 75/week @ 2024-08-21 45/week @ 2024-08-28 70/week @ 2024-09-04 110/week @ 2024-09-11 283/week @ 2024-09-18 167/week @ 2024-09-25 193/week @ 2024-10-02 70/week @ 2024-10-09 55/week @ 2024-10-16 49/week @ 2024-10-23 48/week @ 2024-10-30 49/week @ 2024-11-06 59/week @ 2024-11-13 54/week @ 2024-11-20 66/week @ 2024-11-27 60/week @ 2024-12-04

246 downloads per month
Used in 3 crates

GPL-3.0-only…

4.5MB
87K SLoC

Rust 76K SLoC // 0.0% comments Slint 10K SLoC // 0.0% comments

Slint interpreter library

With this crate, you can load a .slint file at runtime and show its UI.

You only need to use this crate if you do not want to use pre-compiled .slint code, which is the normal way to use Slint, using the slint crate

The entry point for this crate is the Compiler type, which you can use to create CompilationResult with the Compiler::build_from_source or Compiler::build_from_path functions. CompilationResult provides access to all components declared for export. Obtain a ComponentDefinition for each and use [ComponentDefinition::create()] to instantiate a component. The returned ComponentInstance in turn provides access to properties, callbacks, functions, global singletons, as well as implementing ComponentHandle.

Note about async functions

Compiling a component is async but in practice, this is only asynchronous if Compiler::set_file_loader is set and its future is actually asynchronous. If that is not used, then it is fine to use a very simple executor, such as the one provided by the spin_on crate

Examples

This example loads a .slint dynamically from a path and show errors if any:

use slint_interpreter::{ComponentDefinition, Compiler, ComponentHandle};

let compiler = Compiler::default();
let result = spin_on::spin_on(compiler.build_from_path("hello.slint"));
let diagnostics : Vec<_> = result.diagnostics().collect();
diagnostics.print();
if let Some(definition) = result.component("Foo") {
let instance = definition.create().unwrap();
instance.run().unwrap();
}

This example load a .slint from a string and set some properties:

use slint_interpreter::{ComponentDefinition, Compiler, Value, SharedString, ComponentHandle};

let code = r#"
export component MyWin inherits Window {
in property <string> my_name;
Text {
text: "Hello, " + my_name;
}
}
"#;

let mut compiler = Compiler::default();
let result =
spin_on::spin_on(compiler.build_from_source(code.into(), Default::default()));
assert_eq!(result.diagnostics().count(), 0);
let definition = result.component("MyWin");
let instance = definition.unwrap().create().unwrap();
instance.set_property("my_name", Value::from(SharedString::from("World"))).unwrap();
instance.run().unwrap();

Feature flags

Dependencies

~8–49MB
~812K SLoC