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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
use super::bounds::*;
use super::control::*;
use super::actions::*;
use super::font_attr::*;
use super::state_attr::*;
use super::popup_attr::*;
use super::scroll_attr::*;
use super::appearance_attr::*;
use super::super::property::*;
use super::super::binding_canvas::*;
use super::super::resource_manager::*;
use modifier::*;
#[derive(Clone, PartialEq, Debug)]
pub enum ControlAttribute {
BoundingBox(Bounds),
ZIndex(u32),
Padding((u32, u32), (u32, u32)),
Text(Property),
FontAttr(Font),
StateAttr(State),
PopupAttr(Popup),
AppearanceAttr(Appearance),
ScrollAttr(Scroll),
Id(String),
SubComponents(Vec<Control>),
Controller(String),
Action(ActionTrigger, String),
Canvas(Resource<BindingCanvas>)
}
impl ControlAttribute {
pub fn bounding_box<'a>(&'a self) -> Option<&'a Bounds> {
match self {
&BoundingBox(ref bounds) => Some(bounds),
_ => None
}
}
pub fn z_index(&self) -> Option<u32> {
match self {
&ZIndex(zindex) => Some(zindex),
_ => None
}
}
pub fn padding(&self) -> Option<((u32, u32), (u32, u32))> {
match self {
&Padding(left_top, right_bottom) => Some((left_top, right_bottom)),
_ => None
}
}
pub fn text<'a>(&'a self) -> Option<&'a Property> {
match self {
&Text(ref text) => Some(text),
_ => None
}
}
pub fn font<'a>(&'a self) -> Option<&'a Font> {
match self {
&FontAttr(ref attr) => Some(attr),
_ => None
}
}
pub fn id<'a>(&'a self) -> Option<&'a String> {
match self {
&Id(ref id) => Some(id),
_ => None
}
}
pub fn subcomponents<'a>(&'a self) -> Option<&'a Vec<Control>> {
match self {
&SubComponents(ref components) => Some(components),
_ => None
}
}
pub fn controller<'a>(&'a self) -> Option<&'a str> {
match self {
&Controller(ref controller) => Some(controller),
_ => None
}
}
pub fn action<'a>(&'a self) -> Option<(&'a ActionTrigger, &'a String)> {
match self {
&Action(ref trigger, ref action) => Some((trigger, action)),
_ => None
}
}
pub fn state<'a>(&'a self) -> Option<&'a State> {
match self {
&StateAttr(ref state) => Some(state),
_ => None
}
}
pub fn popup<'a>(&'a self) -> Option<&'a Popup> {
match self {
&PopupAttr(ref popup) => Some(popup),
_ => None
}
}
pub fn canvas<'a>(&'a self) -> Option<&'a Resource<BindingCanvas>> {
match self {
&Canvas(ref canvas) => Some(canvas),
_ => None
}
}
pub fn appearance<'a>(&'a self) -> Option<&'a Appearance> {
match self {
&AppearanceAttr(ref appearance) => Some(appearance),
_ => None
}
}
pub fn scroll<'a>(&'a self) -> Option<&'a Scroll> {
match self {
&ScrollAttr(ref scroll) => Some(scroll),
_ => None
}
}
pub fn is_different_flat(&self, compare_to: &ControlAttribute) -> bool {
match self {
&BoundingBox(ref bounds) => Some(bounds) != compare_to.bounding_box(),
&ZIndex(zindex) => Some(zindex) != compare_to.z_index(),
&Padding(lt, rb) => Some((lt, rb)) != compare_to.padding(),
&Text(ref text) => Some(text) != compare_to.text(),
&FontAttr(ref font) => Some(font) != compare_to.font(),
&Id(ref id) => Some(id) != compare_to.id(),
&Controller(ref controller) => Some(controller.as_ref()) != compare_to.controller(),
&Action(ref trigger, ref action) => Some((trigger, action)) != compare_to.action(),
&StateAttr(ref state) => Some(state) != compare_to.state(),
&PopupAttr(ref popup) => Some(popup) != compare_to.popup(),
&Canvas(ref canvas_resource) => Some(canvas_resource) != compare_to.canvas(),
&AppearanceAttr(ref appearance) => Some(appearance) != compare_to.appearance(),
&ScrollAttr(ref scroll) => Some(scroll) != compare_to.scroll(),
&SubComponents(ref components) => Some(components.len()) != compare_to.subcomponents().map(|components| components.len())
}
}
}
use ControlAttribute::*;
impl<'a> Modifier<Control> for &'a str {
fn modify(self, control: &mut Control) {
control.add_attribute(Text(self.to_property()))
}
}
impl Modifier<Control> for String {
fn modify(self, control: &mut Control) {
control.add_attribute(Text(self.to_property()))
}
}
impl<'a> Modifier<Control> for &'a String {
fn modify(self, control: &mut Control) {
control.add_attribute(Text(self.to_property()))
}
}
impl Modifier<Control> for Bounds {
fn modify(self, control: &mut Control) {
control.add_attribute(BoundingBox(self))
}
}
impl Modifier<Control> for Resource<BindingCanvas> {
fn modify(self, control: &mut Control) {
control.add_attribute(ControlAttribute::Canvas(self))
}
}
impl Modifier<Control> for (ActionTrigger, String) {
fn modify(self, control: &mut Control) {
control.add_attribute(Action(self.0, self.1))
}
}
impl<'a> Modifier<Control> for (ActionTrigger, &'a str) {
fn modify(self, control: &mut Control) {
control.add_attribute(Action(self.0, String::from(self.1)))
}
}
impl Modifier<Control> for Vec<ControlAttribute> {
fn modify(self, control: &mut Control) {
for attr in self.into_iter() {
control.add_attribute(attr);
}
}
}
impl Modifier<Control> for Vec<Control> {
fn modify(self, control: &mut Control) {
control.add_attribute(SubComponents(self))
}
}