27 releases (15 stable)

1.5.1 Mar 20, 2024
1.4.1 Feb 2, 2024
1.3.2 Dec 1, 2023
1.3.1 Nov 28, 2023
0.2.1 Mar 10, 2022

#525 in GUI

Download history 43/week @ 2023-12-22 24/week @ 2023-12-29 73/week @ 2024-01-05 127/week @ 2024-01-12 105/week @ 2024-01-19 117/week @ 2024-01-26 155/week @ 2024-02-02 60/week @ 2024-02-09 76/week @ 2024-02-16 80/week @ 2024-02-23 61/week @ 2024-03-01 240/week @ 2024-03-08 610/week @ 2024-03-15 119/week @ 2024-03-22 102/week @ 2024-03-29 37/week @ 2024-04-05

1,008 downloads per month
Used in 2 crates

GPL-3.0-only…

3.5MB
70K 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"));
slint_interpreter::print_diagnostics(&compiler.diagnostics());
if let Some(definition) = definition {
let instance = definition.create().unwrap();
instance.run().unwrap();
}

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

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

let code = r#"
export component MyWin inherits Window {
in 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().unwrap();
instance.set_property("my_name", Value::from(SharedString::from("World"))).unwrap();
instance.run().unwrap();

Feature flags

Dependencies

~7–53MB
~850K SLoC