-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathcounter.rs
35 lines (28 loc) · 1.05 KB
/
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
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License in the LICENSE-APACHE file or at:
// https://www.apache.org/licenses/LICENSE-2.0
//! Counter example (simple button)
use kas::prelude::*;
use kas::widgets::{column, format_value, row, Button};
#[derive(Clone, Debug)]
struct Increment(i32);
fn counter() -> impl Widget<Data = ()> {
let tree = column![
format_value!("{}").align(AlignHints::CENTER),
row![
Button::label_msg("−", Increment(-1)),
Button::label_msg("+", Increment(1)),
]
.map_any(),
];
tree.with_state(0)
.on_message(|_, count, Increment(add)| *count += add)
}
fn main() -> kas::runner::Result<()> {
env_logger::init();
let theme = kas::theme::SimpleTheme::new();
let mut app = kas::runner::Default::with_theme(theme).build(())?;
let _ = app.config_mut().font.set_size(24.0);
app.with(Window::new(counter(), "Counter")).run()
}