mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-03 15:14:35 +00:00
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:
parent
993caa1cd4
commit
b8a8abcdf9
1 changed files with 14 additions and 2 deletions
|
@ -45,6 +45,7 @@ Hello := Rectangle {
|
|||
signal foobar;
|
||||
signal plus_clicked;
|
||||
signal minus_clicked;
|
||||
property<int32> counter;
|
||||
|
||||
color: white;
|
||||
|
||||
|
@ -81,7 +82,7 @@ Hello := Rectangle {
|
|||
clicked => { plus_clicked() }
|
||||
button_text: "+";
|
||||
}
|
||||
counter := Text { x: 100; y: 300; text: "0"; color: black; }
|
||||
counter_label := Text { x: 100; y: 300; text: counter; color: black; }
|
||||
ButtonRectangle {
|
||||
color: 4289374890;
|
||||
x: 50;
|
||||
|
@ -95,5 +96,16 @@ Hello := Rectangle {
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue