| Table of contents |
|---|
| 1. Introduction |
| 2. Prerequisites |
| 3. Steps |
| 4. Optional |
As of writing, Slint documentation does not provide steps to setup your prject from scratch and instead have you download their templates. This document aims to address it and give you a quick start.
- Rust installed on your system
- Text editor of your choice
- Basic understanding of Rust language
-
Example:
cargo new --bin my_project
Replace
my_projectwith a name you desire.
-
Make sure you have the necessary dependencies in your
Cargo.tomlfile: -
Example (via CLI):
cargo add slint # Or add these features (see notes below) cargo add slint --features renderer-femtovg-wgpu,backend-winit cargo add slint-build --build- Notes:
- (Optional) The
renderer-femtovg-wgpufeature enables GPU acceleration using the femtovg renderer and wgpu backend. - (Optional) The
backend-winitfeature enables the winit backend for window management whichrenderer-femtovg-wgpuneeds aside from LinuxKMS backend. - For more information, see Backends and Renderers
- (Optional) The
- Notes:
-
The entry file is typically a
.slintfile that contains the main component/body of your application's main window UI. -
Example:
// ~/Projects/my_slint_app/ui/main_window.slint export component MainWindow inherits Window { // Take note of the component name `MainWindow` title: "Slint Samples"; width: 400px; height: 300px; Text { text: "Hello, World!"; } }
-
Then on your
main.rsfile, you can refer to the following code to run the application and render the UI you defined:// ~/Projects/my_slint_app/src/main.rs // Prevent console window in addition to Slint window in Windows release builds when, e.g., starting the app via file manager. Ignored on other platforms. #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] use std::error::Error; // This macro generates the necessary code to load and display the UI you just created slint::include_modules!(); fn main() -> Result<(), Box<dyn Error>> { // Create an instance of the MainWindow component from main_window.slint let ui = MainWindow::new()?; // Run the application and display the UI ui.run()?; Ok(()) }
-
-
In order for the compiler to know where to find the entry Slint file, you need to configure the
build.rsfile. -
Example:
// ~/Projects/my_slint_app/build.rs fn main() { // This compiles ths Slint files. You only need to specify the path to the entry slint file(s) (the main window file for example) slint_build::compile("ui/main_window.slint").expect("Slint build failed"); }
You might encounter a compile error with the message: error: failed to run custom build command for `yeslogic-fontconfig-sys v6.0.1`
In this case. You may need to install pkgconf and fontconfig as your system dependencies:
Debian/Ubuntu:
sudo apt install pkg-config libfontconfig1-devFedora/RHEL:
sudo dnf install pkgconf-pkg-config fontconfig-develArch Linux:
sudo pacman -S pkgconf fontconfigAfter installation, run cargo clean and then cargo run again.
cargo cleanensures your compile cache directory is clean and any potential corrupt files are removed, adding safety measure before your rerun ofcargo run.
Slint provides Material Design UI toolkit to help you build touch-friendly UI in your project. Refer to their Getting Started page to learn more.
Now, you should be able to run the application using cargo run. Initial compile time might be slow but after that, subsequent compiles are fast.
I also highly recommend reading the official Slint documentation for more information on how to use Slint and build your frontend with it.
If you encounter any issues from following this guide, feel free to reach out by creating a new Github issue.