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
use tuix::*;
use rand::prelude::*;
const STYLE: &str = r#"
"#;
#[derive(Debug, Clone, PartialEq)]
enum CustomEvent {
ChangeColor(Color),
}
#[derive(Default)]
struct Container {
color_picker: Entity,
}
impl Widget for Container {
type Ret = Entity;
type Data = ();
fn on_build(&mut self, state: &mut State, container: Entity) -> Self::Ret {
self.color_picker = ColorPicker::new()
.build(state, container, |builder| {
builder
});
container.set_background_color(state, Color::white())
}
// fn on_event(&mut self, state: &mut State, container: Entity, event: &mut Event) {
// if let Some(custom_event) = event.message.downcast() {
// match custom_event {
// CustomEvent::ChangeColor(color) => {
// container.set_background_color(state, *color);
// }
// }
// }
// }
}
fn main() {
let app = Application::new(
WindowDescription::new()
.with_title("Button")
.with_inner_size(300, 300),
|state, window| {
state.add_theme(STYLE);
Container::default().build(state, window, |builder| builder);
},
);
app.run();
}