-
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathcounter.rs
More file actions
36 lines (29 loc) · 1.08 KB
/
counter.rs
File metadata and controls
36 lines (29 loc) · 1.08 KB
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
36
// 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::{Button, column, format_label, row};
#[derive(Clone, Debug)]
struct Increment(i32);
fn counter() -> impl Widget<Data = ()> {
let tree = column![
format_label!("{}").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::Runner::with_theme(theme).build(())?;
let _ = app.config_mut().font.set_size(24.0);
let window = Window::new(counter(), "Counter").escapable();
app.with(window).run()
}