Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/tests/scene/test_box_container.cpp
59209 views
1
/**************************************************************************/
2
/* test_box_container.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "tests/test_macros.h"
32
33
TEST_FORCE_LINK(test_box_container)
34
35
#include "scene/gui/box_container.h"
36
#include "scene/gui/control.h"
37
#include "scene/main/scene_tree.h"
38
#include "scene/main/window.h"
39
40
namespace TestBoxContainer {
41
42
TEST_CASE("[SceneTree][BoxContainer] HBoxContainer") {
43
HBoxContainer *hbox_container = memnew(HBoxContainer);
44
Window *root = SceneTree::get_singleton()->get_root();
45
root->add_child(hbox_container);
46
47
hbox_container->set_size(Size2(100, 100));
48
SceneTree::get_singleton()->process(0);
49
50
SUBCASE("Default behavior") {
51
Control *child_control = memnew(Control);
52
hbox_container->add_child(child_control);
53
SceneTree::get_singleton()->process(0);
54
55
CHECK_MESSAGE(
56
hbox_container->get_alignment() == BoxContainer::ALIGNMENT_BEGIN,
57
"HBoxContainer alignment is set to ALIGNMENT_BEGIN by default.");
58
59
CHECK_MESSAGE(
60
!hbox_container->is_vertical(),
61
"HBoxContainer orientation is horizontal.");
62
63
CHECK_MESSAGE(
64
child_control->get_position().is_equal_approx(Point2(0, 0)),
65
"Child control is aligned to the left in ALIGNMENT_BEGIN mode.");
66
67
CHECK_MESSAGE(
68
child_control->get_h_size_flags() == Control::SIZE_FILL,
69
"Child control horizontal size flags are set to SIZE_FILL by default.");
70
71
CHECK_MESSAGE(
72
child_control->get_v_size_flags() == Control::SIZE_FILL,
73
"Child control vertical size flags are set to SIZE_FILL by default.");
74
75
CHECK_MESSAGE(
76
child_control->get_size().is_equal_approx(Size2(0, 100)),
77
"Child control takes up minimum horizontal space and matches container height by default.");
78
79
memdelete(child_control);
80
}
81
82
SUBCASE("Child Horizontal Size Flags") {
83
Control *child_control = memnew(Control);
84
hbox_container->add_child(child_control);
85
child_control->set_custom_minimum_size(Size2(20, 20));
86
SceneTree::get_singleton()->process(0);
87
88
CHECK_MESSAGE(
89
child_control->get_position().is_equal_approx(Point2(0, 0)),
90
"Child control is aligned to the left by default with SIZE_FILL.");
91
92
child_control->set_h_size_flags(Control::SIZE_SHRINK_BEGIN);
93
SceneTree::get_singleton()->process(0);
94
95
CHECK_MESSAGE(
96
child_control->get_position().is_equal_approx(Point2(0, 0)),
97
"Child control is aligned to the left of in SIZE_SHRINK_BEGIN horizontal size flag mode.");
98
99
child_control->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
100
SceneTree::get_singleton()->process(0);
101
102
CHECK_MESSAGE(
103
child_control->get_position().is_equal_approx(Point2(0, 0)),
104
"Child control is aligned to the left of in SIZE_SHRINK_CENTER horizontal size flag mode.");
105
106
child_control->set_h_size_flags(Control::SIZE_SHRINK_END);
107
SceneTree::get_singleton()->process(0);
108
109
CHECK_MESSAGE(
110
child_control->get_position().is_equal_approx(Point2(0, 0)),
111
"Child control is aligned to the left of in SIZE_SHRINK_END horizontal size flag mode.");
112
113
child_control->set_h_size_flags(Control::SIZE_EXPAND | Control::SIZE_SHRINK_BEGIN);
114
SceneTree::get_singleton()->process(0);
115
116
CHECK_MESSAGE(
117
child_control->get_position().is_equal_approx(Point2(0, 0)),
118
"Child control is aligned to the left in SIZE_EXPAND | SIZE_SHRINK_BEGIN horizontal size flag mode.");
119
120
child_control->set_h_size_flags(Control::SIZE_EXPAND | Control::SIZE_SHRINK_CENTER);
121
SceneTree::get_singleton()->process(0);
122
123
CHECK_MESSAGE(
124
child_control->get_position().is_equal_approx(Point2(40, 0)),
125
"Child control is aligned to the center in SIZE_EXPAND | SIZE_SHRINK_CENTER horizontal size flag mode.");
126
127
child_control->set_h_size_flags(Control::SIZE_EXPAND | Control::SIZE_SHRINK_END);
128
SceneTree::get_singleton()->process(0);
129
130
CHECK_MESSAGE(
131
child_control->get_position().is_equal_approx(Point2(80, 0)),
132
"Child control is aligned to the right in SIZE_EXPAND | SIZE_SHRINK_END horizontal size flag mode.");
133
134
memdelete(child_control);
135
}
136
137
SUBCASE("Child Vertical Size Flags") {
138
Control *child_control = memnew(Control);
139
hbox_container->add_child(child_control);
140
SceneTree::get_singleton()->process(0);
141
142
CHECK_MESSAGE(
143
child_control->get_position().is_equal_approx(Point2(0, 0)),
144
"Child control is aligned to the top by default with SIZE_FILL.");
145
146
child_control->set_v_size_flags(Control::SIZE_SHRINK_BEGIN);
147
SceneTree::get_singleton()->process(0);
148
149
CHECK_MESSAGE(
150
child_control->get_position().is_equal_approx(Point2(0, 0)),
151
"Child control is aligned to the top of in SIZE_SHRINK_BEGIN vertical size flag mode.");
152
153
child_control->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
154
SceneTree::get_singleton()->process(0);
155
156
CHECK_MESSAGE(
157
child_control->get_position().is_equal_approx(Point2(0, 50)),
158
"Child control is aligned to the center of in SIZE_SHRINK_CENTER vertical size flag mode.");
159
160
child_control->set_v_size_flags(Control::SIZE_SHRINK_END);
161
SceneTree::get_singleton()->process(0);
162
163
CHECK_MESSAGE(
164
child_control->get_position().is_equal_approx(Point2(0, 100)),
165
"Child control is aligned to the bottom of in SIZE_SHRINK_END vertical size flag mode.");
166
167
memdelete(child_control);
168
}
169
170
SUBCASE("Child Alignment") {
171
Control *child_control = memnew(Control);
172
hbox_container->add_child(child_control);
173
SceneTree::get_singleton()->process(0);
174
175
CHECK_MESSAGE(
176
child_control->get_position().is_equal_approx(Point2(0, 0)),
177
"Child control is aligned to the left in ALIGNMENT_BEGIN mode by default.");
178
179
hbox_container->set_alignment(BoxContainer::ALIGNMENT_CENTER);
180
SceneTree::get_singleton()->process(0);
181
182
CHECK_MESSAGE(
183
child_control->get_position().is_equal_approx(Point2(50, 0)),
184
"Child control is aligned to the center in ALIGNMENT_CENTER mode.");
185
186
hbox_container->set_alignment(BoxContainer::ALIGNMENT_END);
187
SceneTree::get_singleton()->process(0);
188
189
CHECK_MESSAGE(
190
child_control->get_position().is_equal_approx(Point2(100, 0)),
191
"Child control is aligned to the right in ALIGNMENT_END mode.");
192
193
memdelete(child_control);
194
}
195
196
SUBCASE("Child Alignment RTL") {
197
Control *child_control = memnew(Control);
198
hbox_container->add_child(child_control);
199
hbox_container->set_layout_direction(Control::LAYOUT_DIRECTION_RTL);
200
SceneTree::get_singleton()->process(0);
201
202
CHECK_MESSAGE(
203
child_control->get_position().is_equal_approx(Point2(100, 0)),
204
"Child control is aligned to the right in RTL ALIGNMENT_BEGIN mode by default.");
205
206
hbox_container->set_alignment(BoxContainer::ALIGNMENT_CENTER);
207
SceneTree::get_singleton()->process(0);
208
209
CHECK_MESSAGE(
210
child_control->get_position().is_equal_approx(Point2(50, 0)),
211
"Child control is aligned to the center in RTL ALIGNMENT_CENTER mode.");
212
213
hbox_container->set_alignment(BoxContainer::ALIGNMENT_END);
214
SceneTree::get_singleton()->process(0);
215
216
CHECK_MESSAGE(
217
child_control->get_position().is_equal_approx(Point2(0, 0)),
218
"Child control is aligned to the right in RTL ALIGNMENT_END mode.");
219
220
memdelete(child_control);
221
}
222
223
SUBCASE("Child Separation") {
224
Control *child_control_1 = memnew(Control);
225
Control *child_control_2 = memnew(Control);
226
hbox_container->add_child(child_control_1);
227
hbox_container->add_child(child_control_2);
228
229
hbox_container->add_theme_constant_override("separation", 10);
230
SceneTree::get_singleton()->process(0);
231
232
CHECK_MESSAGE(
233
child_control_2->get_position().is_equal_approx(Point2(10, 0)),
234
"Child controls are separated by the specified separation value.");
235
236
memdelete(child_control_1);
237
memdelete(child_control_2);
238
}
239
240
SUBCASE("Spacers") {
241
Control *child_control_1 = memnew(Control);
242
Control *child_control_2 = memnew(Control);
243
hbox_container->add_child(child_control_1);
244
hbox_container->add_spacer();
245
hbox_container->add_child(child_control_2);
246
hbox_container->add_theme_constant_override("separation", 0);
247
SceneTree::get_singleton()->process(0);
248
249
CHECK_MESSAGE(
250
child_control_2->get_position().is_equal_approx(Point2(100, 0)),
251
"Spacer pushes child controls apart.");
252
253
memdelete(child_control_1);
254
memdelete(child_control_2);
255
}
256
257
SUBCASE("Expanding children") {
258
Control *child_control_1 = memnew(Control);
259
Control *child_control_2 = memnew(Control);
260
hbox_container->add_child(child_control_1);
261
hbox_container->add_child(child_control_2);
262
hbox_container->add_theme_constant_override("separation", 0);
263
264
child_control_1->set_h_size_flags(Control::SIZE_EXPAND_FILL);
265
SceneTree::get_singleton()->process(0);
266
267
CHECK_MESSAGE(
268
child_control_1->get_size().is_equal_approx(Size2(100, 100)),
269
"One child control expands to fill available space.");
270
271
CHECK_MESSAGE(
272
child_control_2->get_size().is_equal_approx(Size2(0, 100)),
273
"The non-expanding child control remains at minimum size.");
274
275
CHECK_MESSAGE(
276
child_control_1->get_position().is_equal_approx(Point2(0, 0)),
277
"Expanding child control is aligned to the left.");
278
279
CHECK_MESSAGE(
280
child_control_2->get_position().is_equal_approx(Point2(100, 0)),
281
"Non-expanding child control is positioned after the expanding child control.");
282
283
child_control_2->set_custom_minimum_size(Size2(20, 0));
284
SceneTree::get_singleton()->process(0);
285
286
CHECK_MESSAGE(
287
child_control_1->get_size().is_equal_approx(Size2(80, 100)),
288
"Expanding child control shrinks to accommodate the custom minimum size of the other child.");
289
290
CHECK_MESSAGE(
291
child_control_2->get_size().is_equal_approx(Size2(20, 100)),
292
"The non-expanding child control respects its custom minimum size.");
293
294
CHECK_MESSAGE(
295
child_control_1->get_position().is_equal_approx(Point2(0, 0)),
296
"Expanding child control is aligned to the left.");
297
298
CHECK_MESSAGE(
299
child_control_2->get_position().is_equal_approx(Point2(80, 0)),
300
"Non-expanding child control is positioned after the expanding child control.");
301
302
child_control_2->set_h_size_flags(Control::SIZE_EXPAND_FILL);
303
SceneTree::get_singleton()->process(0);
304
305
CHECK_MESSAGE(
306
child_control_1->get_size().is_equal_approx(Size2(50, 100)),
307
"Both child controls expand equally to fill available space.");
308
309
CHECK_MESSAGE(
310
child_control_2->get_size().is_equal_approx(Size2(50, 100)),
311
"Both child controls expand equally to fill available space.");
312
313
CHECK_MESSAGE(
314
child_control_1->get_position().is_equal_approx(Point2(0, 0)),
315
"First expanding child control is aligned to the left.");
316
317
CHECK_MESSAGE(
318
child_control_2->get_position().is_equal_approx(Point2(50, 0)),
319
"Second expanding child control is positioned after the first expanding child control.");
320
321
child_control_2->set_stretch_ratio(3);
322
SceneTree::get_singleton()->process(0);
323
324
CHECK_MESSAGE(
325
child_control_1->get_size().is_equal_approx(Size2(25, 100)),
326
"Child control with lower stretch ratio takes less space.");
327
328
CHECK_MESSAGE(
329
child_control_2->get_size().is_equal_approx(Size2(75, 100)),
330
"Child control with higher stretch ratio takes more space.");
331
332
CHECK_MESSAGE(
333
child_control_1->get_position().is_equal_approx(Point2(0, 0)),
334
"First expanding child control is aligned to the left.");
335
336
CHECK_MESSAGE(
337
child_control_2->get_position().is_equal_approx(Point2(25, 0)),
338
"Second expanding child control is positioned after the first expanding child control.");
339
340
memdelete(child_control_1);
341
memdelete(child_control_2);
342
}
343
344
memdelete(hbox_container);
345
}
346
347
TEST_CASE("[SceneTree][BoxContainer] VBoxContainer") {
348
VBoxContainer *vbox_container = memnew(VBoxContainer);
349
Window *root = SceneTree::get_singleton()->get_root();
350
root->add_child(vbox_container);
351
352
vbox_container->set_size(Size2(100, 100));
353
SceneTree::get_singleton()->process(0);
354
355
SUBCASE("Default behavior") {
356
Control *child_control = memnew(Control);
357
vbox_container->add_child(child_control);
358
SceneTree::get_singleton()->process(0);
359
360
CHECK_MESSAGE(
361
vbox_container->get_alignment() == BoxContainer::ALIGNMENT_BEGIN,
362
"HBoxContainer alignment is set to ALIGNMENT_BEGIN by default.");
363
364
CHECK_MESSAGE(
365
vbox_container->is_vertical(),
366
"VBoxContainer orientation is vertical.");
367
368
CHECK_MESSAGE(
369
child_control->get_position().is_equal_approx(Point2(0, 0)),
370
"Child control is aligned to the left in ALIGNMENT_BEGIN mode.");
371
372
CHECK_MESSAGE(
373
child_control->get_h_size_flags() == Control::SIZE_FILL,
374
"Child control horizontal size flags are set to SIZE_FILL by default.");
375
376
CHECK_MESSAGE(
377
child_control->get_v_size_flags() == Control::SIZE_FILL,
378
"Child control vertical size flags are set to SIZE_FILL by default.");
379
380
CHECK_MESSAGE(
381
child_control->get_size().is_equal_approx(Size2(100, 0)),
382
"Child control takes up minimum vertical space and matches container width by default.");
383
384
memdelete(child_control);
385
}
386
387
SUBCASE("Child Size Flags") {
388
Control *child_control = memnew(Control);
389
vbox_container->add_child(child_control);
390
child_control->set_custom_minimum_size(Size2(20, 20));
391
SceneTree::get_singleton()->process(0);
392
393
CHECK_MESSAGE(
394
child_control->get_position().is_equal_approx(Point2(0, 0)),
395
"Child control is aligned to the top by default with SIZE_FILL.");
396
397
child_control->set_v_size_flags(Control::SIZE_SHRINK_BEGIN);
398
SceneTree::get_singleton()->process(0);
399
400
CHECK_MESSAGE(
401
child_control->get_position().is_equal_approx(Point2(0, 0)),
402
"Child control is aligned to the top of in SIZE_SHRINK_BEGIN vertical size flag mode.");
403
404
child_control->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
405
SceneTree::get_singleton()->process(0);
406
407
CHECK_MESSAGE(
408
child_control->get_position().is_equal_approx(Point2(0, 0)),
409
"Child control is aligned to the top of in SIZE_SHRINK_CENTER vertical size flag mode.");
410
411
child_control->set_v_size_flags(Control::SIZE_SHRINK_END);
412
SceneTree::get_singleton()->process(0);
413
414
CHECK_MESSAGE(
415
child_control->get_position().is_equal_approx(Point2(0, 0)),
416
"Child control is aligned to the top of in SIZE_SHRINK_END vertical size flag mode.");
417
418
child_control->set_v_size_flags(Control::SIZE_EXPAND | Control::SIZE_SHRINK_BEGIN);
419
SceneTree::get_singleton()->process(0);
420
421
CHECK_MESSAGE(
422
child_control->get_position().is_equal_approx(Point2(0, 0)),
423
"Child control is aligned to the top in SIZE_EXPAND | SIZE_SHRINK_BEGIN vertical size flag mode.");
424
425
child_control->set_v_size_flags(Control::SIZE_EXPAND | Control::SIZE_SHRINK_CENTER);
426
SceneTree::get_singleton()->process(0);
427
428
CHECK_MESSAGE(
429
child_control->get_position().is_equal_approx(Point2(0, 40)),
430
"Child control is aligned to the center in SIZE_EXPAND | SIZE_SHRINK_CENTER vertical size flag mode.");
431
432
child_control->set_v_size_flags(Control::SIZE_EXPAND | Control::SIZE_SHRINK_END);
433
SceneTree::get_singleton()->process(0);
434
435
CHECK_MESSAGE(
436
child_control->get_position().is_equal_approx(Point2(0, 80)),
437
"Child control is aligned to the bottom in SIZE_EXPAND | SIZE_SHRINK_END vertical size flag mode.");
438
439
memdelete(child_control);
440
}
441
442
SUBCASE("Child Horizontal Size Flags") {
443
Control *child_control = memnew(Control);
444
vbox_container->add_child(child_control);
445
SceneTree::get_singleton()->process(0);
446
447
CHECK_MESSAGE(
448
child_control->get_position().is_equal_approx(Point2(0, 0)),
449
"Child control is aligned to the left by default with SIZE_FILL.");
450
451
child_control->set_h_size_flags(Control::SIZE_SHRINK_BEGIN);
452
SceneTree::get_singleton()->process(0);
453
454
CHECK_MESSAGE(
455
child_control->get_position().is_equal_approx(Point2(0, 0)),
456
"Child control is aligned to the left of in SIZE_SHRINK_BEGIN horizontal size flag mode.");
457
458
child_control->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
459
SceneTree::get_singleton()->process(0);
460
461
CHECK_MESSAGE(
462
child_control->get_position().is_equal_approx(Point2(50, 0)),
463
"Child control is aligned to the center of in SIZE_SHRINK_CENTER horizontal size flag mode.");
464
465
child_control->set_h_size_flags(Control::SIZE_SHRINK_END);
466
SceneTree::get_singleton()->process(0);
467
468
CHECK_MESSAGE(
469
child_control->get_position().is_equal_approx(Point2(100, 0)),
470
"Child control is aligned to the right of in SIZE_SHRINK_END horizontal size flag mode.");
471
472
memdelete(child_control);
473
}
474
475
SUBCASE("Child Alignment") {
476
Control *child_control = memnew(Control);
477
vbox_container->add_child(child_control);
478
SceneTree::get_singleton()->process(0);
479
480
CHECK_MESSAGE(
481
child_control->get_position().is_equal_approx(Point2(0, 0)),
482
"Child control is aligned to the top in ALIGNMENT_BEGIN mode by default.");
483
484
vbox_container->set_alignment(BoxContainer::ALIGNMENT_CENTER);
485
SceneTree::get_singleton()->process(0);
486
487
CHECK_MESSAGE(
488
child_control->get_position().is_equal_approx(Point2(0, 50)),
489
"Child control is aligned to the center in ALIGNMENT_CENTER mode.");
490
491
vbox_container->set_alignment(BoxContainer::ALIGNMENT_END);
492
SceneTree::get_singleton()->process(0);
493
494
CHECK_MESSAGE(
495
child_control->get_position().is_equal_approx(Point2(0, 100)),
496
"Child control is aligned to the bottom in ALIGNMENT_END mode.");
497
498
memdelete(child_control);
499
}
500
501
SUBCASE("Child Separation") {
502
Control *child_control_1 = memnew(Control);
503
Control *child_control_2 = memnew(Control);
504
vbox_container->add_child(child_control_1);
505
vbox_container->add_child(child_control_2);
506
507
vbox_container->add_theme_constant_override("separation", 10);
508
SceneTree::get_singleton()->process(0);
509
510
CHECK_MESSAGE(
511
child_control_2->get_position().is_equal_approx(Point2(0, 10)),
512
"Child controls are separated by the specified separation value.");
513
514
memdelete(child_control_1);
515
memdelete(child_control_2);
516
}
517
518
SUBCASE("Spacers") {
519
Control *child_control_1 = memnew(Control);
520
Control *child_control_2 = memnew(Control);
521
vbox_container->add_child(child_control_1);
522
vbox_container->add_spacer();
523
vbox_container->add_child(child_control_2);
524
vbox_container->add_theme_constant_override("separation", 0);
525
SceneTree::get_singleton()->process(0);
526
527
CHECK_MESSAGE(
528
child_control_2->get_position().is_equal_approx(Point2(0, 100)),
529
"Spacer pushes child controls apart.");
530
531
memdelete(child_control_1);
532
memdelete(child_control_2);
533
}
534
535
SUBCASE("Expanding children") {
536
Control *child_control_1 = memnew(Control);
537
Control *child_control_2 = memnew(Control);
538
vbox_container->add_child(child_control_1);
539
vbox_container->add_child(child_control_2);
540
vbox_container->add_theme_constant_override("separation", 0);
541
542
child_control_1->set_v_size_flags(Control::SIZE_EXPAND_FILL);
543
SceneTree::get_singleton()->process(0);
544
545
CHECK_MESSAGE(
546
child_control_1->get_size().is_equal_approx(Size2(100, 100)),
547
"One child control expands to fill available space.");
548
549
CHECK_MESSAGE(
550
child_control_2->get_size().is_equal_approx(Size2(100, 0)),
551
"The non-expanding child control remains at minimum size.");
552
553
CHECK_MESSAGE(
554
child_control_1->get_position().is_equal_approx(Point2(0, 0)),
555
"Expanding child control is aligned to the left.");
556
557
CHECK_MESSAGE(
558
child_control_2->get_position().is_equal_approx(Point2(0, 100)),
559
"Non-expanding child control is positioned after the expanding child control.");
560
561
child_control_2->set_custom_minimum_size(Size2(0, 20));
562
SceneTree::get_singleton()->process(0);
563
564
CHECK_MESSAGE(
565
child_control_1->get_size().is_equal_approx(Size2(100, 80)),
566
"Expanding child control shrinks to accommodate the custom minimum size of the other child.");
567
568
CHECK_MESSAGE(
569
child_control_2->get_size().is_equal_approx(Size2(100, 20)),
570
"The non-expanding child control respects its custom minimum size.");
571
572
CHECK_MESSAGE(
573
child_control_1->get_position().is_equal_approx(Point2(0, 0)),
574
"Expanding child control is aligned to the left.");
575
576
CHECK_MESSAGE(
577
child_control_2->get_position().is_equal_approx(Point2(0, 80)),
578
"Non-expanding child control is positioned after the expanding child control.");
579
580
child_control_2->set_v_size_flags(Control::SIZE_EXPAND_FILL);
581
SceneTree::get_singleton()->process(0);
582
583
CHECK_MESSAGE(
584
child_control_1->get_size().is_equal_approx(Size2(100, 50)),
585
"Both child controls expand equally to fill available space.");
586
587
CHECK_MESSAGE(
588
child_control_2->get_size().is_equal_approx(Size2(100, 50)),
589
"Both child controls expand equally to fill available space.");
590
591
CHECK_MESSAGE(
592
child_control_1->get_position().is_equal_approx(Point2(0, 0)),
593
"First expanding child control is aligned to the left.");
594
595
CHECK_MESSAGE(
596
child_control_2->get_position().is_equal_approx(Point2(0, 50)),
597
"Second expanding child control is positioned after the first expanding child control.");
598
599
child_control_2->set_stretch_ratio(3);
600
SceneTree::get_singleton()->process(0);
601
602
CHECK_MESSAGE(
603
child_control_1->get_size().is_equal_approx(Size2(100, 25)),
604
"Child control with lower stretch ratio takes less space.");
605
606
CHECK_MESSAGE(
607
child_control_2->get_size().is_equal_approx(Size2(100, 75)),
608
"Child control with higher stretch ratio takes more space.");
609
610
CHECK_MESSAGE(
611
child_control_1->get_position().is_equal_approx(Point2(0, 0)),
612
"First expanding child control is aligned to the left.");
613
614
CHECK_MESSAGE(
615
child_control_2->get_position().is_equal_approx(Point2(0, 25)),
616
"Second expanding child control is positioned after the first expanding child control.");
617
618
memdelete(child_control_1);
619
memdelete(child_control_2);
620
}
621
622
memdelete(vbox_container);
623
}
624
625
} // namespace TestBoxContainer
626
627