├── .gitignore ├── .vscode ├── extensions.json └── settings.json ├── Cargo.toml ├── LICENSE ├── README.md ├── build.rs ├── src └── main.rs └── ui └── app-window.slint /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | 5 | # Alternative VCS systems 6 | /.jj/ 7 | /.hg/ 8 | /.pijul/ 9 | 10 | # These are backup files generated by rustfmt 11 | **/*.rs.bk 12 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "rust-lang.rust-analyzer", 4 | "vadimcn.vscode-lldb", 5 | "Slint.slint" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "[rust]": { 3 | "editor.defaultFormatter": "rust-lang.rust-analyzer" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "slint-rust-template" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | slint = "1.8.0" 10 | 11 | [build-dependencies] 12 | slint-build = "1.8.0" 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Slint Rust Template 2 | 3 | A template for a Rust application that's using [Slint](https://slint.rs/) for the user interface. 4 | 5 | ## About 6 | 7 | This template helps you get started developing a Rust application with Slint as toolkit 8 | for the user interface. It demonstrates the integration between the `.slint` UI markup and 9 | Rust code, how to react to callbacks, get and set properties, and use basic widgets. 10 | 11 | ## Usage 12 | 13 | 1. Install Rust by following its [getting-started guide](https://www.rust-lang.org/learn/get-started). 14 | Once this is done, you should have the `rustc` compiler and the `cargo` build system installed in your `PATH`. 15 | 2. Download and extract the [ZIP archive of this repository](https://github.com/slint-ui/slint-rust-template/archive/refs/heads/main.zip). 16 | 3. Rename the extracted directory and change into it: 17 | ``` 18 | mv slint-rust-template-main my-project 19 | cd my-project 20 | ``` 21 | 4. Build with `cargo`: 22 | ``` 23 | cargo build 24 | ``` 25 | 5. Run the application binary: 26 | ``` 27 | cargo run 28 | ``` 29 | 30 | We recommend using an IDE for development, along with our [LSP-based IDE integration for `.slint` files](https://github.com/slint-ui/slint/blob/master/tools/lsp/README.md). You can also load this project directly in [Visual Studio Code](https://code.visualstudio.com) and install our [Slint extension](https://marketplace.visualstudio.com/items?itemName=Slint.slint). 31 | 32 | ## Next Steps 33 | 34 | We hope that this template helps you get started, and that you enjoy exploring making user interfaces with Slint. To learn more 35 | about the Slint APIs and the `.slint` markup language, check out our [online documentation](https://slint.dev/docs). 36 | 37 | Don't forget to edit this readme to replace it by yours, and edit the `name =` field in `Cargo.toml` to match the name of your 38 | project. 39 | -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | slint_build::compile("ui/app-window.slint").expect("Slint build failed"); 3 | } 4 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | // 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. 2 | #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] 3 | 4 | use std::error::Error; 5 | 6 | slint::include_modules!(); 7 | 8 | fn main() -> Result<(), Box> { 9 | let ui = AppWindow::new()?; 10 | 11 | ui.on_request_increase_value({ 12 | let ui_handle = ui.as_weak(); 13 | move || { 14 | let ui = ui_handle.unwrap(); 15 | ui.set_counter(ui.get_counter() + 1); 16 | } 17 | }); 18 | 19 | ui.run()?; 20 | 21 | Ok(()) 22 | } 23 | -------------------------------------------------------------------------------- /ui/app-window.slint: -------------------------------------------------------------------------------- 1 | import { Button, VerticalBox } from "std-widgets.slint"; 2 | 3 | export component AppWindow inherits Window { 4 | in-out property counter: 42; 5 | callback request-increase-value(); 6 | VerticalBox { 7 | Text { 8 | text: "Counter: \{root.counter}"; 9 | } 10 | 11 | Button { 12 | text: "Increase value"; 13 | clicked => { 14 | root.request-increase-value(); 15 | } 16 | } 17 | } 18 | } 19 | --------------------------------------------------------------------------------