From 946684ad0d4db4fea9e4ec0dae73b41e0fd7f5e1 Mon Sep 17 00:00:00 2001 From: K V Varun Krishnan Date: Fri, 5 Jan 2024 23:19:46 +0530 Subject: [PATCH] Initialsing Slit --- .gitignore | 6 ++++++ .vscode/extensions.json | 7 +++++++ Cargo.toml | 14 ++++++++++++++ LICENSE | 21 +++++++++++++++++++++ README.md | 40 ++++++++++++++++++++++++++++++++++++++++ build.rs | 3 +++ src/main.rs | 13 +++++++++++++ ui/appwindow.slint | 17 +++++++++++++++++ 8 files changed, 121 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/extensions.json 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/appwindow.slint diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f2e972d --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# Generated by Cargo +# will have compiled files and executables +/target/ + +# These are backup files generated by rustfmt +**/*.rs.bk diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..8a69292 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "rust-lang.rust-analyzer", + "vadimcn.vscode-lldb", + "Slint.slint" + ] +} diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..ae15ace --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "{{project-name}}" +version = "0.1.0" +authors = ["{{authors}}"] +edition = "2021" +build = "build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +slint = "1.0" + +[build-dependencies] +slint-build = "1.0" 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..5a643d7 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +# 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 trigger react to callbacks, get and set properties and use basic widgets. + +## Usage + +1. Install Rust by following the [Rust 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. Install [`cargo-generate`](https://github.com/cargo-generate/cargo-generate) + ``` + cargo install cargo-generate + ``` +3. Set up a sample project with this template + ``` + cargo generate --git https://github.com/slint-ui/slint-rust-template --name my-project + cd my-project + ``` +3. Build with cargo + ``` + cargo build + ``` +4. 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 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 diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..0a2d8aa --- /dev/null +++ b/build.rs @@ -0,0 +1,3 @@ +fn main() { + slint_build::compile("ui/appwindow.slint").unwrap(); +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..4fa6b9f --- /dev/null +++ b/src/main.rs @@ -0,0 +1,13 @@ +slint::include_modules!(); + +fn main() -> Result<(), slint::PlatformError> { + let ui = AppWindow::new()?; + + let ui_handle = ui.as_weak(); + ui.on_request_increase_value(move || { + let ui = ui_handle.unwrap(); + ui.set_counter(ui.get_counter() + 1); + }); + + ui.run() +} diff --git a/ui/appwindow.slint b/ui/appwindow.slint new file mode 100644 index 0000000..7aba0c5 --- /dev/null +++ b/ui/appwindow.slint @@ -0,0 +1,17 @@ +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(); + } + } + } +}