slint-dotnet
slint-dotnet copied to clipboard
SlintDotnet is a C# bindings project to enable developers to use Slint UI with .NET C#
SlintDotnet (Alpha)
Slint is a UI toolkit that supports different programming languages. SlintDotnet is the integration with .NET C#.
⚠️ This is experimental and not ready for production use! SlintDotnet is still in the early stages of development: APIs will change and important features are still being developed.
Installing Slint
Slint is available via Nuget package:
dotnet add package SlintDotnet
Dependencies
You need to install the following components:
- Supported only on Linux (for now):
- x64
- arm
- arm64
- .NET 6.0 SDK for Linux
- fontconfig library (libfontconfig-dev on debian based distributions)
Using SlintDotnet
There are a ready to use template from the VS Code Torizon Templates.
API Overview
To have access to the Slint classes the following using statement is needed:
using Slint;
Window Component
The window component from the .slint file is mapped to the Window class. To have access to the Window class is need to add the using statement to the namespace that is the same name of the .slint file. For example: if the .slint file is named MyWindow.slint:
using MyWindow;
Then the Window class can be instantiated and used:
var window = new Window();
window.run();
Accessing a property
Properties are exposed as properties on the instance of the Window:
window.counter = 42;
⚠️
structproperties are accessed as properties on the instance of theWindow
Callbacks
The callbacks are also exposed as Action properties on the instance of the Window:
window.RequestIncreaseValue = () => {
window.counter++;
};
⚠️ The keywords from the
.slintfile are converted to pascal case.
⚠️ Only
void(void)callbacks are supported for now.
Changing UI from Different Threads
The UI can only be changed from the UI thread, a panic will be triggered if you try to change the UI from a different thread. To change the UI from a different thread use:
window.RunOnUiThread(() => {
window.counter++;
});
This will move the action to the Slint upgrade_in_event_loop to be executed in the UI thread.
⚠️
Window.RunOnUiThreadcan only be called after theWindow.Runmethod. An exception will be thrown if called before.
Type Mappings
.slint Type |
C# Type | Notes |
|---|---|---|
int |
Float |
|
float |
Float |
|
string |
String |
|
bool |
bool |
|
image |
Slint.Image |
|
Timer |
Slint.Timer |
|
color |
❌ | |
length |
Float |
|
physical_length |
❌ | |
duration |
❌ | |
angle |
❌ | |
struct |
object |
|
array |
❌ |