Slint is a GUI toolkit to build native user interfaces for any device,
with JavaScript, Rust, C++, or Python.
Slint-node is the JavaScript and TypeScript API for Node.js, Deno, and Bun.
Describe your UI in the .slint language and connect it to your JavaScript code.
Slint renders the UI itself, so desktop and embedded Linux apps don't need a webview or a bundled Chromium.
To get started, follow the walk-through tutorial, or start from the Getting Started Template, a minimal app.
Warning: Beta Slint-node is still in the early stages of development: APIs will change and important features are still being developed.
The Slint Language Documentation covers the Slint UI description language in detail.
Published API docs for this binding live under slint.dev …/docs/node/. See docs/building.md and docs/nodejs/README.md.
Slint is available via NPM, so you can install by running the following command:
npm install slint-uiThis requires Node.js (v22.18 or newer). Pre-built binaries are included for Linux (x86-64 and ARM64, glibc), macOS (ARM64), and Windows (x86-64 and ARM64).
On platforms without pre-built binaries, build Slint-node from a checkout of this repository by running
pnpm install && pnpm build in api/node. You need to install the following components:
You will also need a few more dependencies, see https://github.com/slint-ui/slint/blob/master/docs/building.md#prerequisites
First, import the API from the slint-ui module. In the following examples we're using ECMAScript module syntax, but if you prefer you can also import the API using CommonJS syntax.
To initialize the API, you first need to import the slint-ui module in our code:
import * as slint from "slint-ui";Next, load a slint file with the loadFile function:
let ui = slint.loadFile(new URL("ui/main.slint", import.meta.url));Combining these two steps leads us to the obligatory "Hello World" example:
import * as slint from "slint-ui";
let ui = slint.loadFile(new URL("ui/main.slint", import.meta.url));
let main = new ui.Main();
main.run();For a full example, see /examples/todo/node.
The examples in this section use the following component:
ui/main.slint
export component MainWindow inherits Window {
callback clicked <=> i-touch-area.clicked;
in property <int> counter;
width: 400px;
height: 200px;
i-touch-area := TouchArea {}
}Each exported Window component is exposed as a type constructor. The type constructor takes as parameter
an object which allow to initialize the value of public properties or callbacks. A name declared with a
dash in .slint can be given either as declared ("my-property") or with underscores (my_property),
which is how it is exposed on the instance.
Place slint-project.json beside the imported .slint file to apply project settings such as library paths.
The import selects the source file. The project file's main entry is used when you load the project itself.
Import .slint files directly.
Load slint-ui/register before your own code:
node --import slint-ui/register app.mjs
deno run --preload npm:slint-ui/register app.ts
bun --preload slint-ui/register app.tsimport * as slint from "slint-ui";
import { MainWindow } from "./ui/main.slint";
let component = new MainWindow({
counter: 42,
clicked: function () {
console.log("hello");
},
});Alternatively, call loadFile() at runtime.
Use this for dynamic loading or to pass compiler options like style or includePaths:
import * as slint from "slint-ui";
let ui = slint.loadFile(new URL("ui/main.slint", import.meta.url));
let component = new ui.MainWindow({
counter: 42,
clicked: function () {
console.log("hello");
},
});Properties declared as out or in-out in .slint files are visible as JavaScript on the component instance.
component.counter = 42;
console.log(component.counter);Callbacks in Slint can be defined using the callback keyword and can be connected to a callback of an other component
using the <=> syntax.
ui/my-component.slint
export component MyComponent inherits Window {
callback clicked <=> i-touch-area.clicked;
width: 400px;
height: 200px;
i-touch-area := TouchArea {}
}The callbacks in Slint are exposed as properties in JavaScript and that can be called as a function.
main.js
import * as slint from "slint-ui";
let ui = slint.loadFile(new URL("ui/my-component.slint", import.meta.url));
let component = new ui.MyComponent();
// connect to a callback
component.clicked = function () {
console.log("hello");
};
// emit a callback
component.clicked();Functions in Slint can be defined using the function keyword.
ui/my-component.slint
export component MyComponent inherits Window {
width: 400px;
height: 200px;
public function my-function() -> int {
return 42;
}
}If the function is marked public, it can also be called from JavaScript.
main.js
import * as slint from "slint-ui";
let ui = slint.loadFile(new URL("ui/my-component.slint", import.meta.url));
let component = new ui.MyComponent();
// call a public function
let result = component.my_function();The types used for properties in .slint design markup each translate to specific types in JavaScript. The follow table summarizes the entire mapping:
.slint Type |
JavaScript Type | Notes |
|---|---|---|
int |
Number |
|
float |
Number |
|
string |
String |
|
color |
RgbaColor |
|
brush |
Brush |
|
image |
ImageData |
|
data-transfer |
DataTransfer |
Drag-and-drop and clipboard payload; usually obtained from a callback parameter. See Drag and Drop. |
length |
Number |
|
physical_length |
Number |
|
duration |
Number |
The number of milliseconds |
angle |
Number |
The angle in degrees |
| structure | Object |
Structures are mapped to JavaScript objects where each structure field is a property. |
| array | Array or any implementation of Model |
|
styled-text |
StyledText |
Use StyledText.fromMarkdown() or StyledText.fromPlainText() to create. |
| enumeration | String |
The value of an enum |
For property of array type, they can either be set using an array. In that case, getting the property also return an array. If the array was set within the .slint file, the array can be obtained
component.model = [1, 2, 3];
// component.model.push(4); // does not work, because it operate on a copy
// but re-assigning works
component.model = component.model.concat(4);Another option is to set a model object. A model object has the following function:
rowCount(): returns the number of element in the model.rowData(index): return the row at the given indexsetRowData(index, data): called when the model need to be changed.this.notify.rowDataChangedmust be called if successful.
As an example, here is the implementation of the ArrayModel (which is available as slint.ArrayModel)
import * as slint from "slint-ui";
let array = [1, 2, 3];
export class ArrayModel<T> extends slint.Model<T> {
private a: Array<T>
constructor(arr: Array<T>) {
super();
this.a = arr;
}
rowCount() {
return this.a.length;
}
rowData(row: number) {
return this.a[row];
}
setRowData(row: number, data: T) {
this.a[row] = data;
this.notify.rowDataChanged(row);
}
push(...values: T[]) {
let size = this.a.length;
Array.prototype.push.apply(this.a, values);
this.notify.rowAdded(size, arguments.length);
}
remove(index: number, size: number) {
let r = this.a.splice(index, size);
this.notify.rowRemoved(index, size);
}
get length(): number {
return this.a.length;
}
values(): IterableIterator<T> {
return this.a.values();
}
entries(): IterableIterator<[number, T]> {
return this.a.entries()
}
}
let model = new ArrayModel(array);
component.model = model;
model.push(4); // this works
// does NOT work, getting the model does not return the right object
// component.model.push(5);An exported struct can be created either by defining an object literal or by using the new keyword.
my-component.slint
export struct Person {
name: string,
age: int
}
export component MyComponent inherits Window {
in-out property <Person> person;
}main.js
import * as slint from "slint-ui";
let ui = slint.loadFile(new URL("my-component.slint", import.meta.url));
let component = new ui.MyComponent();
// object literal
component.person = { name: "Peter", age: 22 };
// new keyword (sets property values to default e.g. '' for string)
component.person = new ui.Person();
// new keyword with parameters
component.person = new ui.Person({ name: "Tim", age: 30 });A value of an exported enum can be set as string or by using the value from the exported enum.
my-component.slint
export enum Position {
top,
bottom
}
export component MyComponent inherits Window {
in-out property <Position> position;
}main.js
import * as slint from "slint-ui";
let ui = slint.loadFile(new URL("my-component.slint", import.meta.url));
let component = new ui.MyComponent();
// set enum value as string
component.position = "top";
// use the value of the enum
component.position = ui.Position.bottom;Slint is open source and available under three licenses: you pick the one that fits your app.
- If your app is open source, use the GNU GPLv3, a widely used, OSI-approved open-source license. It covers any platform, including embedded devices.
- If your app is closed source and runs on desktop, mobile, or the web,
use the Royalty-free License.
It's free of charge, and only asks you to credit Slint, with the
AboutSlintwidget or the Slint badge on your website. - If your app is closed source and runs on an embedded device, buy a commercial license. See the pricing.
Your own code can stay under a permissive license such as MIT or Apache-2.0. Anyone who forks it chooses their own Slint license, so they can reuse it in a closed-source app. The Licensing FAQ covers the details.