-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcounter.rs
35 lines (28 loc) · 880 Bytes
/
counter.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use narui::*;
#[widget]
pub fn counter(#[default] initial_value: i32, context: &mut WidgetContext) -> Fragment {
let count = context.listenable(initial_value);
let value = context.listen(count);
rsx! {
<row>
<button on_click=move |context: &CallbackContext| context.shout(count, context.spy(count) - 1)>
<text>{" - "}</text>
</button>
<padding>
<text>{format!("{}", value)}</text>
</padding>
<button on_click=move |context: &CallbackContext| context.shout(count, context.spy(count) + 1)>
<text>{" + "}</text>
</button>
</row>
}
}
fn main() {
env_logger::init();
app::render(
app::WindowBuilder::new().with_title("narui counter demo"),
rsx_toplevel! {
<counter />
},
);
}