mirror of
https://github.com/allankoechke/slint-rust-template.git
synced 2026-11-29 09:33:22 +00:00
Rewrite callback in a more future-proof and hackable way
This might be someone's first time dealing with callbacks and the dance you have to do in Rust Slint code with weak handles. While the previous code worked, if you try to expand the callback with multiple arguments it quickly devolves into an unsolvable whack-a-mole game of confusing compiler errors. What other examples do and what actually scales is turning it into a weak handle outside of the callback closure and having the top-level closure move everything.
This commit is contained in:
committed by
Olivier Goffart
parent
d66f1cc74b
commit
0ce0692fe5
10
src/main.rs
10
src/main.rs
@@ -8,12 +8,10 @@ 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);
|
||||
}
|
||||
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()?;
|
||||
|
||||
Reference in New Issue
Block a user