Skip to content

What is Slint

Raxorin Studio’s windows are built with Slint, a graphical interface library for Rust. It works like WPF or XAML: the interface goes in a .slint file and what it does goes in Rust.

  • Directorymy_window/
    • build.rs compiles the interface together with the program
    • Cargo.toml uses the slint and slint-build packages
    • Directorysrc/
      • main.rs the code (like WPF’s code-behind)
    • Directoryui/
      • app-window.slint the window

The .slint file can be edited in two ways, and both are always in sync:

  • Design: the visual designer, dragging controls and changing properties in the panel.
  • Code: the file’s text, with completions and colors.
ui/app-window.slint
import { Button, VerticalBox } from "std-widgets.slint";
export component AppWindow inherits Window {
title: "Counter";
width: 300px;
height: 160px;
in-out property <int> count: 0;
VerticalBox {
Text {
text: "You've clicked \{root.count} times";
font-size: 18px;
horizontal-alignment: center;
}
Button {
text: "Add";
clicked => {
root.count += 1;
}
}
}
}
src/main.rs
slint::include_modules!();
fn main() -> Result<(), slint::PlatformError> {
let ui = AppWindow::new()?;
ui.run()
}

This program already works: the button adds by itself, without Rust code. Line by line:

In the file What it is
import { Button, VerticalBox } from "std-widgets.slint"; The standard library controls it uses. The designer adds the imports by itself.
export component AppWindow inherits Window The window. export makes it visible from Rust as AppWindow.
title: "Counter"; A property with its value.
in-out property <int> count: 0; A property of its own, of type integer, that can also be read and changed from Rust.
VerticalBox { … } An element inside another: a column that arranges its children.
"…\{root.count}…" A text with a value inside. It updates by itself when count changes.
clicked => { … } An event: what happens on click.

An element can have a name, with :=, to use it from other elements and from Rust:

greeting := Text { text: "Hello"; }
Button { clicked => { greeting.text = "Goodbye!"; } }

In the designer, the name is the field at the top of the properties panel. To connect events or use a control from Rust it needs a name.

Type Examples
length 12px, 50% (of the parent), parent.width - 20px
int, float 3, 0.5
string "Hello", "Total: \{root.total}"
bool true, false
color / brush #ff641c, #00000080 (with transparency), red, @linear-gradient(90deg, #ff9a00, #791bff)
duration 250ms, 1s
image @image-url("icons/star.svg") (relative to the .slint file)

Next: Connecting to Rust.