Make the plus minus use-case work with the Rust frontend

Initialize the counter label from a property that we modify in signals handlers
from Rust code.
This commit is contained in:
Simon Hausmann 2020-05-28 15:20:09 +02:00
parent 993caa1cd4
commit b8a8abcdf9

View file

@ -45,6 +45,7 @@ Hello := Rectangle {
signal foobar; signal foobar;
signal plus_clicked; signal plus_clicked;
signal minus_clicked; signal minus_clicked;
property<int32> counter;
color: white; color: white;
@ -81,7 +82,7 @@ Hello := Rectangle {
clicked => { plus_clicked() } clicked => { plus_clicked() }
button_text: "+"; button_text: "+";
} }
counter := Text { x: 100; y: 300; text: "0"; color: black; } counter_label := Text { x: 100; y: 300; text: counter; color: black; }
ButtonRectangle { ButtonRectangle {
color: 4289374890; color: 4289374890;
x: 50; x: 50;
@ -95,5 +96,16 @@ Hello := Rectangle {
} }
fn main() { fn main() {
Hello::default().run(); let mut app = Hello::default();
app.plus_clicked.set_handler(|context, ()| {
let app = context.component.downcast::<Hello>().unwrap();
app.counter.set(app.counter.get(context) + 1);
});
app.minus_clicked.set_handler(|context, ()| {
let app = context.component.downcast::<Hello>().unwrap();
app.counter.set(app.counter.get(context) - 1);
});
app.run();
} }