1 module app;
2
3 import std.typecons : Flag, Yes, No;
4 import renderer : render;
5
6 void itemInColumn(Flag!"runTest" runTest = Yes.runTest)
7 {
8 import std.stdio;
9 import std.array : front;
10 import common : makeDom, DomNode, printDom;
11
12 static struct Data
13 {
14 string item0 = "item0", item1 = "item1", item2 = "item2", item3 = "item3";
15 }
16
17 Data data;
18
19 auto root = new DomNode(false, null);
20 {
21 import common : Direction;
22
23 root.name = "root";
24 root.attributes.direction = Direction.column;
25 auto root_item0 = new DomNode(false, null);
26 {
27 root.child ~= root_item0;
28 root_item0.name = "root.item0";
29 }
30 auto root_item1 = new DomNode(false, null);
31 {
32 root.child ~= root_item1;
33 root_item1.name = "root.item1";
34 }
35 auto root_item2 = new DomNode(false, null);
36 {
37 root.child ~= root_item2;
38 root_item2.name = "root.item2";
39 }
40 auto root_item3 = new DomNode(false, null);
41 {
42 root.child ~= root_item3;
43 root_item3.name = "root.item3";
44 }
45 }
46
47 writeln;
48
49 import walker : Walker;
50 import common : Direction, Alignment, Justification;
51 Walker walker;
52 with (walker)
53 {
54 with(area)
55 {
56 x = y = 0;
57 w = 640;
58 h = 480;
59 margin = 10;
60 padding = 10;
61 }
62 direction = Direction.column;
63 alignment = Alignment.stretch;
64 justification = Justification.around;
65 wrapping = false;
66 }
67 walker.render(data, root);
68 writeln;
69
70 walker.renderlog.render("itemInColumn");
71
72 if (!runTest)
73 return;
74
75 import std.array : popFront;
76 import common;
77
78 auto log = walker.renderlog;
79
80 assert(log.front.name == "root");
81 assert(log.front.area == WorkArea(0, 0, 640, 480, 10));
82 assert(log.front.direction == Direction.column);
83 log.popFront;
84 log.popFront;
85
86 assert(log.front.name == "root.item0");
87 assert(log.front.area == WorkArea(10, 10, 620, 115, 10));
88 assert(log.front.direction == Direction.column);
89 log.popFront;
90 log.popFront;
91
92 assert(log.front.name == "root.item1");
93 assert(log.front.area == WorkArea(10, 125, 620, 115, 10));
94 assert(log.front.direction == Direction.column);
95 log.popFront;
96 log.popFront;
97
98 assert(log.front.name == "root.item2");
99 assert(log.front.area == WorkArea(10, 240, 620, 115, 10));
100 assert(log.front.direction == Direction.column);
101 log.popFront;
102 log.popFront;
103
104 assert(log.front.name == "root.item3");
105 assert(log.front.area == WorkArea(10, 355, 620, 115, 10));
106 assert(log.front.direction == Direction.column);
107 log.popFront;
108 log.popFront;
109 }
110
111 void itemInRow(Flag!"runTest" runTest = Yes.runTest)
112 {
113 import std.stdio;
114 import std.array : front;
115 import common : makeDom, DomNode, printDom;
116
117 static struct Data
118 {
119 string item0 = "item0", item1 = "item1", item2 = "item2", item3 = "item3";
120 }
121
122 Data data;
123
124 auto root = new DomNode(false, null);
125 {
126 import common : Direction;
127
128 root.name = "root";
129 root.attributes.direction = Direction.row;
130 root.attributes.margin = 20;
131 root.attributes.padding = 30;
132 auto root_item0 = new DomNode(false, null);
133 {
134 root.child ~= root_item0;
135 root_item0.name = "root.item0";
136 }
137 auto root_item1 = new DomNode(false, null);
138 {
139 root.child ~= root_item1;
140 root_item1.name = "root.item1";
141 }
142 auto root_item2 = new DomNode(false, null);
143 {
144 root.child ~= root_item2;
145 root_item2.name = "root.item2";
146 }
147 auto root_item3 = new DomNode(false, null);
148 {
149 root.child ~= root_item3;
150 root_item3.name = "root.item3";
151 }
152 }
153
154 writeln;
155
156 import walker : Walker;
157 import common : Direction, Alignment, Justification;
158 Walker walker;
159 with (walker)
160 {
161 with(area)
162 {
163 x = y = 0;
164 w = 640;
165 h = 480;
166 margin = 10;
167 }
168 direction = Direction.row;
169 alignment = Alignment.stretch;
170 justification = Justification.around;
171 wrapping = false;
172 }
173 walker.render(data, root);
174 writeln;
175
176 walker.renderlog.render("itemInRow");
177
178 if (!runTest)
179 return;
180
181 import std.array : popFront;
182 import common;
183
184 auto log = walker.renderlog;
185
186 assert(log.front.name == "root");
187 assert(log.front.area == WorkArea(0, 0, 640, 480, 10));
188 assert(log.front.direction == Direction.row);
189 log.popFront;
190 log.popFront;
191
192 assert(log.front.name == "root.item0");
193 assert(log.front.area == WorkArea(10, 10, 155, 460, 10));
194 assert(log.front.direction == Direction.row);
195 log.popFront;
196 log.popFront;
197
198 assert(log.front.name == "root.item1");
199 assert(log.front.area == WorkArea(165, 10, 155, 460, 10));
200 assert(log.front.direction == Direction.row);
201 log.popFront;
202 log.popFront;
203
204 assert(log.front.name == "root.item2");
205 assert(log.front.area == WorkArea(320, 10, 155, 460, 10));
206 assert(log.front.direction == Direction.row);
207 log.popFront;
208 log.popFront;
209
210 assert(log.front.name == "root.item3");
211 assert(log.front.area == WorkArea(475, 10, 155, 460, 10));
212 assert(log.front.direction == Direction.row);
213 log.popFront;
214 log.popFront;
215 }
216
217 void complexCase(Flag!"runTest" runTest = Yes.runTest)
218 {
219 import std.stdio;
220 import std.array : front;
221 import common : makeDom, DomNode, printDom;
222
223 static struct Data
224 {
225 struct Child0
226 {
227
228 }
229
230 Child0 child0;
231
232 struct Child1
233 {
234 struct Panel0
235 {
236 struct Image
237 {
238
239 }
240
241 Image image;
242
243 struct Text
244 {
245
246 }
247
248 Text text;
249 }
250
251 Panel0 panel0;
252
253 struct Panel1
254 {
255 struct Text
256 {
257
258 }
259
260 Text text;
261
262 struct Panel
263 {
264 struct Ok
265 {
266
267 }
268
269 Ok ok;
270
271 struct Cancel
272 {
273
274 }
275
276 Cancel cancel;
277 }
278
279 Panel panel;
280 }
281
282 Panel1 panel1;
283 }
284
285 Child1 child1;
286 }
287
288 Data data2;
289
290 auto root = new DomNode(false, null);
291 {
292 import common : Direction;
293
294 root.name = "root";
295 root.attributes.direction = Direction.column;
296 root.attributes.margin = 10;
297 root.attributes.padding = 10;
298 auto root_child0 = new DomNode(false, null);
299 {
300 root.child ~= root_child0;
301 root_child0.name = "root.child0";
302 }
303 auto root_child1 = new DomNode(false, null);
304 {
305 root.child ~= root_child1;
306 root_child1.name = "root.child1";
307 root_child1.attributes.direction = Direction.row;
308
309 auto root_child1_panel0 = new DomNode(false, null);
310 {
311 root_child1.child ~= root_child1_panel0;
312 root_child1_panel0.name = "root.child1.panel0";
313 root_child1_panel0.attributes.direction = Direction.column;
314 root_child1_panel0.attributes.margin = 20;
315
316 auto image = new DomNode(false, null);
317 {
318 root_child1_panel0.child ~= image;
319 image.name = "root.child1.panel0.image";
320 }
321 auto text = new DomNode(false, null);
322 {
323 root_child1_panel0.child ~= text;
324 text.name = "root.child1.panel0.text";
325 }
326 }
327 auto root_child1_panel1 = new DomNode(false, null);
328 {
329 root_child1.child ~= root_child1_panel1;
330 root_child1_panel1.name = "root.child1.panel1";
331 root_child1_panel1.attributes.direction = Direction.column;
332
333 auto text = new DomNode(false, null);
334 {
335 root_child1_panel1.child ~= text;
336 text.name = "root.child1.panel1.text";
337 }
338
339 auto panel = new DomNode(false, null);
340 {
341 root_child1_panel1.child ~= panel;
342 panel.name = "root.child1.panel1.panel";
343 panel.attributes.direction = Direction.row;
344
345 auto ok = new DomNode(false, null);
346 {
347 panel.child ~= ok;
348 ok.name = "root.child1.panel1.panel.ok";
349 }
350
351 auto cancel = new DomNode(false, null);
352 {
353 panel.child ~= cancel;
354 cancel.name = "root.child1.panel1.panel.cancel";
355 }
356 }
357 }
358 }
359 }
360
361 writeln;
362
363 import walker : Walker;
364 import common : Direction, Alignment, Justification;
365 Walker walker;
366 with (walker)
367 {
368 with(area)
369 {
370 x = y = 0;
371 w = 640;
372 h = 480;
373 }
374 direction = Direction.column;
375 alignment = Alignment.stretch;
376 justification = Justification.around;
377 wrapping = false;
378 }
379 walker.render(data2, root);
380 writeln;
381
382 walker.renderlog.render("complexCase");
383
384 if (!runTest)
385 return;
386
387 import std.array : popFront;
388 import common;
389
390 auto log = walker.renderlog;
391 assert(log.front.name == "root");
392 assert(log.front.area == WorkArea(0, 0, 640, 480, 10));
393 assert(log.front.direction == Direction.column);
394 log.popFront;
395 log.popFront;
396
397 assert(log.front.name == "root.child0");
398 assert(log.front.area == WorkArea(10, 10, 620, 230, 10));
399 assert(log.front.direction == Direction.column);
400 log.popFront;
401 log.popFront;
402
403 assert(log.front.name == "root.child1");
404 assert(log.front.area == WorkArea(10, 240, 620, 230, 10));
405 assert(log.front.direction == Direction.row);
406 log.popFront;
407 log.popFront;
408
409 assert(log.front.name == "root.child1.panel0");
410 assert(log.front.area == WorkArea(20, 250, 300, 210, 20));
411 assert(log.front.direction == Direction.column);
412 log.popFront;
413 log.popFront;
414
415 assert(log.front.name == "root.child1.panel0.image");
416 assert(log.front.area == WorkArea(40, 270, 260, 85, 20));
417 assert(log.front.direction == Direction.column);
418 log.popFront;
419 log.popFront;
420
421 assert(log.front.name == "root.child1.panel0.text");
422 assert(log.front.area == WorkArea(40, 355, 260, 85, 20));
423 assert(log.front.direction == Direction.column);
424 log.popFront;
425 log.popFront;
426
427 assert(log.front.name == "root.child1.panel1");
428 assert(log.front.area == WorkArea(320, 250, 300, 210, 10));
429 assert(log.front.direction == Direction.column);
430 log.popFront;
431 log.popFront;
432
433 assert(log.front.name == "root.child1.panel1.text");
434 assert(log.front.area == WorkArea(330, 260, 280, 95, 10));
435 assert(log.front.direction == Direction.column);
436 log.popFront;
437 log.popFront;
438
439 assert(log.front.name == "root.child1.panel1.panel");
440 assert(log.front.area == WorkArea(330, 355, 280, 95, 10));
441 assert(log.front.direction == Direction.row);
442 log.popFront;
443 log.popFront;
444
445 assert(log.front.name == "root.child1.panel1.panel.ok");
446 assert(log.front.area == WorkArea(340, 365, 130, 75, 10));
447 assert(log.front.direction == Direction.row);
448 log.popFront;
449 log.popFront;
450
451 assert(log.front.name == "root.child1.panel1.panel.cancel");
452 assert(log.front.area == WorkArea(470, 365, 130, 75, 10));
453 assert(log.front.direction == Direction.row);
454 log.popFront;
455 log.popFront;
456 }
457
458 void main()
459 {
460 itemInRow(No.runTest);
461 itemInColumn(No.runTest);
462 complexCase(No.runTest);
463 }