Hello Slint

This commit is contained in:
jaby 2025-01-22 18:41:40 +00:00
parent 89c81798b4
commit 9549d011b8
4 changed files with 48 additions and 3 deletions

View File

@ -7,3 +7,7 @@ edition = "2021"
panic = "abort" panic = "abort"
[dependencies] [dependencies]
slint = "1.9.2"
[build-dependencies]
slint-build = "1.9.2"

View File

@ -0,0 +1,3 @@
fn main() {
slint_build::compile("ui/app-window.slint").expect("Slint build failed");
}

View File

@ -1,3 +1,22 @@
fn main() { // 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.
tim_tool::hello_world(); #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
}
use std::error::Error;
slint::include_modules!();
fn main() -> Result<(), Box<dyn Error>> {
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(())
}

View File

@ -0,0 +1,19 @@
import { Button, VerticalBox } from "std-widgets.slint";
export component AppWindow inherits Window {
in-out property <int> counter: 42;
callback request-increase-value();
VerticalBox {
Text {
text: "Counter: \{root.counter}";
}
Button {
checked: false;
text: "Increase value";
clicked => {
root.request-increase-value();
}
}
}
}