Mercurial > projects > dynamin
annotate dynamin/gui/layout.d @ 100:4f2d709760eb
Change from individual fields to a static array for x, y, width, height, etc.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Tue, 15 May 2012 15:17:24 -0500 |
parents | 2e466b478c0b |
children | 73060bc3f004 |
rev | line source |
---|---|
0 | 1 // Written in the D programming language |
2 // www.digitalmars.com/d/ | |
3 | |
4 /* | |
5 * The contents of this file are subject to the Mozilla Public License Version | |
6 * 1.1 (the "License"); you may not use this file except in compliance with | |
7 * the License. You may obtain a copy of the License at | |
8 * http://www.mozilla.org/MPL/ | |
9 * | |
10 * Software distributed under the License is distributed on an "AS IS" basis, | |
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
12 * for the specific language governing rights and limitations under the | |
13 * License. | |
14 * | |
15 * The Original Code is the Dynamin library. | |
16 * | |
17 * The Initial Developer of the Original Code is Jordan Miner. | |
18 * Portions created by the Initial Developer are Copyright (C) 2007-2009 | |
19 * the Initial Developer. All Rights Reserved. | |
20 * | |
21 * Contributor(s): | |
22 * Jordan Miner <jminer7@gmail.com> | |
23 * | |
24 */ | |
25 | |
26 module dynamin.gui.layout; | |
27 | |
28 import dynamin.all_gui; | |
29 import dynamin.gui.control; | |
30 import dynamin.all_painting; | |
31 import dynamin.core.string; | |
32 import tango.io.Stdout; | |
33 import dynamin.core.benchmark; | |
34 | |
35 // this is a temporary file to hold layout code until I figure out what | |
36 // files to put it in | |
37 | |
38 /* | |
39 Opera's find dialog: | |
40 | |
41 auto whatLabel = win.content.add(new Label("Find What")); | |
42 ... | |
43 | |
44 V( whatLabel | |
45 H( findBox findButton ) | |
46 H( V(wholeWordCheck caseCheck) ~ V(upRadio downRadio) ~) | |
47 H( ~ closeButton ) | |
48 ) | |
49 */ | |
50 | |
51 enum LayoutType { | |
52 None, Table, Control, Filler, Spacer | |
53 } | |
54 enum Elasticity { | |
55 No, Semi, Yes | |
56 } | |
57 struct LayoutGroup { | |
58 LayoutType type; | |
59 LayoutGroup* parent; | |
37
f9fea816b1fb
Correct a comment and remove an unused variable.
Jordan Miner <jminer7@gmail.com>
parents:
11
diff
changeset
|
60 LayoutGroup[] children; // used if type == LayoutType.Table |
0 | 61 Control control; // used if type == LayoutType.Control |
62 int numColumns; // used if type == LayoutType.Table | |
63 int numRows() { return children.length / numColumns; } | |
64 | |
65 bool cacheActive; | |
66 private Elasticity _elasticXCache, _elasticYCache; | |
67 private Size _bestSizeCache; | |
68 private int _baselineCache; | |
69 | |
70 // spacing variables | |
71 int spacing = 8; | |
72 static LayoutGroup opCall(LayoutType type, LayoutGroup* parent) { | |
73 LayoutGroup layout; | |
74 layout.type = type; | |
75 layout.parent = parent; | |
76 layout.children.length = 3; | |
77 layout.children.length = 0; | |
78 return layout; | |
79 } | |
80 | |
81 void setCache() { | |
82 for(int i = 0; i < children.length; ++i) // can't use foreach--copies | |
83 children[i].setCache(); | |
84 _elasticXCache = _elasticX; | |
85 _elasticYCache = _elasticY; | |
86 _bestSizeCache = _bestSize; | |
87 _baselineCache = _baseline; | |
88 cacheActive = true; | |
89 } | |
90 void clearCache() { | |
91 cacheActive = false; | |
92 for(int i = 0; i < children.length; ++i) // can't use foreach--copies | |
93 children[i].clearCache(); | |
94 } | |
95 Elasticity elasticX() { return cacheActive ? _elasticXCache : _elasticX; } | |
96 Elasticity elasticY() { return cacheActive ? _elasticYCache : _elasticY; } | |
97 Size bestSize() { return cacheActive ? _bestSizeCache : _bestSize; } | |
98 int baseline() { return cacheActive ? _baselineCache : _baseline; } | |
99 | |
100 //{{{ _elasticX() | |
101 private Elasticity _elasticX() { | |
102 switch(type) { | |
103 case LayoutType.Control: | |
104 return control.elasticX ? Elasticity.Yes : Elasticity.No; | |
105 case LayoutType.Table: | |
106 auto e = Elasticity.No; | |
107 foreach(layout; children) { | |
108 if(layout.elasticX > e) | |
109 e = layout.elasticX; | |
110 if(e == Elasticity.Yes) | |
111 return e; | |
112 } | |
113 return e; | |
114 case LayoutType.Filler: | |
38
69df5369c5f7
Fix filler to only be elastic in the direction of its parent.
Jordan Miner <jminer7@gmail.com>
parents:
37
diff
changeset
|
115 if(!parent || parent.numColumns > 1 || children.length == 1) |
69df5369c5f7
Fix filler to only be elastic in the direction of its parent.
Jordan Miner <jminer7@gmail.com>
parents:
37
diff
changeset
|
116 return Elasticity.Semi; |
69df5369c5f7
Fix filler to only be elastic in the direction of its parent.
Jordan Miner <jminer7@gmail.com>
parents:
37
diff
changeset
|
117 else |
69df5369c5f7
Fix filler to only be elastic in the direction of its parent.
Jordan Miner <jminer7@gmail.com>
parents:
37
diff
changeset
|
118 return Elasticity.No; |
0 | 119 case LayoutType.Spacer: |
120 return Elasticity.No; | |
121 } | |
122 } | |
123 //}}} | |
124 //{{{ _elasticY() | |
125 private Elasticity _elasticY() { | |
126 switch(type) { | |
127 case LayoutType.Control: | |
128 return control.elasticY ? Elasticity.Yes : Elasticity.No; | |
129 case LayoutType.Table: | |
130 auto e = Elasticity.No; | |
131 foreach(layout; children) { | |
132 if(layout.elasticY > e) | |
133 e = layout.elasticY; | |
134 if(e == Elasticity.Yes) | |
135 return e; | |
136 } | |
137 return e; | |
138 case LayoutType.Filler: | |
38
69df5369c5f7
Fix filler to only be elastic in the direction of its parent.
Jordan Miner <jminer7@gmail.com>
parents:
37
diff
changeset
|
139 if(!parent || parent.numRows > 1 || children.length == 1) |
69df5369c5f7
Fix filler to only be elastic in the direction of its parent.
Jordan Miner <jminer7@gmail.com>
parents:
37
diff
changeset
|
140 return Elasticity.Semi; |
69df5369c5f7
Fix filler to only be elastic in the direction of its parent.
Jordan Miner <jminer7@gmail.com>
parents:
37
diff
changeset
|
141 else |
69df5369c5f7
Fix filler to only be elastic in the direction of its parent.
Jordan Miner <jminer7@gmail.com>
parents:
37
diff
changeset
|
142 return Elasticity.No; |
0 | 143 case LayoutType.Spacer: |
144 return Elasticity.No; | |
145 } | |
146 } | |
147 //}}} | |
148 | |
149 //{{{ _bestSize() | |
150 private Size _bestSize() { | |
151 switch(type) { | |
152 case LayoutType.Control: | |
153 return control.bestSize; | |
154 case LayoutType.Table: | |
155 scope colsInfo = new ColRowInfo[numColumns]; | |
156 scope rowsInfo = new ColRowInfo[numRows]; | |
157 TableInfo info; | |
158 getTableSizes(colsInfo, rowsInfo, info); | |
159 return info.bestSize; | |
160 case LayoutType.Filler: | |
161 case LayoutType.Spacer: | |
162 return Size(0, 0); | |
163 } | |
164 } | |
165 //}}} | |
166 //{{{ _baseline() | |
167 private int _baseline() { | |
168 switch(type) { | |
169 case LayoutType.Control: | |
170 return control.baseline; | |
171 case LayoutType.Table: | |
40
735223842a85
Make horizontal layouts align along their baseline.
Jordan Miner <jminer7@gmail.com>
parents:
39
diff
changeset
|
172 if(numRows != 1) |
735223842a85
Make horizontal layouts align along their baseline.
Jordan Miner <jminer7@gmail.com>
parents:
39
diff
changeset
|
173 return 0; |
735223842a85
Make horizontal layouts align along their baseline.
Jordan Miner <jminer7@gmail.com>
parents:
39
diff
changeset
|
174 scope colsInfo = new ColRowInfo[numColumns]; |
735223842a85
Make horizontal layouts align along their baseline.
Jordan Miner <jminer7@gmail.com>
parents:
39
diff
changeset
|
175 scope rowsInfo = new ColRowInfo[numRows]; |
735223842a85
Make horizontal layouts align along their baseline.
Jordan Miner <jminer7@gmail.com>
parents:
39
diff
changeset
|
176 TableInfo info; |
735223842a85
Make horizontal layouts align along their baseline.
Jordan Miner <jminer7@gmail.com>
parents:
39
diff
changeset
|
177 getTableSizes(colsInfo, rowsInfo, info); |
735223842a85
Make horizontal layouts align along their baseline.
Jordan Miner <jminer7@gmail.com>
parents:
39
diff
changeset
|
178 return cast(int)rowsInfo[0].baseline; |
0 | 179 case LayoutType.Filler: |
180 case LayoutType.Spacer: | |
181 return 0; | |
182 } | |
183 } | |
184 //}}} | |
185 | |
186 //{{{ layout() | |
187 void layout(Rect rect) { | |
188 switch(type) { | |
189 case LayoutType.Control: | |
190 control.location = Point(rect.x, rect.y); | |
191 control.size = Size(rect.width, rect.height); | |
192 return; | |
193 case LayoutType.Table: | |
194 scope colsInfo = new ColRowInfo[numColumns]; | |
195 scope rowsInfo = new ColRowInfo[numRows]; | |
196 TableInfo info; | |
197 getTableSizes(colsInfo, rowsInfo, info); | |
198 | |
199 real extraWidth = rect.width - bestSize.width; | |
200 real extraHeight = rect.height - bestSize.height; | |
201 | |
202 void distExtra(ref real extra, ref ColRowInfo info, | |
203 ref real totalElastic, ref int semis, Elasticity e) { | |
204 if(info.elastic == Elasticity.No || extra <= 0) | |
205 return; | |
206 if(e == Elasticity.Semi && | |
207 info.elastic == Elasticity.Semi) { | |
208 auto thisExtra = extra / semis; | |
209 extra -= thisExtra; | |
210 semis--; | |
211 info.bestSize += thisExtra; | |
212 } else if(e == Elasticity.Yes && | |
213 info.elastic == Elasticity.Yes) { | |
214 auto thisExtra = extra * info.bestSize/totalElastic; | |
215 extra -= thisExtra; | |
216 totalElastic -= info.bestSize; // subtract original size | |
217 info.bestSize += thisExtra; | |
218 } | |
219 } | |
220 real y = 0; | |
221 for(int row = 0; row < numRows; ++row) { // go over each row | |
222 distExtra(extraHeight, rowsInfo[row], info.elasticHeight, info.semiRows, elasticY); | |
223 | |
224 real x = 0; | |
225 for(int col = 0; col < numColumns; ++col) { | |
226 distExtra(extraWidth, colsInfo[col], info.elasticWidth, info.semiColumns, elasticX); | |
227 | |
228 auto layout = children[row * numColumns + col]; | |
229 | |
230 Rect r = Point(x, y) + layout.bestSize; | |
231 | |
232 if(layout.baseline > 0) | |
233 r.y = r.y + rowsInfo[row].baseline - layout.baseline; | |
234 if(layout.elasticX) | |
235 r.width = colsInfo[col].bestSize; | |
236 if(layout.elasticY) | |
237 r.height = rowsInfo[row].bestSize; | |
238 | |
239 layout.layout(r + Point(rect.x, rect.y)); | |
240 | |
241 x += colsInfo[col].bestSize + | |
242 (colsInfo[col].filler ? 0 : spacing); | |
243 } | |
244 y += rowsInfo[row].bestSize + | |
245 (rowsInfo[row].filler ? 0 : spacing); | |
246 } | |
247 return; | |
248 case LayoutType.Filler: | |
249 case LayoutType.Spacer: | |
250 return; | |
251 } | |
252 } | |
253 //}}} | |
254 | |
255 struct ColRowInfo { | |
256 real bestSize = 0; // large enough to hold the largest control | |
257 Elasticity elastic = Elasticity.No; | |
258 bool filler = true; // if the entire column/row is filler | |
259 real baseline; // only applies to rows: max baseline in row | |
260 } | |
261 struct TableInfo { | |
262 // number of semi-elastic columns/rows | |
263 int semiColumns = 0; int semiRows = 0; | |
264 // the sum of fully elastic width/height, not including semi | |
265 real elasticWidth = 0, elasticHeight = 0; | |
100
4f2d709760eb
Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents:
42
diff
changeset
|
266 Size bestSize; |
0 | 267 } |
268 //{{{ getTableSizes() | |
269 // Fills in the passed in array with the column and row sizes, as well | |
270 // as whether they are elastic. The passed in arrays must be the right | |
271 // sizes. They may be stack allocated. The table best size does | |
272 // including spacing, but column and row best sizes do not. | |
273 private void getTableSizes(ColRowInfo[] colsInfo, ColRowInfo[] rowsInfo, ref TableInfo info) { | |
274 assert(children.length % numColumns == 0); | |
275 assert(type == LayoutType.Table); | |
276 | |
277 assert(colsInfo.length == numColumns); | |
278 assert(rowsInfo.length == numRows); | |
279 | |
37
f9fea816b1fb
Correct a comment and remove an unused variable.
Jordan Miner <jminer7@gmail.com>
parents:
11
diff
changeset
|
280 real max = 0; |
0 | 281 LayoutGroup* l; |
282 | |
39
04d2867d335c
Fix possible incorrect extra space after the last control in a layout.
Jordan Miner <jminer7@gmail.com>
parents:
38
diff
changeset
|
283 bool prevNonFiller = false; |
0 | 284 int sp = 0; |
285 for(int col = 0; col < numColumns; ++col) { // go down each column | |
286 for(int row = 0; row < numRows; ++row) { | |
287 l = &children[row * numColumns + col]; | |
288 max = l.bestSize.width > max ? l.bestSize.width : max; | |
289 if(l.elasticX > colsInfo[col].elastic) | |
290 colsInfo[col].elastic = l.elasticX; | |
291 if(l.type != LayoutType.Filler) | |
292 colsInfo[col].filler = false; | |
293 } | |
294 colsInfo[col].bestSize = max; | |
295 if(colsInfo[col].elastic == Elasticity.Yes) | |
296 info.elasticWidth += max; | |
297 else if(colsInfo[col].elastic == Elasticity.Semi) | |
298 info.semiColumns++; | |
39
04d2867d335c
Fix possible incorrect extra space after the last control in a layout.
Jordan Miner <jminer7@gmail.com>
parents:
38
diff
changeset
|
299 // this won't add spacing to the first non-filler |
04d2867d335c
Fix possible incorrect extra space after the last control in a layout.
Jordan Miner <jminer7@gmail.com>
parents:
38
diff
changeset
|
300 sp = (!colsInfo[col].filler && prevNonFiller) ? spacing : 0; |
0 | 301 info.bestSize.width = info.bestSize.width + sp + max; |
39
04d2867d335c
Fix possible incorrect extra space after the last control in a layout.
Jordan Miner <jminer7@gmail.com>
parents:
38
diff
changeset
|
302 prevNonFiller = !colsInfo[col].filler ? true : prevNonFiller ; |
0 | 303 max = 0; |
304 } | |
305 | |
39
04d2867d335c
Fix possible incorrect extra space after the last control in a layout.
Jordan Miner <jminer7@gmail.com>
parents:
38
diff
changeset
|
306 prevNonFiller = false; |
0 | 307 real maxBl = 0; |
308 sp = 0; | |
309 for(int row = 0; row < numRows; ++row) { // go over each row | |
310 for(int col = 0; col < numColumns; ++col) { | |
311 l = &children[row * numColumns + col]; | |
312 max = l.bestSize.height > max ? l.bestSize.height : max; | |
313 maxBl = l.baseline > maxBl ? l.baseline : maxBl; | |
314 if(l.elasticY > rowsInfo[row].elastic) | |
315 rowsInfo[row].elastic = l.elasticY; | |
316 if(l.type != LayoutType.Filler) | |
317 rowsInfo[row].filler = false; | |
318 } | |
319 rowsInfo[row].bestSize = max; | |
320 rowsInfo[row].baseline = maxBl; | |
321 if(rowsInfo[row].elastic == Elasticity.Yes) | |
322 info.elasticHeight += max; | |
323 else if(rowsInfo[row].elastic == Elasticity.Semi) | |
324 info.semiRows++; | |
39
04d2867d335c
Fix possible incorrect extra space after the last control in a layout.
Jordan Miner <jminer7@gmail.com>
parents:
38
diff
changeset
|
325 // this won't add spacing to the first non-filler |
04d2867d335c
Fix possible incorrect extra space after the last control in a layout.
Jordan Miner <jminer7@gmail.com>
parents:
38
diff
changeset
|
326 sp = (!rowsInfo[row].filler && prevNonFiller) ? spacing : 0; |
0 | 327 info.bestSize.height = info.bestSize.height + sp + max; |
39
04d2867d335c
Fix possible incorrect extra space after the last control in a layout.
Jordan Miner <jminer7@gmail.com>
parents:
38
diff
changeset
|
328 prevNonFiller = !rowsInfo[row].filler ? true : prevNonFiller ; |
0 | 329 max = maxBl = 0; |
330 } | |
331 } | |
332 //}}} | |
333 } | |
334 | |
335 //{{{ LayoutPanel class | |
336 class LayoutPanel : Panel { | |
337 LayoutGroup root; | |
338 LayoutGroup* current; | |
339 void startLayout(int ncolumns) { | |
340 if(current is null) { | |
341 root = LayoutGroup(LayoutType.Table, null); | |
342 root.numColumns = ncolumns; | |
343 current = &root; | |
344 return; | |
345 } | |
346 current.children.length = current.children.length+1; | |
347 current.children[$-1] = LayoutGroup(LayoutType.Table, current); | |
348 current.children[$-1].numColumns = ncolumns; | |
349 current = ¤t.children[$-1]; | |
350 } | |
351 void endLayout() { | |
352 current = current.parent; | |
353 } | |
354 override void add(Control c) { | |
355 if(current is null) | |
356 throw new Exception("Cannot add a control until a layout is started"); | |
357 current.children.length = current.children.length+1; | |
358 current.children[$-1] = LayoutGroup(LayoutType.Control, current); | |
359 current.children[$-1].control = c; | |
360 super.add(c); | |
361 } | |
362 void addFiller() { | |
363 current.children.length = current.children.length+1; | |
364 current.children[$-1] = LayoutGroup(LayoutType.Filler, current); | |
365 } | |
366 void addSpacer() { | |
367 current.children.length = current.children.length+1; | |
368 current.children[$-1] = LayoutGroup(LayoutType.Spacer, current); | |
369 } | |
370 | |
371 override Size bestSize() { | |
372 return root.bestSize + Size(root.spacing*2, root.spacing*2); | |
373 } | |
374 override bool elasticX() { return root.elasticX == Elasticity.Yes; } | |
375 override bool elasticY() { return root.elasticY == Elasticity.Yes; } | |
376 override void layout() { | |
377 //benchmarkAndWrite("layout", { | |
378 root.setCache(); | |
379 int sp = root.spacing; | |
380 root.layout(Rect(sp, sp, width-2*sp, height-2*sp)); | |
381 root.clearCache(); | |
382 //}); | |
383 } | |
384 } | |
385 //}}} | |
386 | |
387 //{{{ createLayout() etc. | |
388 /** | |
389 * Note: if you do this: | |
390 * ----- | |
391 * char[] s = createLayout("V( b1 H(b2 b3) )"); | |
392 * ----- | |
393 * Then the program will crash when compiled with the -release flag. (I am | |
394 * pretty sure it is a DMD bug, but I don't have time to make a testcase | |
395 * for a bug that does not bother me.) This will work correctly: | |
396 * ----- | |
397 * const char[] s = createLayout("V( b1 H(b2 b3) )"); | |
398 * ----- | |
399 * Because then the function is interpreted at compile time with CTFE. | |
400 */ | |
401 string createLayout(string layout) { | |
402 string code = "delegate LayoutPanel() {\n"; | |
403 code ~= "auto panel = new LayoutPanel;\n"; | |
404 assert(getToken(layout) == "H" || getToken(layout) == "V" || | |
405 getToken(layout) == "T", "layout type 'H', 'V', or 'T' expected"); | |
406 code ~= parseLayout(layout); | |
407 code ~= "return panel;\n"; | |
408 code ~= "}()"; | |
409 return code; | |
410 } | |
411 | |
412 void skipWS(ref string str) { | |
413 int i = 0; | |
414 while(" \t\n\r\v\f".contains(str[i])) | |
415 i++; | |
416 str = str[i..$]; | |
417 } | |
418 // advances to the next token and returns it | |
419 string nextToken(ref string str) { | |
420 skipWS(str); | |
421 str = str[getToken(str).length..$]; | |
422 return getToken(str); | |
423 } | |
424 // returns H or V or ( or ) or myControl | |
425 // gets the current token | |
426 string getToken(string str) { | |
427 string idChars = | |
428 "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | |
429 | |
430 // TODO: // for line comments? | |
431 skipWS(str); | |
11
df1c8e659b75
Change layout language to use * for filler and ~ for spacing. Ticket #24
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
432 if("()[]*~".contains(str[0])) { |
0 | 433 return str[0..1]; |
434 } else if(idChars.contains(str[0])) { | |
435 int i = 1; | |
436 while(idChars.contains(str[i])) | |
437 i++; | |
438 return str[0..i]; | |
439 } else { | |
440 assert(0, "unknown character: " ~ str[0]); | |
441 } | |
442 } | |
443 | |
444 // {{{ copied from Phobos | |
445 char[] ctfeUintToString(uint u) { | |
446 char[uint.sizeof * 3] buffer = void; | |
447 int ndigits; | |
448 char[] result; | |
449 char[] digits = "0123456789"; | |
450 | |
451 ndigits = 0; | |
452 if (u < 10) | |
453 // Avoid storage allocation for simple stuff | |
454 result = digits[u .. u + 1]; | |
455 else | |
456 { | |
457 while (u) | |
458 { | |
459 uint c = (u % 10) + '0'; | |
460 u /= 10; | |
461 ndigits++; | |
462 buffer[buffer.length - ndigits] = cast(char)c; | |
463 } | |
464 result = new char[ndigits]; | |
465 result[] = buffer[buffer.length - ndigits .. buffer.length]; | |
466 } | |
467 return result; | |
468 } | |
469 uint ctfeStringToUint(char[] s) | |
470 { | |
471 int length = s.length; | |
472 | |
473 if (!length) | |
474 return 0; | |
475 | |
476 uint v = 0; | |
477 | |
478 for (int i = 0; i < length; i++) | |
479 { | |
480 char c = s[i]; | |
481 if (c >= '0' && c <= '9') | |
482 { | |
483 if (v < uint.max/10 || (v == uint.max/10 && c <= '5')) | |
484 v = v * 10 + (c - '0'); | |
485 else | |
486 return 0; | |
487 } | |
488 else | |
489 return 0; | |
490 } | |
491 return v; | |
492 } | |
493 //}}} | |
494 | |
495 uint parseBody(ref string layout, ref string bcode) { | |
496 uint count = 0; | |
497 assert(nextToken(layout) == "(", "open parenthesis expected"); | |
498 while(nextToken(layout) != ")") { | |
11
df1c8e659b75
Change layout language to use * for filler and ~ for spacing. Ticket #24
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
499 if(getToken(layout) == "*") |
0 | 500 bcode = bcode ~ "panel.addFiller();\n"; |
11
df1c8e659b75
Change layout language to use * for filler and ~ for spacing. Ticket #24
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
501 else if(getToken(layout) == "~") |
0 | 502 bcode = bcode ~ "panel.addSpacer();\n"; |
503 else | |
504 bcode = bcode ~ parseLayout(layout); | |
505 count++; | |
506 } | |
507 bcode = bcode ~ "panel.endLayout();\n"; | |
508 return count; | |
509 } | |
510 | |
511 string parseLayout(ref string layout) { | |
512 string code = ""; | |
513 | |
514 if(getToken(layout) == "H") { | |
515 string bodyCode; | |
516 auto count = parseBody(layout, bodyCode); | |
517 code ~= "panel.startLayout(" ~ ctfeUintToString(count) ~ ");\n"; | |
518 code ~= bodyCode; | |
519 } else if(getToken(layout) == "V") { | |
520 code ~= "panel.startLayout(1);\n"; | |
521 parseBody(layout, code); | |
522 } else if(getToken(layout) == "T") { | |
523 assert(nextToken(layout) == "[", "open bracket expected"); | |
524 nextToken(layout); | |
525 assert("0123456789".contains(getToken(layout)[0]), | |
526 "number of table columns expected"); | |
527 uint columns = ctfeStringToUint(getToken(layout)); | |
528 code ~= "panel.startLayout(" ~ getToken(layout) ~ ");\n"; | |
529 assert(nextToken(layout) == "]", "close bracket expected"); | |
530 assert(parseBody(layout, code) % columns == 0, | |
531 "number of controls must be a multiple of number of columns"); | |
532 } else { | |
533 code ~= "panel.add(" ~ getToken(layout) ~ ");\n"; | |
534 } | |
535 | |
536 return code; | |
537 } | |
538 | |
539 //{{{ parser tests | |
540 static assert(createLayout("H()") != "not evaluatable at compile time"); | |
541 //pragma(msg, createLayout("V()")); | |
542 | |
543 static assert(createLayout("V(c1 c2)") == | |
544 `delegate LayoutPanel() { | |
545 auto panel = new LayoutPanel; | |
546 panel.startLayout(1); | |
547 panel.add(c1); | |
548 panel.add(c2); | |
549 panel.endLayout(); | |
550 return panel; | |
551 }()`); | |
11
df1c8e659b75
Change layout language to use * for filler and ~ for spacing. Ticket #24
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
552 static assert(createLayout("V(c1 * c2 H(c3 ~) c4)") == |
0 | 553 `delegate LayoutPanel() { |
554 auto panel = new LayoutPanel; | |
555 panel.startLayout(1); | |
556 panel.add(c1); | |
557 panel.addFiller(); | |
558 panel.add(c2); | |
559 panel.startLayout(2); | |
560 panel.add(c3); | |
561 panel.addSpacer(); | |
562 panel.endLayout(); | |
563 panel.add(c4); | |
564 panel.endLayout(); | |
565 return panel; | |
566 }()`); | |
567 static assert(createLayout("V( c1 T[2](c2 c3) c4 )") == | |
568 `delegate LayoutPanel() { | |
569 auto panel = new LayoutPanel; | |
570 panel.startLayout(1); | |
571 panel.add(c1); | |
572 panel.startLayout(2); | |
573 panel.add(c2); | |
574 panel.add(c3); | |
575 panel.endLayout(); | |
576 panel.add(c4); | |
577 panel.endLayout(); | |
578 return panel; | |
579 }()`); | |
580 //}}} | |
581 | |
582 //}}} | |
583 | |
584 unittest { | |
41
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
585 class FakeButton : Control { |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
586 Size bestSize() { return Size(80, 30); } |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
587 bool elasticX() { return false; } |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
588 bool elasticY() { return false; } |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
589 int baseline() { return 20; } |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
590 } |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
591 class FakeTextBox : Control { |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
592 Size bestSize() { return Size(100, 20); } |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
593 bool elasticX() { return true; } |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
594 bool elasticY() { return false; } |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
595 int baseline() { return 18; } |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
596 } |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
597 class FakeListBox : Control { |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
598 Size bestSize() { return Size(100, 300); } |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
599 bool elasticX() { return false; } |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
600 bool elasticY() { return true; } |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
601 int baseline() { return 15; } |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
602 } |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
603 class FakeLabel : Control { |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
604 Size bestSize() { return Size(70, 15); } |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
605 bool elasticX() { return false; } |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
606 bool elasticY() { return false; } |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
607 int baseline() { return 13; } |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
608 } |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
609 auto button1 = new FakeButton(); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
610 auto tb1 = new FakeTextBox(); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
611 auto tb2 = new FakeTextBox(); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
612 auto lb1 = new FakeListBox(); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
613 auto label1 = new FakeLabel(); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
614 auto label2 = new FakeLabel(); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
615 |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
616 Panel panel; |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
617 auto sp = 8; // TODO: get from same place as layout |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
618 |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
619 // vertical layout |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
620 panel = mixin(createLayout(`V( label1 button1 )`)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
621 assert(panel.bestSize == Size(80+sp*2, 30+15+sp*3)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
622 assert(panel.elasticX == false); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
623 assert(panel.elasticY == false); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
624 panel.size = [1000, 1000]; |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
625 assert(label1.location == Point(sp, sp)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
626 assert(label1.size == label1.bestSize); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
627 assert(button1.location == Point(sp, 15+sp*2)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
628 assert(button1.size == button1.bestSize); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
629 |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
630 // horizontal layout |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
631 panel = mixin(createLayout(`H( label1 button1 * )`)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
632 assert(panel.bestSize == Size(80+70+sp*3, 30+sp*2)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
633 assert(panel.elasticX == false); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
634 assert(panel.elasticY == false); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
635 panel.size = [1000, 1000]; |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
636 assert(label1.location == Point(sp, 20-13+sp)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
637 assert(label1.size == label1.bestSize); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
638 assert(button1.location == Point(70+sp*2, sp)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
639 assert(button1.size == button1.bestSize); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
640 |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
641 // filler is last priority |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
642 panel = mixin(createLayout(`H( * label1 tb1 )`)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
643 assert(panel.bestSize == Size(70+100+sp*3, 20+sp*2)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
644 assert(panel.elasticX == true); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
645 assert(panel.elasticY == false); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
646 panel.size = [500, 1000]; |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
647 assert(label1.location == Point(sp, 18-13+sp)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
648 assert(label1.size == label1.bestSize); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
649 assert(tb1.location == Point(70+sp*2, sp)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
650 assert(tb1.size == Size(panel.width-70-sp*3, tb1.bestSize.height)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
651 |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
652 // extra space is distributed evenly between elastic controls |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
653 panel = mixin(createLayout(`V( H( tb1 label1 tb2 ) H( * label2 button1) )`)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
654 assert(panel.bestSize == Size(270+sp*4, 20+30+sp*3)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
655 assert(panel.elasticX == true); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
656 assert(panel.elasticY == false); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
657 panel.size = [500, 1000]; |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
658 assert(tb1.location == Point(sp, sp)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
659 assert(tb1.size == Size((panel.width-70-sp*4) / 2, 20)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
660 assert(label1.location == Point(tb1.width+sp*2, 18-13+sp)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
661 assert(label1.size == label1.bestSize); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
662 assert(tb2.location == Point(tb1.width+70+sp*3, sp)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
663 assert(tb2.size == Size(tb1.width, 20)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
664 assert(label2.location == Point(panel.width-80-70-sp*2, 20+(20-13)+sp*2)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
665 assert(label2.size == label2.bestSize); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
666 assert(button1.location == Point(panel.width-80-sp, 20+sp*2)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
667 assert(button1.size == button1.bestSize); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
668 |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
669 // extra space is distributed evenly between filler |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
670 panel = mixin(createLayout(`V( * label1 * label2 * )`)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
671 assert(panel.bestSize == Size(70+sp*2, 15+15+sp*3)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
672 assert(panel.elasticX == false); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
673 assert(panel.elasticY == false); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
674 panel.size = [500, 120]; |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
675 assert(label1.location == Point(sp, 30)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
676 assert(label1.size == label1.bestSize); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
677 assert(label2.location == Point(sp, 75)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
678 assert(label2.size == label2.bestSize); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
679 |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
680 // spacing |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
681 panel = mixin(createLayout(`H( ~ label1 ~ button1 ~ )`)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
682 assert(panel.bestSize == Size(70+80+sp*6, 30+sp*2)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
683 assert(panel.elasticX == false); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
684 assert(panel.elasticY == false); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
685 panel.size = [500, 500]; |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
686 assert(label1.location == Point(sp*2, 20-13+sp)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
687 assert(button1.location == Point(70+sp*4, sp)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
688 |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
689 // semielastic |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
690 panel = mixin(createLayout(`T[2]( H(*label1) tb1 H(*button1) tb2 )`)); |
42
2e466b478c0b
Fix a bug in a test that somehow slipped by in last commits.
Jordan Miner <jminer7@gmail.com>
parents:
41
diff
changeset
|
691 assert(panel.bestSize == Size(80+100+sp*3, 20+30+sp*3)); |
41
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
692 assert(panel.elasticX == true); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
693 assert(panel.elasticY == false); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
694 panel.size = [500, 500]; |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
695 assert(label1.location == Point(10+sp, 18-13+sp)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
696 assert(label1.size == label1.bestSize); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
697 assert(button1.location == Point(sp, 20+sp*2)); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
698 assert(button1.size == button1.bestSize); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
699 |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
700 //assert(.location == Point()); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
701 //assert(.size == Size()); |
c25e8b83c5b8
Add a few layout tests (with decent coverage).
Jordan Miner <jminer7@gmail.com>
parents:
40
diff
changeset
|
702 //Stdout("1:")(panel.bestSize).newline; |
0 | 703 } |
704 |