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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use crate::section::*;
use crate::component::*;
use crate::span::*;
pub enum Alignment {
Left,
Right,
Top,
Bottom,
}
pub enum Content {
Section {
section: SectionRef,
},
Span {
span: SpanRef,
}
}
impl Content {
pub fn on_resize(&mut self, left: f64, top: f64, right: f64, bottom: f64) -> (f64, f64, bool) {
match self {
Content::Section { ref section } => {
let mut section = section.borrow_mut();
section.on_resize(left, top, right, bottom)
},
Content::Span { ref span } => {
let mut span = span.borrow_mut();
let span = span.as_mut();
span.on_resize(left, top, right, bottom);
(0., 0., true)
}
}
}
pub fn draw(&self, ctx: &web_sys::CanvasRenderingContext2d) {
match self {
Content::Section { ref section } => {
let section = section.borrow();
section.draw(ctx);
},
Content::Span { ref span } => {
let span = span.borrow();
span.draw(ctx);
}
}
}
pub fn render_tick(&self, ctx: &web_sys::CanvasRenderingContext2d) {
match self {
Content::Section { ref section } => {
let section = section.borrow();
section.render_tick(ctx);
},
Content::Span { ref span } => {
let span = span.borrow();
span.render_tick(ctx);
}
}
}
pub fn tick(&mut self) {
match self {
Content::Section { ref mut section } => {
let mut section = section.borrow_mut();
section.tick();
},
Content::Span { ref mut span } => {
let mut span = span.borrow_mut();
span.tick();
}
}
}
pub fn get_order_value(&self) -> u8 {
match self {
Content::Section { ref section } => {
section.borrow().order
},
Content::Span { ref span } => {
span.borrow().get_order()
}
}
}
pub fn dispatch_event(&mut self, ev: &mut Event) {
match self {
Content::Section { ref section } => {
let mut section = section.borrow_mut();
section.dispatch_event(ev);
},
Content::Span { ref span } => {
let mut span = span.borrow_mut();
let span = span.as_mut();
span.dispatch_event(ev);
}
}
}
}