init from a Window should work like "onload" event? #2761
-
Hey everyone, I'm new to Slint, and I'm using the following:
import {
Button,
HorizontalBox,
VerticalBox,
AboutSlint
} from "std-widgets.slint";
export component AppWindow inherits Window {
in-out property<int> counter: 42;
in-out property<string> vendor;
callback request-increase-value();
callback request-vendor-name();
init => {
root.request-vendor-name();
}
VerticalBox {
AboutSlint {
}
Text {
horizontal-alignment: center;
text: "openGL: \{root.vendor}";
}
Text {
horizontal-alignment: center;
text: "Counter: \{root.counter}";
}
HorizontalBox {
alignment: center;
Button {
text: "Increase value";
clicked => {
root.request-increase-value();
}
}
}
}
}
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);
});
let ui_handle = ui.as_weak();
ui.on_request_vendor_name(move || {
let ui = ui_handle.unwrap();
ui.set_vendor("Test".into());
});
ui.run()
} But the code from |
Beta Was this translation helpful? Give feedback.
Answered by
tronical
May 20, 2023
Replies: 1 comment
-
Hi! The |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
microhobby
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! The
init
callback is invoked when the Window is constructed, so that's before your call toon_request_vendor_name
. In this case you don't really need init, you can just set the vendor property directly.