From 8cec608e21c5e6e251415af4072261cfca998ddd Mon Sep 17 00:00:00 2001 From: 2ndbeam <2ndbeam@disroot.org> Date: Wed, 3 Sep 2025 20:43:19 +0300 Subject: [PATCH] Initial commit --- .cargo/config.toml | 12 ++++++++++++ .gitignore | 11 +++++++++++ Cargo.toml | 12 ++++++++++++ LICENSE | 21 +++++++++++++++++++++ README.md | 38 ++++++++++++++++++++++++++++++++++++++ build.rs | 3 +++ src/main.rs | 22 ++++++++++++++++++++++ ui/app-window.slint | 18 ++++++++++++++++++ 8 files changed, 137 insertions(+) create mode 100644 .cargo/config.toml create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 build.rs create mode 100644 src/main.rs create mode 100644 ui/app-window.slint diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..c971371 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,12 @@ +[target.x86_64-pc-windows-msvc] +# Increase default stack size to avoid running out of stack +# space in debug builds. The size matches Linux's default. +rustflags = [ + "-C", "link-arg=/STACK:8000000" +] +[target.aarch64-pc-windows-msvc] +# Increase default stack size to avoid running out of stack +# space in debug builds. The size matches Linux's default. +rustflags = [ + "-C", "link-arg=/STACK:8000000" +] diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..91e558f --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# Generated by Cargo +# will have compiled files and executables +/target/ + +# Alternative VCS systems +/.jj/ +/.hg/ +/.pijul/ + +# These are backup files generated by rustfmt +**/*.rs.bk diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..a69b766 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "aliveline" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +slint = "1.12.1" + +[build-dependencies] +slint-build = "1.12.1" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..242da62 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..3a77de6 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# Slint Rust Template + +A template for a Rust application that's using [Slint](https://slint.rs/) for the user interface. + +## About + +This template helps you get started developing a Rust application with Slint as toolkit +for the user interface. It demonstrates the integration between the `.slint` UI markup and +Rust code, how to react to callbacks, get and set properties, and use basic widgets. + +## Usage + +1. Install Rust by following its [getting-started guide](https://www.rust-lang.org/learn/get-started). + Once this is done, you should have the `rustc` compiler and the `cargo` build system installed in your `PATH`. +2. Download and extract the [ZIP archive of this repository](https://github.com/slint-ui/slint-rust-template/archive/refs/heads/main.zip). +3. Rename the extracted directory and change into it: + ``` + mv slint-rust-template-main my-project + cd my-project + ``` +4. Build with `cargo`: + ``` + cargo build + ``` +5. Run the application binary: + ``` + cargo run + ``` + +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). + +## Next Steps + +We hope that this template helps you get started, and that you enjoy exploring making user interfaces with Slint. To learn more +about the Slint APIs and the `.slint` markup language, check out our [online documentation](https://slint.dev/docs). + +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 +project. diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..9bc3037 --- /dev/null +++ b/build.rs @@ -0,0 +1,3 @@ +fn main() { + slint_build::compile("ui/app-window.slint").expect("Slint build failed"); +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..d065a6d --- /dev/null +++ b/src/main.rs @@ -0,0 +1,22 @@ +// 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; + +slint::include_modules!(); + +fn main() -> Result<(), Box> { + let ui = AppWindow::new()?; + + ui.on_request_increase_value({ + let ui_handle = ui.as_weak(); + move || { + let ui = ui_handle.unwrap(); + ui.set_counter(ui.get_counter() + 1); + } + }); + + ui.run()?; + + Ok(()) +} diff --git a/ui/app-window.slint b/ui/app-window.slint new file mode 100644 index 0000000..2d5522c --- /dev/null +++ b/ui/app-window.slint @@ -0,0 +1,18 @@ +import { Button, VerticalBox } from "std-widgets.slint"; + +export component AppWindow inherits Window { + in-out property counter: 42; + callback request-increase-value(); + VerticalBox { + Text { + text: "Counter: \{root.counter}"; + } + + Button { + text: "Increase value"; + clicked => { + root.request-increase-value(); + } + } + } +}