Crate slint_interpreter
source ·Expand description
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();
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#"
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();
instance.run();
Feature flags
-
compat-0-3-0
(enabled by default) — Mandatory feature: This feature is required to keep the compatibility with Slint 0.3.0 Newer patch version may put current functionality behind a new feature that would be enabled by default only if this feature was added -
display-diagnostics
— enable theprint_diagnostics
function to show diagnostic in the console output -
std
(enabled by default) — Enable use of the Rust standard library.
Backends
See the documentation of the slint
crate
-
backend-qt
(enabled by default) — The Qt backend feature uses Qt for the windowing system integration and rendering. This backend also provides thenative
style. It requires Qt 5.15 or later to be installed. If Qt is not installed, the backend will not be operational -
backend-winit
(enabled by default) — The winit crate is used for the event loop and windowing system integration. With this feature, both x11 and wayland windowing systems are supported. For a smaller build, omit this feature and select one of the other specificbackend-winit-XX
features. -
backend-winit-x11
— Simliar tobackend-winit
this enables the winit based event loop but only with support for the X Window System on Unix. -
backend-winit-wayland
— Simliar tobackend-winit
this enables the winit based event loop but only with support for the Wayland window system on Unix. -
renderer-winit-femtovg
(enabled by default) — Enable thewinit
backend and make it capable of renderer using the femtovg crate. -
renderer-winit-skia
— Enable thewinit
backend and make it capable of rendering using Skia -
renderer-winit-skia-opengl
— Same asrenderer-winit-skia
, but Skia will always use OpenGL. -
renderer-winit-software
— Enable thewinit
backend and make it capable of rendering using the software renderer
Macros
vtable::HasStaticVTable<ModelAdaptorVTable>
for it.Structs
to_
and from_
(a)rgb helper functions:[T]
..slint
.Enums
invoke_from_event_loop()
and quit_event_loop()
functionComponentInstance::get_property
ComponentInstance::invoke_callback
set_rendering_notifier
on the slint::Window
.ComponentInstance::set_callback
ComponentInstance::set_property
crate::Window
.Value
enum, without
the contained values.Window::set_position
.Window::set_size
.Traits
.slint
markup. Alternatively, you can use ComponentHandle::global
to obtain access.Functions
slint::run_event_loop()
will return.