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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use crate::{Entity, Event, PropSet, State, Widget, WindowEvent, apply_hover};
use crate::systems::{apply_styles, apply_visibility, apply_z_ordering, apply_transform};
use crate::layout::geometry_changed;
#[derive(Clone)]
pub struct WindowWidget {}
impl WindowWidget {
pub fn new() -> Self {
WindowWidget {}
}
pub fn build_window(self, state: &mut State) {
state.build(Entity::root(), self);
}
}
impl Widget for WindowWidget {
type Ret = Entity;
type Data = ();
fn on_build(&mut self, state: &mut State, entity: Entity) -> Self::Ret {
entity
}
fn on_event(&mut self, state: &mut State, _entity: Entity, event: &mut Event) {
if let Some(window_event) = event.message.downcast::<WindowEvent>() {
match window_event {
WindowEvent::WindowClose => {
println!("Window Close Event");
}
WindowEvent::Debug(val) => {
println!("{}", val);
}
WindowEvent::Restyle => {
let tree = state.tree.clone();
apply_styles(state, &tree);
}
WindowEvent::Relayout => {
let tree = state.tree.clone();
state.needs_redraw = true;
apply_z_ordering(state, &tree);
apply_visibility(state, &tree);
morphorm::layout(&mut state.data, &state.tree, &mut state.style);
apply_transform(state, &tree);
geometry_changed(state, &tree);
apply_hover(state);
}
WindowEvent::Redraw => {
let tree = state.tree.clone();
apply_transform(state, &tree);
state.needs_redraw = true;
}
_ => {}
}
}
}
}