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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#![windows_subsystem = "windows"]
use druid::widget::prelude::*;
use druid::widget::{Button, Label, ZStack};
use druid::{AppLauncher, Data, Lens, UnitPoint, Vec2, WindowDesc};
#[derive(Clone, Data, Lens)]
struct State {
counter: usize,
}
pub fn main() {
let main_window = WindowDesc::new(build_root_widget())
.title("Hello World!")
.window_size((400.0, 400.0));
let initial_state: State = State { counter: 0 };
AppLauncher::with_window(main_window)
.log_to_console()
.launch(initial_state)
.expect("Failed to launch application");
}
fn build_root_widget() -> impl Widget<State> {
ZStack::new(
Button::from_label(Label::dynamic(|state: &State, _| {
format!(
"Very large button with text! Count up (currently {})",
state.counter
)
}))
.on_click(|_, state: &mut State, _| state.counter += 1),
)
.with_child(
Button::new("Reset").on_click(|_, state: &mut State, _| state.counter = 0),
Vec2::new(1.0, 1.0),
Vec2::ZERO,
UnitPoint::LEFT,
Vec2::new(10.0, 0.0),
)
}