Rust: add on_* to set signal handler

This commit is contained in:
Olivier Goffart 2020-08-03 13:26:43 +02:00
parent b2a1a72450
commit 8aef208340
3 changed files with 18 additions and 13 deletions

View file

@ -144,16 +144,14 @@ Hello := Rectangle {
fn main() {
let app = Hello::new();
let app_weak = sixtyfps::re_exports::PinWeak::downgrade(app.clone());
app.plus_clicked.set_handler(move |()| {
app.as_ref().on_plus_clicked(move || {
let app = app_weak.upgrade().unwrap();
let counter = Hello::field_offsets().counter.apply_pin(app.as_ref());
counter.set(counter.get() + 1);
app.as_ref().set_counter(app.as_ref().get_counter() + 1);
});
let app_weak = sixtyfps::re_exports::PinWeak::downgrade(app.clone());
app.minus_clicked.set_handler(move |()| {
app.as_ref().on_minus_clicked(move || {
let app = app_weak.upgrade().unwrap();
let counter = Hello::field_offsets().counter.apply_pin(app.as_ref());
counter.set(counter.get() - 1);
app.as_ref().set_counter(app.as_ref().get_counter() - 1);
});
app.run();
}