11 releases

0.3.4 Jan 25, 2023
0.3.3 Dec 16, 2022
0.3.2 Nov 28, 2022
0.2.5 Jul 6, 2022
0.2.1 Mar 10, 2022

#386 in GUI

Download history 13/week @ 2022-10-13 27/week @ 2022-10-20 59/week @ 2022-10-27 26/week @ 2022-11-03 28/week @ 2022-11-10 29/week @ 2022-11-17 62/week @ 2022-11-24 19/week @ 2022-12-01 44/week @ 2022-12-08 70/week @ 2022-12-15 31/week @ 2022-12-22 22/week @ 2022-12-29 25/week @ 2023-01-05 30/week @ 2023-01-12 46/week @ 2023-01-19 69/week @ 2023-01-26

170 downloads per month
Used in 2 crates

GPL-3.0-only…

3MB
56K SLoC

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 [ComponentCompiler] type, which you can use to create [ComponentDefinition] with the [ComponentCompiler::build_from_source] or [ComponentCompiler::build_from_path] functions.

Note about async functions

Compiling a component is async but in practice, this is only asynchronous if [ComponentCompiler::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, ComponentCompiler, ComponentHandle};

let mut compiler = ComponentCompiler::default();
let definition =
spin_on::spin_on(compiler.build_from_path("hello.slint"));
# #[cfg(feature="print_diagnostics")]
slint_interpreter::print_diagnostics(&compiler.diagnostics());
if let Some(definition) = definition {
let instance = definition.create();
instance.run();
}

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

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

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

let mut compiler = ComponentCompiler::default();
let definition =
spin_on::spin_on(compiler.build_from_source(code.into(), Default::default()));
assert!(compiler.diagnostics().is_empty());
let instance = definition.unwrap().create();
instance.set_property("my_name", Value::from(SharedString::from("World"))).unwrap();
# return; // we don't want to call run in the tests
instance.run();

Feature flags

Dependencies

~9–21MB
~429K SLoC