diff --git a/src/Tools/tim_tool/Cargo.toml b/src/Tools/tim_tool/Cargo.toml index 4db563ea..c695b90c 100644 --- a/src/Tools/tim_tool/Cargo.toml +++ b/src/Tools/tim_tool/Cargo.toml @@ -7,3 +7,7 @@ edition = "2021" panic = "abort" [dependencies] +slint = "1.9.2" + +[build-dependencies] +slint-build = "1.9.2" diff --git a/src/Tools/tim_tool/build.rs b/src/Tools/tim_tool/build.rs new file mode 100644 index 00000000..9bc30378 --- /dev/null +++ b/src/Tools/tim_tool/build.rs @@ -0,0 +1,3 @@ +fn main() { + slint_build::compile("ui/app-window.slint").expect("Slint build failed"); +} diff --git a/src/Tools/tim_tool/src/main.rs b/src/Tools/tim_tool/src/main.rs index 41bf1c4d..d065a6de 100644 --- a/src/Tools/tim_tool/src/main.rs +++ b/src/Tools/tim_tool/src/main.rs @@ -1,3 +1,22 @@ -fn main() { - tim_tool::hello_world(); -} \ No newline at end of file +// 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/src/Tools/tim_tool/ui/app-window.slint b/src/Tools/tim_tool/ui/app-window.slint new file mode 100644 index 00000000..a2cb9238 --- /dev/null +++ b/src/Tools/tim_tool/ui/app-window.slint @@ -0,0 +1,19 @@ +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 { + checked: false; + text: "Increase value"; + clicked => { + root.request-increase-value(); + } + } + } +}