Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/tests/scene/test_split_container.cpp
45997 views
1
/**************************************************************************/
2
/* test_split_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_split_container)
34
35
#ifndef ADVANCED_GUI_DISABLED
36
37
#include "scene/gui/split_container.h"
38
#include "scene/main/scene_tree.h"
39
#include "scene/main/window.h"
40
#include "tests/display_server_mock.h"
41
#include "tests/signal_watcher.h"
42
43
namespace TestSplitContainer {
44
45
#define CHECK_RECTS(m_rects, m_child_rects) \
46
CHECK(m_rects.size() == m_child_rects.size()); \
47
for (int i = 0; i < (int)m_child_rects.size(); i++) { \
48
CHECK_MESSAGE(m_child_rects[i] == m_rects[i], vformat("Child %s is the wrong size. Child rect: %s, expected: %s.", i, m_child_rects[i], m_rects[i])); \
49
}
50
51
static inline Vector<Rect2> get_rects_multi(SplitContainer *p_sc, const Vector<int> &p_positions, int p_sep, bool p_horizontal = true) {
52
// p_positions is the top/left side of the dragger.
53
Vector<Rect2> rects;
54
int last_pos = 0;
55
for (int i = 0; i < (int)p_positions.size() + 1; i++) {
56
const int pos = i >= (int)p_positions.size() ? p_sc->get_size()[p_horizontal ? 0 : 1] : p_positions[i];
57
Rect2 rect;
58
if (p_horizontal) {
59
rect.size.y = p_sc->get_size().y;
60
rect.position.x = last_pos;
61
rect.size.x = pos - last_pos;
62
} else {
63
rect.size.x = p_sc->get_size().x;
64
rect.position.y = last_pos;
65
rect.size.y = pos - last_pos;
66
}
67
rects.push_back(rect);
68
last_pos = pos + p_sep;
69
}
70
return rects;
71
}
72
73
static inline Vector<Rect2> get_rects(SplitContainer *p_sc, int p_position, int p_sep, bool p_horizontal = true) {
74
return get_rects_multi(p_sc, Vector<int>({ p_position }), p_sep, p_horizontal);
75
}
76
77
static inline Vector<Rect2> get_rects_multi_rtl(SplitContainer *p_sc, const Vector<int> &p_positions, int p_sep) {
78
Vector<Rect2> rects;
79
int last_pos = p_sc->get_size().x;
80
for (int i = 0; i < (int)p_positions.size() + 1; i++) {
81
const int pos = i >= (int)p_positions.size() ? 0 : p_sc->get_size().x - p_positions[i];
82
Rect2 rect;
83
rect.size.y = p_sc->get_size().y;
84
rect.position.x = pos;
85
rect.size.x = last_pos - pos;
86
rects.push_back(rect);
87
last_pos = pos - p_sep;
88
}
89
return rects;
90
}
91
92
static inline Vector<Rect2> get_rects_rtl(SplitContainer *p_sc, int p_position, int p_sep) {
93
return get_rects_multi_rtl(p_sc, Vector<int>({ p_position }), p_sep);
94
}
95
96
static inline Vector<Rect2> get_child_rects(SplitContainer *p_sc) {
97
Vector<Rect2> rects;
98
for (int i = 0; i < p_sc->get_child_count(false); i++) {
99
Control *c = Object::cast_to<Control>(p_sc->get_child(i, false));
100
if (!c || !c->is_visible()) {
101
continue;
102
}
103
rects.push_back(c->get_rect());
104
}
105
return rects;
106
}
107
108
static inline void set_size_flags(SplitContainer *p_sc, Vector<float> p_expand_ratios, bool p_horizontal = true) {
109
for (int i = 0; i < p_sc->get_child_count(false); i++) {
110
Control *c = Object::cast_to<Control>(p_sc->get_child(i, false));
111
if (!c || !c->is_visible()) {
112
continue;
113
}
114
float ratio = p_expand_ratios[i];
115
if (p_horizontal) {
116
c->set_h_size_flags(ratio > 0 ? Control::SIZE_EXPAND_FILL : Control::SIZE_FILL);
117
} else {
118
c->set_v_size_flags(ratio > 0 ? Control::SIZE_EXPAND_FILL : Control::SIZE_FILL);
119
}
120
if (ratio > 0) {
121
c->set_stretch_ratio(ratio);
122
}
123
}
124
MessageQueue::get_singleton()->flush();
125
}
126
127
TEST_CASE("[SceneTree][SplitContainer] Add and remove children") {
128
SplitContainer *split_container = memnew(SplitContainer);
129
split_container->set_size(Size2(500, 500));
130
SceneTree::get_singleton()->get_root()->add_child(split_container);
131
132
SUBCASE("[SplitContainer] One child") {
133
Control *child_a = memnew(Control);
134
split_container->add_child(child_a);
135
MessageQueue::get_singleton()->flush();
136
137
// One child will fill the entire area.
138
CHECK(child_a->get_rect() == split_container->get_rect());
139
140
split_container->set_vertical(true);
141
CHECK(child_a->get_rect() == split_container->get_rect());
142
143
memdelete(child_a);
144
}
145
146
SUBCASE("[SplitContainer] Preserve split offset") {
147
// The split offset is preserved through adding, removing, and changing visibility of children.
148
split_container->set_split_offset(100);
149
CHECK(split_container->get_split_offset() == 100);
150
151
Control *child_a = memnew(Control);
152
split_container->add_child(child_a);
153
MessageQueue::get_singleton()->flush();
154
CHECK(split_container->get_split_offset() == 100);
155
156
Control *child_b = memnew(Control);
157
split_container->add_child(child_b);
158
MessageQueue::get_singleton()->flush();
159
CHECK(split_container->get_split_offset() == 100);
160
161
child_a->hide();
162
MessageQueue::get_singleton()->flush();
163
CHECK(split_container->get_split_offset() == 100);
164
165
child_b->hide();
166
MessageQueue::get_singleton()->flush();
167
CHECK(split_container->get_split_offset() == 100);
168
169
child_b->show();
170
MessageQueue::get_singleton()->flush();
171
CHECK(split_container->get_split_offset() == 100);
172
173
child_a->show();
174
MessageQueue::get_singleton()->flush();
175
CHECK(split_container->get_split_offset() == 100);
176
177
split_container->remove_child(child_a);
178
MessageQueue::get_singleton()->flush();
179
CHECK(split_container->get_split_offset() == 100);
180
181
split_container->add_child(child_a);
182
MessageQueue::get_singleton()->flush();
183
CHECK(split_container->get_split_offset() == 100);
184
185
memdelete(child_a);
186
memdelete(child_b);
187
}
188
189
memdelete(split_container);
190
}
191
192
TEST_CASE("[SceneTree][SplitContainer] Dragger visibility") {
193
SplitContainer *split_container = memnew(SplitContainer);
194
split_container->set_size(Size2(500, 500));
195
SceneTree::get_singleton()->get_root()->add_child(split_container);
196
Control *child_a = memnew(Control);
197
Control *child_b = memnew(Control);
198
split_container->add_child(child_a);
199
split_container->add_child(child_b);
200
SplitContainerDragger *dragger = Object::cast_to<SplitContainerDragger>(split_container->get_child(2, true));
201
202
split_container->add_theme_constant_override("autohide", 0);
203
MessageQueue::get_singleton()->flush();
204
205
const int sep_constant = split_container->get_theme_constant("separation");
206
const Size2i sep = Size2i(MAX(sep_constant, split_container->get_theme_icon("h_grabber")->get_width()), MAX(sep_constant, split_container->get_theme_icon("v_grabber")->get_height()));
207
208
SUBCASE("[SplitContainer] Visibility based on child count") {
209
split_container->remove_child(child_a);
210
split_container->remove_child(child_b);
211
MessageQueue::get_singleton()->flush();
212
213
// No children, not visible.
214
CHECK_FALSE(dragger->is_visible());
215
216
// Add one child, not visible.
217
split_container->add_child(child_a);
218
MessageQueue::get_singleton()->flush();
219
CHECK_FALSE(dragger->is_visible());
220
221
// Two children, visible.
222
split_container->add_child(child_b);
223
MessageQueue::get_singleton()->flush();
224
CHECK(dragger->is_visible());
225
226
// Remove a child, not visible.
227
split_container->remove_child(child_b);
228
MessageQueue::get_singleton()->flush();
229
CHECK_FALSE(dragger->is_visible());
230
}
231
232
SUBCASE("[SplitContainer] Set dragger visibility") {
233
split_container->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN);
234
MessageQueue::get_singleton()->flush();
235
CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
236
// Can't check the visibility since it happens in draw.
237
238
split_container->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN_COLLAPSED);
239
MessageQueue::get_singleton()->flush();
240
CHECK_RECTS(get_rects(split_container, 0, 0), get_child_rects(split_container));
241
242
split_container->set_dragger_visibility(SplitContainer::DRAGGER_VISIBLE);
243
MessageQueue::get_singleton()->flush();
244
CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
245
}
246
247
SUBCASE("[SplitContainer] Not visible when collapsed") {
248
split_container->set_collapsed(true);
249
MessageQueue::get_singleton()->flush();
250
CHECK_FALSE(dragger->is_visible());
251
252
split_container->set_collapsed(false);
253
MessageQueue::get_singleton()->flush();
254
CHECK(dragger->is_visible());
255
}
256
257
memdelete(child_a);
258
memdelete(child_b);
259
memdelete(split_container);
260
}
261
262
TEST_CASE("[SceneTree][SplitContainer] Collapsed") {
263
DisplayServerMock *DS = (DisplayServerMock *)(DisplayServer::get_singleton());
264
265
SplitContainer *split_container = memnew(SplitContainer);
266
split_container->set_size(Size2(500, 500));
267
SceneTree::get_singleton()->get_root()->add_child(split_container);
268
Control *child_a = memnew(Control);
269
split_container->add_child(child_a);
270
Control *child_b = memnew(Control);
271
split_container->add_child(child_b);
272
MessageQueue::get_singleton()->flush();
273
274
const int sep_constant = split_container->get_theme_constant("separation");
275
const Size2i sep = Size2i(MAX(sep_constant, split_container->get_theme_icon("h_grabber")->get_width()), MAX(sep_constant, split_container->get_theme_icon("v_grabber")->get_height()));
276
277
SUBCASE("[SplitContainer] Dragging and cursor") {
278
split_container->set_collapsed(true);
279
280
// Cursor is default.
281
SEND_GUI_MOUSE_MOTION_EVENT(Point2(1, 1), MouseButtonMask::NONE, Key::NONE);
282
CHECK(DS->get_cursor_shape() == DisplayServerEnums::CURSOR_ARROW);
283
284
// Dragger is disabled, cannot drag.
285
SEND_GUI_MOUSE_BUTTON_EVENT(Point2(1, 1), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
286
MessageQueue::get_singleton()->flush();
287
CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
288
CHECK(split_container->get_split_offset() == 0);
289
SEND_GUI_MOUSE_MOTION_EVENT(Point2(10, 1), MouseButtonMask::LEFT, Key::NONE);
290
MessageQueue::get_singleton()->flush();
291
CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
292
CHECK(split_container->get_split_offset() == 0);
293
}
294
295
SUBCASE("[SplitContainer] No expand flags") {
296
int def_pos = 0;
297
298
split_container->set_split_offset(10);
299
MessageQueue::get_singleton()->flush();
300
CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
301
302
split_container->set_collapsed(true);
303
MessageQueue::get_singleton()->flush();
304
305
// The split offset is treated as 0 when collapsed.
306
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
307
CHECK(split_container->get_split_offset() == 10);
308
}
309
310
SUBCASE("[SplitContainer] First child expanded") {
311
int def_pos = split_container->get_size().x - sep.x;
312
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
313
split_container->set_split_offset(-10);
314
MessageQueue::get_singleton()->flush();
315
316
CHECK_RECTS(get_rects(split_container, def_pos - 10, sep.x), get_child_rects(split_container));
317
318
split_container->set_collapsed(true);
319
MessageQueue::get_singleton()->flush();
320
321
// The split offset is treated as 0 when collapsed.
322
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
323
CHECK(split_container->get_split_offset() == -10);
324
}
325
326
SUBCASE("[SplitContainer] Second child expanded") {
327
int def_pos = 0;
328
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
329
split_container->set_split_offset(10);
330
MessageQueue::get_singleton()->flush();
331
332
CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
333
334
split_container->set_collapsed(true);
335
MessageQueue::get_singleton()->flush();
336
337
// The split offset is treated as 0 when collapsed.
338
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
339
CHECK(split_container->get_split_offset() == 10);
340
}
341
342
SUBCASE("[SplitContainer] Both children expanded") {
343
int def_pos = (split_container->get_size().y - sep.y) / 2;
344
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
345
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
346
split_container->set_split_offset(10);
347
MessageQueue::get_singleton()->flush();
348
349
CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
350
351
split_container->set_collapsed(true);
352
MessageQueue::get_singleton()->flush();
353
354
// The split offset is treated as 0 when collapsed.
355
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
356
CHECK(split_container->get_split_offset() == 10);
357
}
358
359
memdelete(child_a);
360
memdelete(child_b);
361
memdelete(split_container);
362
}
363
364
TEST_CASE("[SceneTree][SplitContainer] Cursor shape") {
365
DisplayServerMock *DS = (DisplayServerMock *)(DisplayServer::get_singleton());
366
367
SplitContainer *split_container = memnew(SplitContainer);
368
split_container->set_size(Size2(500, 500));
369
SceneTree::get_singleton()->get_root()->add_child(split_container);
370
Control *child_a = memnew(Control);
371
split_container->add_child(child_a);
372
Control *child_b = memnew(Control);
373
split_container->add_child(child_b);
374
MessageQueue::get_singleton()->flush();
375
376
Point2 on_dragger = Point2(1, 1);
377
Point2 not_on_dragger = Point2(50, 50);
378
379
// Default cursor shape.
380
SEND_GUI_MOUSE_MOTION_EVENT(not_on_dragger, MouseButtonMask::NONE, Key::NONE);
381
CHECK(DS->get_cursor_shape() == DisplayServerEnums::CURSOR_ARROW);
382
383
// Horizontal cursor shape.
384
SEND_GUI_MOUSE_MOTION_EVENT(on_dragger, MouseButtonMask::NONE, Key::NONE);
385
CHECK(DS->get_cursor_shape() == DisplayServerEnums::CURSOR_HSPLIT);
386
387
// Vertical cursor shape.
388
split_container->set_vertical(true);
389
SEND_GUI_MOUSE_MOTION_EVENT(on_dragger, MouseButtonMask::NONE, Key::NONE);
390
CHECK(DS->get_cursor_shape() == DisplayServerEnums::CURSOR_VSPLIT);
391
392
// Move off, default cursor shape.
393
SEND_GUI_MOUSE_MOTION_EVENT(not_on_dragger, MouseButtonMask::NONE, Key::NONE);
394
CHECK(DS->get_cursor_shape() == DisplayServerEnums::CURSOR_ARROW);
395
396
memdelete(child_a);
397
memdelete(child_b);
398
memdelete(split_container);
399
}
400
401
TEST_CASE("[SceneTree][SplitContainer] Two children") {
402
SplitContainer *split_container = memnew(SplitContainer);
403
split_container->set_size(Size2(500, 500));
404
SceneTree::get_singleton()->get_root()->add_child(split_container);
405
Control *child_a = memnew(Control);
406
Control *child_b = memnew(Control);
407
split_container->add_child(child_a);
408
split_container->add_child(child_b);
409
MessageQueue::get_singleton()->flush();
410
411
const int sep_constant = split_container->get_theme_constant("separation");
412
const Size2i sep = Size2i(MAX(sep_constant, split_container->get_theme_icon("h_grabber")->get_width()), MAX(sep_constant, split_container->get_theme_icon("v_grabber")->get_height()));
413
414
SUBCASE("[SplitContainer] Minimum size") {
415
// Minimum size is the sum of both children's minimum sizes and the separator depending on the vertical axis.
416
child_a->set_custom_minimum_size(Size2(100, 200));
417
child_b->set_custom_minimum_size(Size2(100, 200));
418
MessageQueue::get_singleton()->flush();
419
420
Size2 min_size = split_container->get_minimum_size();
421
CHECK(min_size.x == 200 + sep.x);
422
CHECK(min_size.y == 200);
423
424
split_container->set_vertical(true);
425
MessageQueue::get_singleton()->flush();
426
min_size = split_container->get_minimum_size();
427
CHECK(min_size.x == 100);
428
CHECK(min_size.y == 400 + sep.y);
429
}
430
431
SUBCASE("[SplitContainer] Default position") {
432
SUBCASE("[SplitContainer] Vertical") {
433
// Make sure clamping the split offset doesn't change it or the position.
434
split_container->set_vertical(true);
435
436
// No expand flags set.
437
MessageQueue::get_singleton()->flush();
438
int def_pos = 0;
439
CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
440
split_container->clamp_split_offset();
441
MessageQueue::get_singleton()->flush();
442
CHECK(split_container->get_split_offset() == 0);
443
CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
444
445
// First expand flags set.
446
child_a->set_v_size_flags(Control::SIZE_EXPAND_FILL);
447
child_b->set_v_size_flags(Control::SIZE_FILL);
448
MessageQueue::get_singleton()->flush();
449
def_pos = split_container->get_size().y - sep.y;
450
CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
451
split_container->clamp_split_offset();
452
MessageQueue::get_singleton()->flush();
453
CHECK(split_container->get_split_offset() == 0);
454
CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
455
456
// Second expand flags set.
457
child_a->set_v_size_flags(Control::SIZE_FILL);
458
child_b->set_v_size_flags(Control::SIZE_EXPAND_FILL);
459
MessageQueue::get_singleton()->flush();
460
def_pos = 0;
461
CHECK_RECTS(get_rects(split_container, 0, sep.y, false), get_child_rects(split_container));
462
split_container->clamp_split_offset();
463
MessageQueue::get_singleton()->flush();
464
CHECK(split_container->get_split_offset() == 0);
465
CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
466
467
// Both expand flags set.
468
child_a->set_v_size_flags(Control::SIZE_EXPAND_FILL);
469
child_b->set_v_size_flags(Control::SIZE_EXPAND_FILL);
470
MessageQueue::get_singleton()->flush();
471
def_pos = (split_container->get_size().y - sep.y) / 2;
472
CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
473
split_container->clamp_split_offset();
474
MessageQueue::get_singleton()->flush();
475
CHECK(split_container->get_split_offset() == 0);
476
CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
477
478
// Unequal stretch ratios.
479
child_a->set_stretch_ratio(2.0);
480
MessageQueue::get_singleton()->flush();
481
def_pos = (split_container->get_size().y * 2 / 3) - sep.y / 2;
482
CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
483
split_container->clamp_split_offset();
484
MessageQueue::get_singleton()->flush();
485
CHECK(split_container->get_split_offset() == 0);
486
CHECK_RECTS(get_rects(split_container, def_pos, sep.y, false), get_child_rects(split_container));
487
}
488
489
SUBCASE("[SplitContainer] Right to left") {
490
split_container->set_layout_direction(Control::LAYOUT_DIRECTION_RTL);
491
split_container->set_position(Point2(0, 0));
492
493
// No expand flags set.
494
MessageQueue::get_singleton()->flush();
495
int def_pos = 0;
496
CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
497
split_container->clamp_split_offset();
498
MessageQueue::get_singleton()->flush();
499
CHECK(split_container->get_split_offset() == 0);
500
CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
501
502
// First expand flags set.
503
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
504
child_b->set_h_size_flags(Control::SIZE_FILL);
505
MessageQueue::get_singleton()->flush();
506
def_pos = split_container->get_size().y - sep.y;
507
CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
508
split_container->clamp_split_offset();
509
MessageQueue::get_singleton()->flush();
510
CHECK(split_container->get_split_offset() == 0);
511
CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
512
513
// Second expand flags set.
514
child_a->set_h_size_flags(Control::SIZE_FILL);
515
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
516
MessageQueue::get_singleton()->flush();
517
def_pos = 0;
518
CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
519
split_container->clamp_split_offset();
520
MessageQueue::get_singleton()->flush();
521
CHECK(split_container->get_split_offset() == 0);
522
CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
523
524
// Both expand flags set.
525
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
526
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
527
MessageQueue::get_singleton()->flush();
528
def_pos = (split_container->get_size().y - sep.y) / 2;
529
CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
530
split_container->clamp_split_offset();
531
MessageQueue::get_singleton()->flush();
532
CHECK(split_container->get_split_offset() == 0);
533
CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
534
535
// Unequal stretch ratios.
536
child_a->set_stretch_ratio(2.0);
537
MessageQueue::get_singleton()->flush();
538
def_pos = (split_container->get_size().y * 2 / 3) - sep.y / 2;
539
CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
540
split_container->clamp_split_offset();
541
MessageQueue::get_singleton()->flush();
542
CHECK(split_container->get_split_offset() == 0);
543
CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
544
}
545
546
SUBCASE("[SplitContainer] No expand flags") {
547
int def_pos = 0;
548
549
CHECK(split_container->get_split_offset() == 0);
550
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
551
552
split_container->clamp_split_offset();
553
MessageQueue::get_singleton()->flush();
554
CHECK(split_container->get_split_offset() == 0);
555
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
556
557
// Minimum sizes affect default position.
558
559
// First child with minimum size.
560
child_a->set_custom_minimum_size(Size2(400, 0));
561
MessageQueue::get_singleton()->flush();
562
def_pos = 400;
563
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
564
split_container->clamp_split_offset();
565
MessageQueue::get_singleton()->flush();
566
CHECK(split_container->get_split_offset() == def_pos);
567
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
568
569
// Second child with minimum size.
570
child_a->set_custom_minimum_size(Size2(0, 0));
571
child_b->set_custom_minimum_size(Size2(400, 0));
572
MessageQueue::get_singleton()->flush();
573
def_pos = split_container->get_size().x - 400 - sep.x;
574
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
575
split_container->clamp_split_offset();
576
MessageQueue::get_singleton()->flush();
577
CHECK(split_container->get_split_offset() == def_pos);
578
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
579
580
// Both children with minimum size.
581
child_a->set_custom_minimum_size(Size2(200, 0));
582
child_b->set_custom_minimum_size(Size2(288, 0));
583
MessageQueue::get_singleton()->flush();
584
def_pos = 200;
585
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
586
split_container->clamp_split_offset();
587
MessageQueue::get_singleton()->flush();
588
CHECK(split_container->get_split_offset() == def_pos);
589
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
590
}
591
592
SUBCASE("[SplitContainer] First child expanded") {
593
const int def_pos = split_container->get_size().x - sep.x;
594
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
595
MessageQueue::get_singleton()->flush();
596
597
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
598
599
split_container->clamp_split_offset();
600
MessageQueue::get_singleton()->flush();
601
CHECK(split_container->get_split_offset() == 0);
602
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
603
604
// Minimum sizes affect default position.
605
606
// First child with minimum size.
607
child_a->set_custom_minimum_size(Size2(400, 0));
608
MessageQueue::get_singleton()->flush();
609
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
610
split_container->clamp_split_offset();
611
MessageQueue::get_singleton()->flush();
612
CHECK(split_container->get_split_offset() == 0);
613
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
614
615
// Second child with minimum size.
616
child_a->set_custom_minimum_size(Size2(0, 0));
617
child_b->set_custom_minimum_size(Size2(400, 0));
618
MessageQueue::get_singleton()->flush();
619
int pos = split_container->get_size().x - 400 - sep.x;
620
CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
621
split_container->clamp_split_offset();
622
MessageQueue::get_singleton()->flush();
623
CHECK(split_container->get_split_offset() == pos - def_pos);
624
CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
625
626
// Both children with minimum size.
627
child_a->set_custom_minimum_size(Size2(200, 0));
628
child_b->set_custom_minimum_size(Size2(288, 0));
629
MessageQueue::get_singleton()->flush();
630
pos = 200;
631
CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
632
split_container->clamp_split_offset();
633
MessageQueue::get_singleton()->flush();
634
CHECK(split_container->get_split_offset() == pos - def_pos);
635
CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
636
}
637
638
SUBCASE("[SplitContainer] Second child expanded") {
639
int def_pos = 0;
640
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
641
MessageQueue::get_singleton()->flush();
642
643
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
644
645
split_container->clamp_split_offset();
646
MessageQueue::get_singleton()->flush();
647
CHECK(split_container->get_split_offset() == 0);
648
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
649
650
// Minimum sizes affect default position.
651
652
// First child with minimum size.
653
child_a->set_custom_minimum_size(Size2(400, 0));
654
MessageQueue::get_singleton()->flush();
655
def_pos = 400;
656
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
657
split_container->clamp_split_offset();
658
MessageQueue::get_singleton()->flush();
659
CHECK(split_container->get_split_offset() == def_pos);
660
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
661
662
// Second child with minimum size.
663
child_a->set_custom_minimum_size(Size2(0, 0));
664
child_b->set_custom_minimum_size(Size2(400, 0));
665
MessageQueue::get_singleton()->flush();
666
def_pos = 500 - 400 - sep.x;
667
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
668
split_container->clamp_split_offset();
669
MessageQueue::get_singleton()->flush();
670
CHECK(split_container->get_split_offset() == def_pos);
671
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
672
673
// Both children with minimum size.
674
child_a->set_custom_minimum_size(Size2(200, 0));
675
child_b->set_custom_minimum_size(Size2(288, 0));
676
MessageQueue::get_singleton()->flush();
677
def_pos = 200;
678
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
679
split_container->clamp_split_offset();
680
MessageQueue::get_singleton()->flush();
681
CHECK(split_container->get_split_offset() == def_pos);
682
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
683
}
684
685
SUBCASE("[SplitContainer] Both children expanded") {
686
const int def_pos = (split_container->get_size().x - sep.x) / 2;
687
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
688
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
689
MessageQueue::get_singleton()->flush();
690
691
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
692
693
split_container->clamp_split_offset();
694
MessageQueue::get_singleton()->flush();
695
CHECK(split_container->get_split_offset() == 0);
696
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
697
698
// Minimum sizes affect default position.
699
700
// First child with minimum size.
701
child_a->set_custom_minimum_size(Size2(400, 0));
702
MessageQueue::get_singleton()->flush();
703
int pos = 400;
704
CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
705
split_container->clamp_split_offset();
706
MessageQueue::get_singleton()->flush();
707
CHECK(split_container->get_split_offset() == pos - def_pos);
708
CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
709
710
// Second child with minimum size.
711
child_a->set_custom_minimum_size(Size2(0, 0));
712
child_b->set_custom_minimum_size(Size2(400, 0));
713
MessageQueue::get_singleton()->flush();
714
pos = split_container->get_size().x - 400 - sep.x;
715
CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
716
split_container->clamp_split_offset();
717
MessageQueue::get_singleton()->flush();
718
CHECK(split_container->get_split_offset() == pos - def_pos);
719
CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
720
721
// Both children with minimum size.
722
child_a->set_custom_minimum_size(Size2(200, 0));
723
child_b->set_custom_minimum_size(Size2(288, 0));
724
MessageQueue::get_singleton()->flush();
725
pos = 200;
726
CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
727
split_container->clamp_split_offset();
728
MessageQueue::get_singleton()->flush();
729
CHECK(split_container->get_split_offset() == pos - def_pos);
730
CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
731
}
732
733
SUBCASE("[SplitContainer] Unequal stretch ratios") {
734
const int def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
735
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
736
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
737
child_a->set_stretch_ratio(2.0);
738
MessageQueue::get_singleton()->flush();
739
740
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
741
742
split_container->clamp_split_offset();
743
MessageQueue::get_singleton()->flush();
744
CHECK(split_container->get_split_offset() == 0);
745
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
746
747
// Minimum sizes affect default position.
748
749
// First child with minimum size.
750
child_a->set_custom_minimum_size(Size2(400, 0));
751
MessageQueue::get_singleton()->flush();
752
int pos = 400;
753
CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
754
split_container->clamp_split_offset();
755
MessageQueue::get_singleton()->flush();
756
CHECK(split_container->get_split_offset() == pos - def_pos);
757
CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
758
759
// Second child with minimum size.
760
child_a->set_custom_minimum_size(Size2(0, 0));
761
child_b->set_custom_minimum_size(Size2(400, 0));
762
MessageQueue::get_singleton()->flush();
763
pos = split_container->get_size().x - 400 - sep.x;
764
CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
765
split_container->clamp_split_offset();
766
MessageQueue::get_singleton()->flush();
767
CHECK(split_container->get_split_offset() == pos - def_pos);
768
CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
769
770
// Both children with minimum size.
771
child_a->set_custom_minimum_size(Size2(200, 0));
772
child_b->set_custom_minimum_size(Size2(288, 0));
773
MessageQueue::get_singleton()->flush();
774
pos = 200;
775
CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
776
split_container->clamp_split_offset();
777
MessageQueue::get_singleton()->flush();
778
CHECK(split_container->get_split_offset() == pos - def_pos);
779
CHECK_RECTS(get_rects(split_container, pos, sep.x), get_child_rects(split_container));
780
}
781
}
782
783
SUBCASE("[SplitContainer] Set split offset") {
784
SUBCASE("[SplitContainer] Right to left") {
785
split_container->set_layout_direction(Control::LAYOUT_DIRECTION_RTL);
786
split_container->set_position(Point2(0, 0));
787
int def_pos = 0;
788
// Positive.
789
split_container->set_split_offset(10);
790
MessageQueue::get_singleton()->flush();
791
CHECK(split_container->get_split_offset() == 10);
792
CHECK_RECTS(get_rects_rtl(split_container, def_pos + 10, sep.y), get_child_rects(split_container));
793
794
// Negative.
795
split_container->set_split_offset(-10);
796
MessageQueue::get_singleton()->flush();
797
CHECK(split_container->get_split_offset() == -10);
798
CHECK_RECTS(get_rects_rtl(split_container, def_pos, sep.y), get_child_rects(split_container));
799
}
800
801
SUBCASE("[SplitContainer] No expand flags") {
802
int def_pos = 0;
803
804
// Positive.
805
split_container->set_split_offset(10);
806
MessageQueue::get_singleton()->flush();
807
CHECK(split_container->get_split_offset() == 10);
808
CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
809
810
// Negative.
811
split_container->set_split_offset(-10);
812
MessageQueue::get_singleton()->flush();
813
CHECK(split_container->get_split_offset() == -10);
814
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
815
816
// Clamped.
817
split_container->set_split_offset(1000);
818
MessageQueue::get_singleton()->flush();
819
CHECK(split_container->get_split_offset() == 1000);
820
CHECK_RECTS(get_rects(split_container, split_container->get_size().x - sep.x, sep.x), get_child_rects(split_container));
821
}
822
823
SUBCASE("[SplitContainer] First child expanded") {
824
int def_pos = split_container->get_size().x - sep.x;
825
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
826
MessageQueue::get_singleton()->flush();
827
828
// Positive.
829
split_container->set_split_offset(10);
830
MessageQueue::get_singleton()->flush();
831
CHECK(split_container->get_split_offset() == 10);
832
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
833
834
// Negative.
835
split_container->set_split_offset(-10);
836
MessageQueue::get_singleton()->flush();
837
CHECK(split_container->get_split_offset() == -10);
838
CHECK_RECTS(get_rects(split_container, def_pos - 10, sep.x), get_child_rects(split_container));
839
840
// Clamped.
841
split_container->set_split_offset(-1000);
842
MessageQueue::get_singleton()->flush();
843
CHECK(split_container->get_split_offset() == -1000);
844
CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
845
}
846
847
SUBCASE("[SplitContainer] Second child expanded") {
848
int def_pos = 0;
849
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
850
MessageQueue::get_singleton()->flush();
851
852
// Positive.
853
split_container->set_split_offset(10);
854
MessageQueue::get_singleton()->flush();
855
CHECK(split_container->get_split_offset() == 10);
856
CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
857
858
// Negative.
859
split_container->set_split_offset(-10);
860
MessageQueue::get_singleton()->flush();
861
CHECK(split_container->get_split_offset() == -10);
862
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
863
864
// Clamped.
865
split_container->set_split_offset(1000);
866
MessageQueue::get_singleton()->flush();
867
CHECK(split_container->get_split_offset() == 1000);
868
CHECK_RECTS(get_rects(split_container, split_container->get_size().x - sep.x, sep.x), get_child_rects(split_container));
869
}
870
871
SUBCASE("[SplitContainer] Both children expanded") {
872
int def_pos = (split_container->get_size().x - sep.x) / 2;
873
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
874
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
875
MessageQueue::get_singleton()->flush();
876
877
// Positive.
878
split_container->set_split_offset(10);
879
MessageQueue::get_singleton()->flush();
880
CHECK(split_container->get_split_offset() == 10);
881
CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
882
883
// Negative.
884
split_container->set_split_offset(-10);
885
MessageQueue::get_singleton()->flush();
886
CHECK(split_container->get_split_offset() == -10);
887
CHECK_RECTS(get_rects(split_container, def_pos - 10, sep.x), get_child_rects(split_container));
888
889
// Clamped positive.
890
split_container->set_split_offset(1000);
891
MessageQueue::get_singleton()->flush();
892
CHECK(split_container->get_split_offset() == 1000);
893
CHECK_RECTS(get_rects(split_container, split_container->get_size().x - sep.x, sep.x), get_child_rects(split_container));
894
895
// Clamped negative.
896
split_container->set_split_offset(-1000);
897
MessageQueue::get_singleton()->flush();
898
CHECK(split_container->get_split_offset() == -1000);
899
CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
900
}
901
902
SUBCASE("[SplitContainer] Unequal stretch ratios") {
903
int def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
904
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
905
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
906
child_a->set_stretch_ratio(2.0);
907
MessageQueue::get_singleton()->flush();
908
909
// Positive.
910
split_container->set_split_offset(10);
911
MessageQueue::get_singleton()->flush();
912
CHECK(split_container->get_split_offset() == 10);
913
CHECK_RECTS(get_rects(split_container, def_pos + 10, sep.x), get_child_rects(split_container));
914
915
// Negative.
916
split_container->set_split_offset(-10);
917
MessageQueue::get_singleton()->flush();
918
CHECK(split_container->get_split_offset() == -10);
919
CHECK_RECTS(get_rects(split_container, def_pos - 10, sep.x), get_child_rects(split_container));
920
921
// Clamped positive.
922
split_container->set_split_offset(1000);
923
MessageQueue::get_singleton()->flush();
924
CHECK(split_container->get_split_offset() == 1000);
925
CHECK_RECTS(get_rects(split_container, split_container->get_size().x - sep.x, sep.x), get_child_rects(split_container));
926
927
// Clamped negative.
928
split_container->set_split_offset(-1000);
929
MessageQueue::get_singleton()->flush();
930
CHECK(split_container->get_split_offset() == -1000);
931
CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
932
}
933
}
934
935
SUBCASE("[SplitContainer] Keep split offset when changing minimum size") {
936
SUBCASE("[SplitContainer] No expand flags") {
937
int def_pos = 0;
938
939
split_container->set_split_offset(100);
940
child_a->set_custom_minimum_size(Size2(10, 0));
941
MessageQueue::get_singleton()->flush();
942
CHECK(split_container->get_split_offset() == 100);
943
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
944
945
child_a->set_custom_minimum_size(Size2(50, 0));
946
MessageQueue::get_singleton()->flush();
947
CHECK(split_container->get_split_offset() == 100);
948
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
949
}
950
951
SUBCASE("[SplitContainer] First child expanded") {
952
int def_pos = split_container->get_size().x - sep.x;
953
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
954
MessageQueue::get_singleton()->flush();
955
956
split_container->set_split_offset(-100);
957
child_b->set_custom_minimum_size(Size2(10, 0));
958
MessageQueue::get_singleton()->flush();
959
CHECK(split_container->get_split_offset() == -100);
960
CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
961
962
child_b->set_custom_minimum_size(Size2(50, 0));
963
MessageQueue::get_singleton()->flush();
964
CHECK(split_container->get_split_offset() == -100);
965
CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
966
}
967
968
SUBCASE("[SplitContainer] Second child expanded") {
969
int def_pos = 0;
970
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
971
MessageQueue::get_singleton()->flush();
972
973
split_container->set_split_offset(100);
974
child_a->set_custom_minimum_size(Size2(10, 0));
975
MessageQueue::get_singleton()->flush();
976
CHECK(split_container->get_split_offset() == 100);
977
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
978
979
child_a->set_custom_minimum_size(Size2(50, 0));
980
MessageQueue::get_singleton()->flush();
981
CHECK(split_container->get_split_offset() == 100);
982
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
983
}
984
985
SUBCASE("[SplitContainer] Both children expanded") {
986
int def_pos = (split_container->get_size().x - sep.x) / 2;
987
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
988
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
989
MessageQueue::get_singleton()->flush();
990
991
split_container->set_split_offset(20);
992
child_a->set_custom_minimum_size(Size2(10, 0));
993
child_b->set_custom_minimum_size(Size2(10, 0));
994
MessageQueue::get_singleton()->flush();
995
CHECK(split_container->get_split_offset() == 20);
996
CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
997
998
child_a->set_custom_minimum_size(Size2(50, 0));
999
child_b->set_custom_minimum_size(Size2(50, 0));
1000
MessageQueue::get_singleton()->flush();
1001
CHECK(split_container->get_split_offset() == 20);
1002
CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
1003
}
1004
}
1005
1006
SUBCASE("[SplitContainer] Keep split offset when changing visibility") {
1007
SUBCASE("[SplitContainer] No expand flags") {
1008
int def_pos = 0;
1009
split_container->set_split_offset(100);
1010
1011
child_a->hide();
1012
MessageQueue::get_singleton()->flush();
1013
CHECK(split_container->get_split_offset() == 100);
1014
CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
1015
1016
child_b->hide();
1017
MessageQueue::get_singleton()->flush();
1018
CHECK(split_container->get_split_offset() == 100);
1019
1020
child_a->show();
1021
MessageQueue::get_singleton()->flush();
1022
CHECK(split_container->get_split_offset() == 100);
1023
CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
1024
1025
child_b->show();
1026
MessageQueue::get_singleton()->flush();
1027
CHECK(split_container->get_split_offset() == 100);
1028
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
1029
}
1030
1031
SUBCASE("[SplitContainer] First child expanded") {
1032
int def_pos = split_container->get_size().x - sep.x;
1033
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1034
MessageQueue::get_singleton()->flush();
1035
split_container->set_split_offset(-100);
1036
1037
child_a->hide();
1038
MessageQueue::get_singleton()->flush();
1039
CHECK(split_container->get_split_offset() == -100);
1040
CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
1041
1042
child_b->hide();
1043
MessageQueue::get_singleton()->flush();
1044
CHECK(split_container->get_split_offset() == -100);
1045
1046
child_a->show();
1047
MessageQueue::get_singleton()->flush();
1048
CHECK(split_container->get_split_offset() == -100);
1049
CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
1050
1051
child_b->show();
1052
MessageQueue::get_singleton()->flush();
1053
CHECK(split_container->get_split_offset() == -100);
1054
CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
1055
}
1056
1057
SUBCASE("[SplitContainer] Second child expanded") {
1058
int def_pos = 0;
1059
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1060
MessageQueue::get_singleton()->flush();
1061
split_container->set_split_offset(100);
1062
1063
child_a->hide();
1064
MessageQueue::get_singleton()->flush();
1065
CHECK(split_container->get_split_offset() == 100);
1066
CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
1067
1068
child_b->hide();
1069
MessageQueue::get_singleton()->flush();
1070
CHECK(split_container->get_split_offset() == 100);
1071
1072
child_a->show();
1073
MessageQueue::get_singleton()->flush();
1074
CHECK(split_container->get_split_offset() == 100);
1075
CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
1076
1077
child_b->show();
1078
MessageQueue::get_singleton()->flush();
1079
CHECK(split_container->get_split_offset() == 100);
1080
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
1081
}
1082
1083
SUBCASE("[SplitContainer] Both children expanded") {
1084
int def_pos = (split_container->get_size().x - sep.x) / 2;
1085
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1086
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1087
MessageQueue::get_singleton()->flush();
1088
split_container->set_split_offset(20);
1089
1090
child_a->hide();
1091
MessageQueue::get_singleton()->flush();
1092
CHECK(split_container->get_split_offset() == 20);
1093
CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
1094
1095
child_b->hide();
1096
MessageQueue::get_singleton()->flush();
1097
CHECK(split_container->get_split_offset() == 20);
1098
1099
child_a->show();
1100
MessageQueue::get_singleton()->flush();
1101
CHECK(split_container->get_split_offset() == 20);
1102
CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
1103
1104
child_b->show();
1105
MessageQueue::get_singleton()->flush();
1106
CHECK(split_container->get_split_offset() == 20);
1107
CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
1108
}
1109
}
1110
1111
SUBCASE("[SplitContainer] Keep split offset when removing children") {
1112
SUBCASE("[SplitContainer] No expand flags") {
1113
int def_pos = 0;
1114
split_container->set_split_offset(100);
1115
1116
split_container->remove_child(child_a);
1117
MessageQueue::get_singleton()->flush();
1118
CHECK(split_container->get_split_offset() == 100);
1119
CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
1120
1121
split_container->remove_child(child_b);
1122
MessageQueue::get_singleton()->flush();
1123
CHECK(split_container->get_split_offset() == 100);
1124
1125
split_container->add_child(child_a);
1126
MessageQueue::get_singleton()->flush();
1127
CHECK(split_container->get_split_offset() == 100);
1128
CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
1129
1130
split_container->add_child(child_b);
1131
MessageQueue::get_singleton()->flush();
1132
CHECK(split_container->get_split_offset() == 100);
1133
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
1134
}
1135
1136
SUBCASE("[SplitContainer] First child expanded") {
1137
int def_pos = split_container->get_size().x - sep.x;
1138
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1139
MessageQueue::get_singleton()->flush();
1140
split_container->set_split_offset(-100);
1141
1142
split_container->remove_child(child_a);
1143
MessageQueue::get_singleton()->flush();
1144
CHECK(split_container->get_split_offset() == -100);
1145
CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
1146
1147
split_container->remove_child(child_b);
1148
MessageQueue::get_singleton()->flush();
1149
CHECK(split_container->get_split_offset() == -100);
1150
1151
split_container->add_child(child_a);
1152
MessageQueue::get_singleton()->flush();
1153
CHECK(split_container->get_split_offset() == -100);
1154
CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
1155
1156
split_container->add_child(child_b);
1157
MessageQueue::get_singleton()->flush();
1158
CHECK(split_container->get_split_offset() == -100);
1159
CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
1160
}
1161
1162
SUBCASE("[SplitContainer] Second child expanded") {
1163
int def_pos = 0;
1164
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1165
MessageQueue::get_singleton()->flush();
1166
split_container->set_split_offset(100);
1167
1168
split_container->remove_child(child_a);
1169
MessageQueue::get_singleton()->flush();
1170
CHECK(split_container->get_split_offset() == 100);
1171
CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
1172
1173
split_container->remove_child(child_b);
1174
MessageQueue::get_singleton()->flush();
1175
CHECK(split_container->get_split_offset() == 100);
1176
1177
split_container->add_child(child_a);
1178
MessageQueue::get_singleton()->flush();
1179
CHECK(split_container->get_split_offset() == 100);
1180
CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
1181
1182
split_container->add_child(child_b);
1183
MessageQueue::get_singleton()->flush();
1184
CHECK(split_container->get_split_offset() == 100);
1185
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
1186
}
1187
1188
SUBCASE("[SplitContainer] Both children expanded") {
1189
int def_pos = (split_container->get_size().x - sep.x) / 2;
1190
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1191
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1192
MessageQueue::get_singleton()->flush();
1193
split_container->set_split_offset(20);
1194
1195
split_container->remove_child(child_a);
1196
MessageQueue::get_singleton()->flush();
1197
CHECK(split_container->get_split_offset() == 20);
1198
CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
1199
1200
split_container->remove_child(child_b);
1201
MessageQueue::get_singleton()->flush();
1202
CHECK(split_container->get_split_offset() == 20);
1203
1204
split_container->add_child(child_a);
1205
MessageQueue::get_singleton()->flush();
1206
CHECK(split_container->get_split_offset() == 20);
1207
CHECK_RECTS(get_rects_multi(split_container, Vector<int>(), sep.x), get_child_rects(split_container));
1208
1209
split_container->add_child(child_b);
1210
MessageQueue::get_singleton()->flush();
1211
CHECK(split_container->get_split_offset() == 20);
1212
CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
1213
}
1214
}
1215
1216
SUBCASE("[SplitContainer] Keep split offset when changing expand flags") {
1217
int def_pos = 0;
1218
split_container->set_split_offset(20);
1219
MessageQueue::get_singleton()->flush();
1220
CHECK(split_container->get_split_offset() == 20);
1221
CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
1222
1223
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1224
def_pos = split_container->get_size().x - sep.x;
1225
MessageQueue::get_singleton()->flush();
1226
CHECK(split_container->get_split_offset() == 20);
1227
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
1228
1229
child_a->set_h_size_flags(Control::SIZE_FILL);
1230
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1231
def_pos = 0;
1232
MessageQueue::get_singleton()->flush();
1233
CHECK(split_container->get_split_offset() == 20);
1234
CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
1235
1236
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1237
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1238
def_pos = (split_container->get_size().x - sep.x) / 2;
1239
MessageQueue::get_singleton()->flush();
1240
CHECK(split_container->get_split_offset() == 20);
1241
CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
1242
1243
child_a->set_h_size_flags(Control::SIZE_FILL);
1244
child_b->set_h_size_flags(Control::SIZE_FILL);
1245
def_pos = 0;
1246
MessageQueue::get_singleton()->flush();
1247
CHECK(split_container->get_split_offset() == 20);
1248
CHECK_RECTS(get_rects(split_container, def_pos + 20, sep.x), get_child_rects(split_container));
1249
}
1250
1251
SUBCASE("[SplitContainer] Keep split offset when moving children") {
1252
int def_pos = 0;
1253
split_container->set_split_offset(100);
1254
1255
split_container->move_child(child_a, 1);
1256
MessageQueue::get_singleton()->flush();
1257
CHECK(split_container->get_split_offset() == 100);
1258
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
1259
}
1260
1261
SUBCASE("[SplitContainer] Resize split container") {
1262
SUBCASE("[SplitContainer] No expand flags") {
1263
int def_pos = 0;
1264
// Increase the size.
1265
split_container->set_size(Size2(600, 500));
1266
MessageQueue::get_singleton()->flush();
1267
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
1268
1269
// Decrease the size.
1270
split_container->set_size(Size2(400, 500));
1271
MessageQueue::get_singleton()->flush();
1272
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
1273
1274
// Change size with a split offset.
1275
split_container->set_split_offset(100);
1276
MessageQueue::get_singleton()->flush();
1277
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
1278
1279
split_container->set_size(Size2(500, 500));
1280
MessageQueue::get_singleton()->flush();
1281
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
1282
CHECK(split_container->get_split_offset() == 100);
1283
1284
// Change size so that the first child changes size.
1285
split_container->set_size(Size2(80, 500));
1286
MessageQueue::get_singleton()->flush();
1287
CHECK_RECTS(get_rects(split_container, 80 - sep.x, sep.x), get_child_rects(split_container));
1288
CHECK(split_container->get_split_offset() == 100);
1289
1290
// Increase size again.
1291
split_container->set_size(Size2(500, 500));
1292
MessageQueue::get_singleton()->flush();
1293
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
1294
CHECK(split_container->get_split_offset() == 100);
1295
}
1296
1297
SUBCASE("[SplitContainer] First child expanded") {
1298
int def_pos = split_container->get_size().x - sep.x;
1299
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1300
MessageQueue::get_singleton()->flush();
1301
1302
// Increase the size.
1303
split_container->set_size(Size2(600, 500));
1304
def_pos = split_container->get_size().x - sep.x;
1305
MessageQueue::get_singleton()->flush();
1306
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
1307
1308
// Decrease the size.
1309
split_container->set_size(Size2(400, 500));
1310
def_pos = split_container->get_size().x - sep.x;
1311
MessageQueue::get_singleton()->flush();
1312
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
1313
1314
// Change size with a split offset.
1315
split_container->set_split_offset(-100);
1316
MessageQueue::get_singleton()->flush();
1317
CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
1318
1319
split_container->set_size(Size2(500, 500));
1320
def_pos = split_container->get_size().x - sep.x;
1321
MessageQueue::get_singleton()->flush();
1322
CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
1323
CHECK(split_container->get_split_offset() == -100);
1324
1325
// Change size so that the second child changes size.
1326
split_container->set_size(Size2(80, 500));
1327
MessageQueue::get_singleton()->flush();
1328
CHECK_RECTS(get_rects(split_container, 0, sep.x), get_child_rects(split_container));
1329
CHECK(split_container->get_split_offset() == -100);
1330
1331
// Increase size again.
1332
split_container->set_size(Size2(500, 500));
1333
MessageQueue::get_singleton()->flush();
1334
CHECK_RECTS(get_rects(split_container, def_pos - 100, sep.x), get_child_rects(split_container));
1335
CHECK(split_container->get_split_offset() == -100);
1336
}
1337
1338
SUBCASE("[SplitContainer] Second child expanded") {
1339
int def_pos = 0;
1340
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1341
MessageQueue::get_singleton()->flush();
1342
1343
// Increase the size.
1344
split_container->set_size(Size2(600, 500));
1345
MessageQueue::get_singleton()->flush();
1346
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
1347
1348
// Decrease the size.
1349
split_container->set_size(Size2(400, 500));
1350
MessageQueue::get_singleton()->flush();
1351
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
1352
1353
// Change size with a split offset.
1354
split_container->set_split_offset(100);
1355
MessageQueue::get_singleton()->flush();
1356
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
1357
1358
split_container->set_size(Size2(500, 500));
1359
MessageQueue::get_singleton()->flush();
1360
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
1361
CHECK(split_container->get_split_offset() == 100);
1362
1363
// Change size so that the first child changes size.
1364
split_container->set_size(Size2(80, 500));
1365
MessageQueue::get_singleton()->flush();
1366
CHECK_RECTS(get_rects(split_container, 80 - sep.x, sep.x), get_child_rects(split_container));
1367
CHECK(split_container->get_split_offset() == 100);
1368
1369
// Increase size again.
1370
split_container->set_size(Size2(500, 500));
1371
MessageQueue::get_singleton()->flush();
1372
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
1373
CHECK(split_container->get_split_offset() == 100);
1374
}
1375
1376
SUBCASE("[SplitContainer] Both children expanded") {
1377
int def_pos = (split_container->get_size().x - sep.x) / 2;
1378
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1379
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1380
MessageQueue::get_singleton()->flush();
1381
1382
// Increase the size.
1383
split_container->set_size(Size2(600, 500));
1384
def_pos = (split_container->get_size().x - sep.x) / 2;
1385
MessageQueue::get_singleton()->flush();
1386
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
1387
1388
// Decrease the size.
1389
split_container->set_size(Size2(400, 500));
1390
def_pos = (split_container->get_size().x - sep.x) / 2;
1391
MessageQueue::get_singleton()->flush();
1392
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
1393
1394
// Change size with a split offset.
1395
split_container->set_split_offset(100);
1396
MessageQueue::get_singleton()->flush();
1397
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
1398
1399
split_container->set_size(Size2(500, 500));
1400
def_pos = (split_container->get_size().x - sep.x) / 2;
1401
MessageQueue::get_singleton()->flush();
1402
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
1403
CHECK(split_container->get_split_offset() == 100);
1404
1405
// Change size so that the second child is minimized.
1406
split_container->set_size(Size2(80, 500));
1407
MessageQueue::get_singleton()->flush();
1408
CHECK_RECTS(get_rects(split_container, 80 - sep.x, sep.x), get_child_rects(split_container));
1409
CHECK(split_container->get_split_offset() == 100);
1410
1411
// Increase size again.
1412
split_container->set_size(Size2(500, 500));
1413
def_pos = (split_container->get_size().x - sep.x) / 2;
1414
MessageQueue::get_singleton()->flush();
1415
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
1416
CHECK(split_container->get_split_offset() == 100);
1417
}
1418
1419
SUBCASE("[SplitContainer] Unequal stretch ratios") {
1420
int def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
1421
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1422
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1423
child_a->set_stretch_ratio(2.0);
1424
MessageQueue::get_singleton()->flush();
1425
1426
// Increase the size.
1427
split_container->set_size(Size2(600, 500));
1428
def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
1429
MessageQueue::get_singleton()->flush();
1430
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
1431
1432
// Decrease the size.
1433
split_container->set_size(Size2(400, 500));
1434
def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
1435
MessageQueue::get_singleton()->flush();
1436
CHECK_RECTS(get_rects(split_container, def_pos, sep.x), get_child_rects(split_container));
1437
1438
// Change size with a split offset.
1439
split_container->set_split_offset(100);
1440
MessageQueue::get_singleton()->flush();
1441
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
1442
1443
split_container->set_size(Size2(500, 500));
1444
def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
1445
MessageQueue::get_singleton()->flush();
1446
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
1447
CHECK(split_container->get_split_offset() == 100);
1448
1449
// Change size so that the second child is minimized.
1450
split_container->set_size(Size2(80, 500));
1451
MessageQueue::get_singleton()->flush();
1452
CHECK_RECTS(get_rects(split_container, 80 - sep.x, sep.x), get_child_rects(split_container));
1453
CHECK(split_container->get_split_offset() == 100);
1454
1455
// Increase size again.
1456
split_container->set_size(Size2(500, 500));
1457
def_pos = (split_container->get_size().x * 2 / 3) - sep.x / 2;
1458
MessageQueue::get_singleton()->flush();
1459
CHECK_RECTS(get_rects(split_container, def_pos + 100, sep.x), get_child_rects(split_container));
1460
CHECK(split_container->get_split_offset() == 100);
1461
}
1462
}
1463
1464
SUBCASE("[SplitContainer] Drag") {
1465
SUBCASE("[SplitContainer] Vertical, no expand flags") {
1466
SIGNAL_WATCH(split_container, "dragged");
1467
Array signal_args = { { 0 } };
1468
1469
split_container->set_vertical(true);
1470
Point2 mouse_offset = Point2(1, 1);
1471
int dragger_pos = 0;
1472
int split_dragger_ofs = 0;
1473
1474
// Grab the dragger.
1475
SEND_GUI_MOUSE_BUTTON_EVENT(mouse_offset + Point2(0, dragger_pos), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
1476
MessageQueue::get_singleton()->flush();
1477
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
1478
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1479
SIGNAL_CHECK_FALSE("dragged");
1480
1481
// Move the dragger.
1482
dragger_pos = 10;
1483
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(0, dragger_pos), MouseButtonMask::LEFT, Key::NONE);
1484
MessageQueue::get_singleton()->flush();
1485
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
1486
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1487
// It is clamped.
1488
split_container->clamp_split_offset();
1489
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1490
((Array)signal_args[0])[0] = split_container->get_split_offset();
1491
SIGNAL_CHECK("dragged", signal_args);
1492
1493
// Move down.
1494
dragger_pos = 400;
1495
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(0, dragger_pos), MouseButtonMask::LEFT, Key::NONE);
1496
MessageQueue::get_singleton()->flush();
1497
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
1498
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1499
((Array)signal_args[0])[0] = split_container->get_split_offset();
1500
SIGNAL_CHECK("dragged", signal_args);
1501
1502
// Moves even when mouse is outside.
1503
dragger_pos = split_container->get_size().y - sep.y;
1504
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(0, 1000), MouseButtonMask::LEFT, Key::NONE);
1505
MessageQueue::get_singleton()->flush();
1506
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
1507
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1508
((Array)signal_args[0])[0] = split_container->get_split_offset();
1509
SIGNAL_CHECK("dragged", signal_args);
1510
1511
// Move up.
1512
dragger_pos = 100;
1513
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(0, dragger_pos), MouseButtonMask::LEFT, Key::NONE);
1514
MessageQueue::get_singleton()->flush();
1515
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
1516
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1517
((Array)signal_args[0])[0] = split_container->get_split_offset();
1518
SIGNAL_CHECK("dragged", signal_args);
1519
1520
// Release.
1521
SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(mouse_offset + Point2(0, dragger_pos), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
1522
MessageQueue::get_singleton()->flush();
1523
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
1524
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1525
SIGNAL_CHECK_FALSE("dragged");
1526
1527
// No longer moves with the mouse.
1528
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(0, 200), MouseButtonMask::NONE, Key::NONE);
1529
MessageQueue::get_singleton()->flush();
1530
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.y, false), get_child_rects(split_container));
1531
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1532
SIGNAL_CHECK_FALSE("dragged");
1533
1534
SIGNAL_UNWATCH(split_container, "dragged");
1535
}
1536
1537
SUBCASE("[SplitContainer] No expand flags") {
1538
Point2 mouse_offset = Point2(1, 1);
1539
int dragger_pos = 0;
1540
int split_dragger_ofs = 0;
1541
1542
// Grab the dragger.
1543
SEND_GUI_MOUSE_BUTTON_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
1544
MessageQueue::get_singleton()->flush();
1545
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1546
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1547
1548
// Move the dragger.
1549
dragger_pos = 10;
1550
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1551
MessageQueue::get_singleton()->flush();
1552
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1553
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1554
// It is clamped.
1555
split_container->clamp_split_offset();
1556
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1557
1558
// Continue moving.
1559
dragger_pos = 400;
1560
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1561
MessageQueue::get_singleton()->flush();
1562
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1563
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1564
1565
// Moves even when mouse is outside.
1566
dragger_pos = split_container->get_size().x - sep.x;
1567
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(1000, 0), MouseButtonMask::LEFT, Key::NONE);
1568
MessageQueue::get_singleton()->flush();
1569
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1570
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1571
1572
// Move back in.
1573
dragger_pos = 100;
1574
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1575
MessageQueue::get_singleton()->flush();
1576
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1577
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1578
1579
// Release.
1580
SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
1581
MessageQueue::get_singleton()->flush();
1582
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1583
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1584
1585
// No longer moves with the mouse.
1586
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(200, 0), MouseButtonMask::NONE, Key::NONE);
1587
MessageQueue::get_singleton()->flush();
1588
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1589
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1590
}
1591
1592
SUBCASE("[SplitContainer] First child expanded") {
1593
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1594
MessageQueue::get_singleton()->flush();
1595
Point2 mouse_offset = Point2(1, 1);
1596
int dragger_pos = split_container->get_size().x - sep.x;
1597
int split_dragger_ofs = -dragger_pos;
1598
1599
// Grab the dragger.
1600
SEND_GUI_MOUSE_BUTTON_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
1601
MessageQueue::get_singleton()->flush();
1602
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1603
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1604
1605
// Move the dragger.
1606
dragger_pos -= 10;
1607
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1608
MessageQueue::get_singleton()->flush();
1609
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1610
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1611
// It is clamped.
1612
split_container->clamp_split_offset();
1613
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1614
1615
// Continue moving.
1616
dragger_pos = 400;
1617
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1618
MessageQueue::get_singleton()->flush();
1619
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1620
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1621
1622
// Moves even when mouse is outside.
1623
dragger_pos = split_container->get_size().x - sep.x;
1624
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(1000, 0), MouseButtonMask::LEFT, Key::NONE);
1625
MessageQueue::get_singleton()->flush();
1626
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1627
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1628
1629
// Move back in.
1630
dragger_pos = 100;
1631
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1632
MessageQueue::get_singleton()->flush();
1633
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1634
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1635
1636
// Release.
1637
SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
1638
MessageQueue::get_singleton()->flush();
1639
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1640
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1641
1642
// No longer moves with the mouse.
1643
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(200, 0), MouseButtonMask::NONE, Key::NONE);
1644
MessageQueue::get_singleton()->flush();
1645
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1646
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1647
}
1648
1649
SUBCASE("[SplitContainer] Second child expanded") {
1650
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1651
MessageQueue::get_singleton()->flush();
1652
Point2 mouse_offset = Point2(1, 1);
1653
int dragger_pos = 0;
1654
int split_dragger_ofs = 0;
1655
1656
// Grab the dragger.
1657
SEND_GUI_MOUSE_BUTTON_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
1658
MessageQueue::get_singleton()->flush();
1659
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1660
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1661
1662
// Move the dragger.
1663
dragger_pos = 10;
1664
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1665
MessageQueue::get_singleton()->flush();
1666
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1667
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1668
// It is clamped.
1669
split_container->clamp_split_offset();
1670
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1671
1672
// Continue moving.
1673
dragger_pos = 400;
1674
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1675
MessageQueue::get_singleton()->flush();
1676
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1677
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1678
1679
// Moves even when mouse is outside.
1680
dragger_pos = split_container->get_size().x - sep.x;
1681
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(1000, 0), MouseButtonMask::LEFT, Key::NONE);
1682
MessageQueue::get_singleton()->flush();
1683
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1684
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1685
1686
// Move back in.
1687
dragger_pos = 100;
1688
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1689
MessageQueue::get_singleton()->flush();
1690
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1691
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1692
1693
// Release.
1694
SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
1695
MessageQueue::get_singleton()->flush();
1696
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1697
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1698
1699
// No longer moves with the mouse.
1700
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(200, 0), MouseButtonMask::NONE, Key::NONE);
1701
MessageQueue::get_singleton()->flush();
1702
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1703
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1704
}
1705
1706
SUBCASE("[SplitContainer] Both children expanded") {
1707
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1708
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1709
MessageQueue::get_singleton()->flush();
1710
Point2 mouse_offset = Point2(1, 1);
1711
int dragger_pos = (split_container->get_size().x - sep.x) / 2;
1712
int split_dragger_ofs = -dragger_pos;
1713
1714
// Grab the dragger.
1715
SEND_GUI_MOUSE_BUTTON_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
1716
MessageQueue::get_singleton()->flush();
1717
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1718
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1719
1720
// Move the dragger.
1721
dragger_pos += 10;
1722
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1723
MessageQueue::get_singleton()->flush();
1724
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1725
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1726
// It is clamped.
1727
split_container->clamp_split_offset();
1728
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1729
1730
// Continue moving.
1731
dragger_pos = 400;
1732
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1733
MessageQueue::get_singleton()->flush();
1734
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1735
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1736
1737
// Moves even when mouse is outside.
1738
dragger_pos = split_container->get_size().x - sep.x;
1739
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(1000, 0), MouseButtonMask::LEFT, Key::NONE);
1740
MessageQueue::get_singleton()->flush();
1741
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1742
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1743
1744
// Move back in.
1745
dragger_pos = 100;
1746
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1747
MessageQueue::get_singleton()->flush();
1748
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1749
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1750
1751
// Release.
1752
SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
1753
MessageQueue::get_singleton()->flush();
1754
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1755
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1756
1757
// No longer moves with the mouse.
1758
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(200, 0), MouseButtonMask::NONE, Key::NONE);
1759
MessageQueue::get_singleton()->flush();
1760
CHECK_RECTS(get_rects(split_container, dragger_pos, sep.x), get_child_rects(split_container));
1761
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1762
}
1763
}
1764
1765
memdelete(child_b);
1766
memdelete(child_a);
1767
memdelete(split_container);
1768
}
1769
1770
TEST_CASE("[SceneTree][SplitContainer] More children") {
1771
SplitContainer *split_container = memnew(SplitContainer);
1772
split_container->set_size(Size2(500, 500));
1773
SceneTree::get_singleton()->get_root()->add_child(split_container);
1774
Control *child_a = memnew(Control);
1775
Control *child_b = memnew(Control);
1776
Control *child_c = memnew(Control);
1777
split_container->add_child(child_a);
1778
split_container->add_child(child_b);
1779
split_container->add_child(child_c);
1780
Size2i min_size = Size2i(10, 10);
1781
child_a->set_custom_minimum_size(min_size);
1782
child_b->set_custom_minimum_size(min_size);
1783
child_c->set_custom_minimum_size(min_size);
1784
MessageQueue::get_singleton()->flush();
1785
1786
const int sep_constant = split_container->get_theme_constant("separation");
1787
const Size2i sep = Size2i(MAX(sep_constant, split_container->get_theme_icon("h_grabber")->get_width()), MAX(sep_constant, split_container->get_theme_icon("v_grabber")->get_height()));
1788
1789
SUBCASE("[SplitContainer] Duplicate") {
1790
// Make sure dynamically added internal draggers duplicate properly.
1791
SplitContainer *duplicate = (SplitContainer *)(Node *)split_container->duplicate();
1792
SceneTree::get_singleton()->get_root()->add_child(duplicate);
1793
MessageQueue::get_singleton()->flush();
1794
CHECK(duplicate->get_child_count(false) == split_container->get_child_count(false));
1795
CHECK(duplicate->get_child_count(true) == split_container->get_child_count(true));
1796
memdelete(duplicate);
1797
}
1798
1799
SUBCASE("[SplitContainer] Default position") {
1800
CHECK(split_container->get_split_offsets() == Vector<int>({ 0, 0 }));
1801
1802
set_size_flags(split_container, { -1, -1, -1 }); // None expanded.
1803
Vector<int> def_pos = { min_size.x, min_size.x * 2 + sep.x };
1804
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1805
split_container->clamp_split_offset();
1806
MessageQueue::get_singleton()->flush();
1807
CHECK(split_container->get_split_offsets() == Vector<int>({ min_size.x, min_size.x * 2 + sep.x }));
1808
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1809
1810
split_container->set_split_offsets({ 0, 0 });
1811
1812
set_size_flags(split_container, { 1, -1, -1 }); // First expanded.
1813
def_pos = { (int)split_container->get_size().x - sep.x * 2 - min_size.x * 2, (int)split_container->get_size().x - sep.x - min_size.x };
1814
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1815
split_container->clamp_split_offset();
1816
MessageQueue::get_singleton()->flush();
1817
CHECK(split_container->get_split_offsets() == Vector<int>({ -min_size.x * 2 - sep.x, -min_size.x }));
1818
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1819
split_container->set_split_offsets({ 0, 0 });
1820
1821
set_size_flags(split_container, { -1, 1, -1 }); // Second expanded.
1822
def_pos = { min_size.x, (int)split_container->get_size().x - min_size.x - sep.x };
1823
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1824
split_container->clamp_split_offset();
1825
MessageQueue::get_singleton()->flush();
1826
CHECK(split_container->get_split_offsets() == Vector<int>({ min_size.x, -min_size.x }));
1827
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1828
split_container->set_split_offsets({ 0, 0 });
1829
1830
set_size_flags(split_container, { -1, -1, 1 }); // Third expanded.
1831
def_pos = { min_size.x, min_size.x * 2 + sep.x };
1832
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1833
split_container->clamp_split_offset();
1834
MessageQueue::get_singleton()->flush();
1835
CHECK(split_container->get_split_offsets() == Vector<int>({ min_size.x, min_size.x * 2 + sep.x }));
1836
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1837
split_container->set_split_offsets({ 0, 0 });
1838
1839
set_size_flags(split_container, { 1, 1, -1 }); // First and second expanded.
1840
int child_2_expanded_size = ((int)split_container->get_size().x - min_size.x) / 2 - sep.x;
1841
def_pos = { child_2_expanded_size, (int)split_container->get_size().x - min_size.x - sep.x };
1842
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1843
split_container->clamp_split_offset();
1844
MessageQueue::get_singleton()->flush();
1845
CHECK(split_container->get_split_offsets() == Vector<int>({ 0, -min_size.x }));
1846
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1847
split_container->set_split_offsets({ 0, 0 });
1848
1849
set_size_flags(split_container, { 1, -1, 1 }); // First and third expanded.
1850
def_pos = { child_2_expanded_size, child_2_expanded_size + min_size.x + sep.x };
1851
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1852
split_container->clamp_split_offset();
1853
MessageQueue::get_singleton()->flush();
1854
CHECK(split_container->get_split_offsets() == Vector<int>({ 0, 0 }));
1855
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1856
split_container->set_split_offsets({ 0, 0 });
1857
1858
set_size_flags(split_container, { -1, 1, 1 }); // Second and third expanded.
1859
def_pos = { min_size.x, min_size.x + child_2_expanded_size + sep.x };
1860
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1861
split_container->clamp_split_offset();
1862
MessageQueue::get_singleton()->flush();
1863
CHECK(split_container->get_split_offsets() == Vector<int>({ min_size.x, 0 }));
1864
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1865
split_container->set_split_offsets({ 0, 0 });
1866
1867
set_size_flags(split_container, { 1, 1, 1 }); // All expanded.
1868
int child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
1869
// Add 1 due to pixel error accumulation.
1870
def_pos = { child_3_expanded_size, child_3_expanded_size * 2 + sep.x + 1 };
1871
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1872
split_container->clamp_split_offset();
1873
MessageQueue::get_singleton()->flush();
1874
CHECK(split_container->get_split_offsets() == Vector<int>({ 0, 0 }));
1875
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1876
split_container->set_split_offsets({ 0, 0 });
1877
1878
set_size_flags(split_container, { 1, 2, 3 }); // All expanded, different ratios.
1879
int child_6_expanded_size = (split_container->get_size().x - sep.x * 2) / 6;
1880
def_pos = { child_6_expanded_size, child_6_expanded_size * 3 + sep.x + 1 };
1881
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1882
split_container->clamp_split_offset();
1883
MessageQueue::get_singleton()->flush();
1884
CHECK(split_container->get_split_offsets() == Vector<int>({ 0, 0 }));
1885
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1886
split_container->set_split_offsets({ 0, 0 });
1887
}
1888
1889
SUBCASE("[SplitContainer] Set split offset") {
1890
const int expanded_single_size = (int)split_container->get_size().x - min_size.x * 2 - sep.x * 2;
1891
1892
SUBCASE("[SplitContainer] No expand flags") {
1893
set_size_flags(split_container, { -1, -1, -1 }); // None expanded.
1894
1895
// First is positive.
1896
split_container->set_split_offsets({ 50, 0 });
1897
MessageQueue::get_singleton()->flush();
1898
CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 0 });
1899
CHECK_RECTS(get_rects_multi(split_container, { 50, 50 + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
1900
1901
// Second is positive.
1902
split_container->set_split_offsets({ 0, 50 });
1903
MessageQueue::get_singleton()->flush();
1904
CHECK(split_container->get_split_offsets() == Vector<int>{ 0, 50 });
1905
CHECK_RECTS(get_rects_multi(split_container, { min_size.x, 50 }, sep.x), get_child_rects(split_container));
1906
1907
// Both are positive and equal, the first will override since they both start at 0.
1908
split_container->set_split_offsets({ 50, 50 });
1909
MessageQueue::get_singleton()->flush();
1910
CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 50 });
1911
CHECK_RECTS(get_rects_multi(split_container, { 50, 50 + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
1912
1913
// Both are negative and clamped.
1914
split_container->set_split_offsets({ -50, -50 });
1915
MessageQueue::get_singleton()->flush();
1916
CHECK(split_container->get_split_offsets() == Vector<int>{ -50, -50 });
1917
CHECK_RECTS(get_rects_multi(split_container, { min_size.x, min_size.x * 2 + sep.x }, sep.x), get_child_rects(split_container));
1918
1919
// First positive, second negative. First takes priority.
1920
split_container->set_split_offsets({ 50, -50 });
1921
MessageQueue::get_singleton()->flush();
1922
CHECK(split_container->get_split_offsets() == Vector<int>{ 50, -50 });
1923
CHECK_RECTS(get_rects_multi(split_container, { 50, 50 + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
1924
1925
// First is clamped and pushes second to the end.
1926
split_container->set_split_offsets({ 1000, 0 });
1927
MessageQueue::get_singleton()->flush();
1928
CHECK(split_container->get_split_offsets() == Vector<int>{ 1000, 0 });
1929
CHECK_RECTS(get_rects_multi(split_container, { expanded_single_size, expanded_single_size + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
1930
1931
// Second is clamped.
1932
split_container->set_split_offsets({ 0, 1000 });
1933
MessageQueue::get_singleton()->flush();
1934
CHECK(split_container->get_split_offsets() == Vector<int>{ 0, 1000 });
1935
CHECK_RECTS(get_rects_multi(split_container, { min_size.x, expanded_single_size + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
1936
1937
// Both are clamped positively, first one takes priority.
1938
split_container->set_split_offsets({ 1000, 1000 });
1939
MessageQueue::get_singleton()->flush();
1940
CHECK(split_container->get_split_offsets() == Vector<int>{ 1000, 1000 });
1941
CHECK_RECTS(get_rects_multi(split_container, { expanded_single_size, expanded_single_size + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
1942
}
1943
1944
SUBCASE("[SplitContainer] First child expanded") {
1945
set_size_flags(split_container, { 1, -1, -1 }); // First expanded.
1946
1947
// First is positive and clamped.
1948
split_container->set_split_offsets({ 50, 0 });
1949
MessageQueue::get_singleton()->flush();
1950
CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 0 });
1951
CHECK_RECTS(get_rects_multi(split_container, { expanded_single_size, expanded_single_size + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
1952
1953
// Second is positive and clamped.
1954
split_container->set_split_offsets({ 0, 50 });
1955
MessageQueue::get_singleton()->flush();
1956
CHECK(split_container->get_split_offsets() == Vector<int>{ 0, 50 });
1957
CHECK_RECTS(get_rects_multi(split_container, { expanded_single_size, expanded_single_size + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
1958
1959
// First is negative and moves left.
1960
split_container->set_split_offsets({ -50, 0 });
1961
MessageQueue::get_singleton()->flush();
1962
CHECK(split_container->get_split_offsets() == Vector<int>{ -50, 0 });
1963
CHECK_RECTS(get_rects_multi(split_container, { (int)split_container->get_size().x - 50 - sep.x, (int)split_container->get_size().x - min_size.x - sep.x }, sep.x), get_child_rects(split_container));
1964
1965
// Second is negative, but first has priority so it doesn't move.
1966
split_container->set_split_offsets({ 0, -50 });
1967
MessageQueue::get_singleton()->flush();
1968
CHECK(split_container->get_split_offsets() == Vector<int>{ 0, -50 });
1969
CHECK_RECTS(get_rects_multi(split_container, { expanded_single_size, expanded_single_size + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
1970
1971
// Both are negative and equal, they move left but the second doesn't move as much as wanted.
1972
split_container->set_split_offsets({ -50, -50 });
1973
MessageQueue::get_singleton()->flush();
1974
CHECK(split_container->get_split_offsets() == Vector<int>{ -50, -50 });
1975
CHECK_RECTS(get_rects_multi(split_container, { (int)split_container->get_size().x - 50 - sep.x, (int)split_container->get_size().x - 50 + min_size.x }, sep.x), get_child_rects(split_container));
1976
1977
// Both are negative with space and move left.
1978
split_container->set_split_offsets({ -100, -50 });
1979
MessageQueue::get_singleton()->flush();
1980
CHECK(split_container->get_split_offsets() == Vector<int>{ -100, -50 });
1981
CHECK_RECTS(get_rects_multi(split_container, { (int)split_container->get_size().x - 100 - sep.x, (int)split_container->get_size().x - 50 - sep.x }, sep.x), get_child_rects(split_container));
1982
1983
// First moves all the way left.
1984
split_container->set_split_offsets({ -1000, 0 });
1985
MessageQueue::get_singleton()->flush();
1986
CHECK(split_container->get_split_offsets() == Vector<int>{ -1000, 0 });
1987
CHECK_RECTS(get_rects_multi(split_container, { min_size.x, expanded_single_size + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
1988
1989
// Second cannot move all the way left since first takes priority.
1990
split_container->set_split_offsets({ 0, -1000 });
1991
MessageQueue::get_singleton()->flush();
1992
CHECK(split_container->get_split_offsets() == Vector<int>{ 0, -1000 });
1993
CHECK_RECTS(get_rects_multi(split_container, { expanded_single_size, expanded_single_size + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
1994
1995
// First and second move all the way left.
1996
split_container->set_split_offsets({ -1000, -1000 });
1997
MessageQueue::get_singleton()->flush();
1998
CHECK(split_container->get_split_offsets() == Vector<int>{ -1000, -1000 });
1999
CHECK_RECTS(get_rects_multi(split_container, { min_size.x, min_size.x * 2 + sep.x }, sep.x), get_child_rects(split_container));
2000
}
2001
2002
SUBCASE("[SplitContainer] All children expanded") {
2003
set_size_flags(split_container, { 1, 1, 1 }); // All expanded.
2004
const int child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
2005
2006
// First is moved positive, does not affect second.
2007
split_container->set_split_offsets({ 50, 0 });
2008
MessageQueue::get_singleton()->flush();
2009
CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 0 });
2010
CHECK_RECTS(get_rects_multi(split_container, { child_3_expanded_size + 50, child_3_expanded_size * 2 + sep.x + 1 }, sep.x), get_child_rects(split_container));
2011
2012
// First is moved negative, does not affect second.
2013
split_container->set_split_offsets({ -50, 0 });
2014
MessageQueue::get_singleton()->flush();
2015
CHECK(split_container->get_split_offsets() == Vector<int>{ -50, 0 });
2016
CHECK_RECTS(get_rects_multi(split_container, { child_3_expanded_size - 50, child_3_expanded_size * 2 + sep.x + 1 }, sep.x), get_child_rects(split_container));
2017
2018
// Second is moved positive, does not affect first.
2019
split_container->set_split_offsets({ 0, 50 });
2020
MessageQueue::get_singleton()->flush();
2021
CHECK(split_container->get_split_offsets() == Vector<int>{ 0, 50 });
2022
CHECK_RECTS(get_rects_multi(split_container, { child_3_expanded_size, child_3_expanded_size * 2 + 50 + sep.x + 1 }, sep.x), get_child_rects(split_container));
2023
2024
// Second is moved negative, does not affect first.
2025
split_container->set_split_offsets({ 0, -50 });
2026
MessageQueue::get_singleton()->flush();
2027
CHECK(split_container->get_split_offsets() == Vector<int>{ 0, -50 });
2028
CHECK_RECTS(get_rects_multi(split_container, { child_3_expanded_size, child_3_expanded_size * 2 - 50 + sep.x + 1 }, sep.x), get_child_rects(split_container));
2029
2030
// First is moved positive enough to affect second.
2031
split_container->set_split_offsets({ 200, 0 });
2032
MessageQueue::get_singleton()->flush();
2033
CHECK(split_container->get_split_offsets() == Vector<int>{ 200, 0 });
2034
CHECK_RECTS(get_rects_multi(split_container, { child_3_expanded_size + 200, child_3_expanded_size + 200 + sep.x + min_size.x }, sep.x), get_child_rects(split_container));
2035
2036
// Second is moved enough to pass the first, but the first has priority.
2037
split_container->set_split_offsets({ 0, -200 });
2038
MessageQueue::get_singleton()->flush();
2039
CHECK(split_container->get_split_offsets() == Vector<int>{ 0, -200 });
2040
CHECK_RECTS(get_rects_multi(split_container, { child_3_expanded_size, child_3_expanded_size + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
2041
}
2042
}
2043
2044
SUBCASE("[SplitContainer] Resize") {
2045
SUBCASE("[SplitContainer] No expand flags") {
2046
Vector<int> def_pos = { min_size.x, min_size.x * 2 + sep.x };
2047
// Increase the size.
2048
split_container->set_size(Size2(600, 500));
2049
MessageQueue::get_singleton()->flush();
2050
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2051
2052
// Decrease the size.
2053
split_container->set_size(Size2(400, 500));
2054
MessageQueue::get_singleton()->flush();
2055
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2056
2057
// Change size with a split offset.
2058
split_container->set_split_offsets({ 50, 100 });
2059
split_container->set_size(Size2(500, 500));
2060
MessageQueue::get_singleton()->flush();
2061
CHECK_RECTS(get_rects_multi(split_container, { 50, 100 }, sep.x), get_child_rects(split_container));
2062
CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 100 });
2063
2064
// Change size so that the second child gets clamped and changes size.
2065
split_container->set_size(Size2(100, 500));
2066
MessageQueue::get_singleton()->flush();
2067
CHECK_RECTS(get_rects_multi(split_container, { 50, 100 - sep.x - min_size.x }, sep.x), get_child_rects(split_container));
2068
CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 100 });
2069
2070
// Change size so that the first child changes size.
2071
split_container->set_size(Size2(60, 500));
2072
MessageQueue::get_singleton()->flush();
2073
CHECK_RECTS(get_rects_multi(split_container, { 60 - min_size.x * 2 - sep.x * 2, 60 - sep.x - min_size.x }, sep.x), get_child_rects(split_container));
2074
CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 100 });
2075
2076
// Increase size again.
2077
split_container->set_size(Size2(500, 500));
2078
MessageQueue::get_singleton()->flush();
2079
CHECK_RECTS(get_rects_multi(split_container, { 50, 100 }, sep.x), get_child_rects(split_container));
2080
CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 100 });
2081
}
2082
2083
SUBCASE("[SplitContainer] First child expanded") {
2084
set_size_flags(split_container, { 1, -1, -1 });
2085
Vector<int> def_pos = { (int)split_container->get_size().x - sep.x * 2 - min_size.x, (int)split_container->get_size().x - sep.x };
2086
// Increase the size.
2087
split_container->set_size(Size2(600, 500));
2088
def_pos = { (int)split_container->get_size().x - sep.x * 2 - min_size.x * 2, (int)split_container->get_size().x - sep.x - min_size.x };
2089
MessageQueue::get_singleton()->flush();
2090
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2091
2092
// Decrease the size.
2093
split_container->set_size(Size2(400, 500));
2094
def_pos = { (int)split_container->get_size().x - sep.x * 2 - min_size.x * 2, (int)split_container->get_size().x - sep.x - min_size.x };
2095
MessageQueue::get_singleton()->flush();
2096
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2097
2098
// Change size with a split offset.
2099
split_container->set_split_offsets({ -100, -50 });
2100
split_container->set_size(Size2(500, 500));
2101
MessageQueue::get_singleton()->flush();
2102
CHECK_RECTS(get_rects_multi(split_container, { (int)split_container->get_size().x - 100 - sep.x, (int)split_container->get_size().x - 50 - sep.x }, sep.x), get_child_rects(split_container));
2103
CHECK(split_container->get_split_offsets() == Vector<int>{ -100, -50 });
2104
2105
// Change size so that the first child gets clamped and changes size.
2106
split_container->set_size(Size2(100, 500));
2107
MessageQueue::get_singleton()->flush();
2108
CHECK_RECTS(get_rects_multi(split_container, { min_size.x, (int)split_container->get_size().x - 50 - sep.x }, sep.x), get_child_rects(split_container));
2109
CHECK(split_container->get_split_offsets() == Vector<int>{ -100, -50 });
2110
2111
// Change size so that the second child changes size.
2112
split_container->set_size(Size2(50, 500));
2113
MessageQueue::get_singleton()->flush();
2114
CHECK_RECTS(get_rects_multi(split_container, { min_size.x, min_size.x * 2 + sep.x }, sep.x), get_child_rects(split_container));
2115
CHECK(split_container->get_split_offsets() == Vector<int>{ -100, -50 });
2116
2117
// Increase size again.
2118
split_container->set_size(Size2(500, 500));
2119
MessageQueue::get_singleton()->flush();
2120
CHECK_RECTS(get_rects_multi(split_container, { (int)split_container->get_size().x - 100 - sep.x, (int)split_container->get_size().x - 50 - sep.x }, sep.x), get_child_rects(split_container));
2121
CHECK(split_container->get_split_offsets() == Vector<int>{ -100, -50 });
2122
}
2123
2124
SUBCASE("[SplitContainer] All children expanded") {
2125
set_size_flags(split_container, { 1, 1, 1 });
2126
// Increase the size.
2127
split_container->set_size(Size2(600, 500));
2128
MessageQueue::get_singleton()->flush();
2129
int child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
2130
Vector<int> def_pos = { child_3_expanded_size, child_3_expanded_size * 2 + sep.x };
2131
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2132
2133
// Decrease the size.
2134
split_container->set_size(Size2(400, 500));
2135
MessageQueue::get_singleton()->flush();
2136
child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
2137
def_pos = { child_3_expanded_size, child_3_expanded_size * 2 + sep.x };
2138
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2139
2140
// Change size with a split offset.
2141
split_container->set_split_offsets({ -50, 50 });
2142
split_container->set_size(Size2(500, 500));
2143
MessageQueue::get_singleton()->flush();
2144
child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
2145
def_pos = { child_3_expanded_size, child_3_expanded_size * 2 + sep.x + 1 };
2146
CHECK_RECTS(get_rects_multi(split_container, { def_pos[0] - 50, def_pos[1] + 50 }, sep.x), get_child_rects(split_container));
2147
CHECK(split_container->get_split_offsets() == Vector<int>{ -50, 50 });
2148
2149
// Change size so that the children get clamped and change sizes.
2150
split_container->set_size(Size2(100, 500));
2151
MessageQueue::get_singleton()->flush();
2152
CHECK_RECTS(get_rects_multi(split_container, { min_size.x, (int)split_container->get_size().x - sep.x - min_size.x }, sep.x), get_child_rects(split_container));
2153
CHECK(split_container->get_split_offsets() == Vector<int>{ -50, 50 });
2154
2155
// Increase size again.
2156
split_container->set_size(Size2(500, 500));
2157
MessageQueue::get_singleton()->flush();
2158
child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
2159
def_pos = { child_3_expanded_size, child_3_expanded_size * 2 + sep.x + 1 };
2160
CHECK_RECTS(get_rects_multi(split_container, { def_pos[0] - 50, def_pos[1] + 50 }, sep.x), get_child_rects(split_container));
2161
CHECK(split_container->get_split_offsets() == Vector<int>{ -50, 50 });
2162
}
2163
}
2164
2165
SUBCASE("[SplitContainer] Visibility changes") {
2166
set_size_flags(split_container, { -1, -1, -1 }); // None expanded.
2167
split_container->set_split_offsets({ 50, 122 });
2168
MessageQueue::get_singleton()->flush();
2169
Vector<int> def_pos = { 50, 122 };
2170
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2171
2172
// Hide and show the first child.
2173
child_a->set_visible(false);
2174
MessageQueue::get_singleton()->flush();
2175
CHECK(split_container->get_split_offsets() == Vector<int>({ 60 }));
2176
CHECK_RECTS(get_rects_multi(split_container, { 60 }, sep.x), get_child_rects(split_container));
2177
2178
child_a->set_visible(true);
2179
MessageQueue::get_singleton()->flush();
2180
CHECK(split_container->get_split_offsets() == def_pos);
2181
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2182
2183
// Hide and show the second child.
2184
child_b->set_visible(false);
2185
MessageQueue::get_singleton()->flush();
2186
CHECK(split_container->get_split_offsets() == Vector<int>({ 50 }));
2187
CHECK_RECTS(get_rects_multi(split_container, { 50 }, sep.x), get_child_rects(split_container));
2188
child_b->set_visible(true);
2189
MessageQueue::get_singleton()->flush();
2190
CHECK(split_container->get_split_offsets() == def_pos);
2191
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2192
2193
// Hide and show the last child.
2194
child_c->set_visible(false);
2195
MessageQueue::get_singleton()->flush();
2196
CHECK(split_container->get_split_offsets() == Vector<int>({ 50 }));
2197
CHECK_RECTS(get_rects_multi(split_container, { 50 }, sep.x), get_child_rects(split_container));
2198
child_c->set_visible(true);
2199
MessageQueue::get_singleton()->flush();
2200
CHECK(split_container->get_split_offsets() == def_pos);
2201
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2202
2203
set_size_flags(split_container, { 1, 1, 1 }); // All expanded.
2204
split_container->set_split_offsets({ 50, 60 });
2205
MessageQueue::get_singleton()->flush();
2206
int child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
2207
def_pos = { child_3_expanded_size + 50, child_3_expanded_size * 2 + sep.x + 1 + 60 };
2208
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2209
2210
// Hide and show the first child.
2211
int child_2_expanded_size = (split_container->get_size().x - sep.x) / 2;
2212
child_a->set_visible(false);
2213
MessageQueue::get_singleton()->flush();
2214
int half_point = (split_container->get_size().x - def_pos[0]) / 2 - sep.x;
2215
int so = child_3_expanded_size + 11 - half_point; // 11 is from 60 - 50 + 1 to get the second child's size.
2216
CHECK_RECTS(get_rects_multi(split_container, { child_2_expanded_size + so }, sep.x), get_child_rects(split_container));
2217
CHECK(split_container->get_split_offsets() == Vector<int>({ so }));
2218
child_a->set_visible(true);
2219
MessageQueue::get_singleton()->flush();
2220
CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2221
CHECK(split_container->get_split_offsets() == Vector<int>({ 50, 60 }));
2222
2223
// Hide and show the second child.
2224
child_b->set_visible(false);
2225
MessageQueue::get_singleton()->flush();
2226
half_point = (split_container->get_size().x - (def_pos[1] - def_pos[0] - sep.x)) / 2 - sep.x + 1;
2227
so = def_pos[0] - half_point;
2228
CHECK_RECTS(get_rects_multi(split_container, { child_2_expanded_size + so }, sep.x), get_child_rects(split_container));
2229
CHECK(split_container->get_split_offsets() == Vector<int>({ so }));
2230
child_b->set_visible(true);
2231
MessageQueue::get_singleton()->flush();
2232
// There is lost precision due to SplitContainer using ints, so this is off by one.
2233
CHECK_RECTS(get_rects_multi(split_container, { def_pos[0] - 1, def_pos[1] - 1 }, sep.x), get_child_rects(split_container));
2234
CHECK(split_container->get_split_offsets() == Vector<int>({ 49, 59 }));
2235
2236
// Hide and show the last child.
2237
split_container->set_split_offsets({ 50, 60 });
2238
child_c->set_visible(false);
2239
MessageQueue::get_singleton()->flush();
2240
half_point = (def_pos[1] - sep.x) / 2 + 1;
2241
so = def_pos[0] - half_point;
2242
CHECK_RECTS(get_rects_multi(split_container, { child_2_expanded_size + so }, sep.x), get_child_rects(split_container));
2243
CHECK(split_container->get_split_offsets() == Vector<int>({ so }));
2244
child_c->set_visible(true);
2245
MessageQueue::get_singleton()->flush();
2246
CHECK_RECTS(get_rects_multi(split_container, { def_pos[0] - 1, def_pos[1] - 1 }, sep.x), get_child_rects(split_container));
2247
CHECK(split_container->get_split_offsets() == Vector<int>({ 49, 59 }));
2248
}
2249
2250
SUBCASE("[SplitContainer] Adjust split offset when moving children") {
2251
split_container->set_split_offsets({ 50, 80 });
2252
split_container->move_child(child_a, 1);
2253
Vector<int> pos = { 30 - sep.x, 80 }; // 30 = 80 - 50.
2254
MessageQueue::get_singleton()->flush();
2255
CHECK(split_container->get_split_offsets() == pos);
2256
CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2257
2258
// Move last child to first.
2259
split_container->set_split_offsets({ 50, 80 });
2260
split_container->move_child(child_c, 0);
2261
pos = { (int)split_container->get_size().x - 80 - sep.x, (int)split_container->get_size().x - 30 };
2262
MessageQueue::get_singleton()->flush();
2263
CHECK(split_container->get_split_offsets() == pos);
2264
CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2265
2266
// Move it back.
2267
split_container->move_child(child_c, 2);
2268
pos = { 50, 80 };
2269
MessageQueue::get_singleton()->flush();
2270
CHECK(split_container->get_split_offsets() == pos);
2271
CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2272
}
2273
2274
SUBCASE("[SplitContainer] Showing child with not enough space shrinks the largest child first") {
2275
set_size_flags(split_container, { -1, -1, -1 }); // None expanded.
2276
2277
// Second child is largest.
2278
child_a->set_visible(false);
2279
Vector<int> pos = { 360 };
2280
split_container->set_split_offsets(pos);
2281
2282
MessageQueue::get_singleton()->flush();
2283
CHECK(split_container->get_split_offsets() == pos);
2284
CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2285
2286
child_a->set_size(Vector2(100, 100));
2287
MessageQueue::get_singleton()->flush();
2288
CHECK(split_container->get_split_offsets() == pos);
2289
CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2290
2291
child_a->set_visible(true);
2292
pos = { 100, 360 };
2293
MessageQueue::get_singleton()->flush();
2294
CHECK(split_container->get_split_offsets() == pos);
2295
CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2296
2297
// Last child is largest.
2298
child_a->set_visible(false);
2299
pos = { 60 };
2300
split_container->set_split_offsets(pos);
2301
2302
MessageQueue::get_singleton()->flush();
2303
CHECK(split_container->get_split_offsets() == pos);
2304
CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2305
2306
child_a->set_size(Vector2(100, 100));
2307
MessageQueue::get_singleton()->flush();
2308
CHECK(split_container->get_split_offsets() == pos);
2309
CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2310
2311
child_a->set_visible(true);
2312
pos = { 100, 160 + sep.x };
2313
MessageQueue::get_singleton()->flush();
2314
CHECK(split_container->get_split_offsets() == pos);
2315
CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2316
2317
// Both visible children are the same size.
2318
child_a->set_visible(false);
2319
pos = { (int)split_container->get_size().x / 2 - sep.x / 2 };
2320
split_container->set_split_offsets(pos);
2321
2322
MessageQueue::get_singleton()->flush();
2323
CHECK(split_container->get_split_offsets() == pos);
2324
CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2325
CHECK(child_b->get_size().x == child_c->get_size().x);
2326
2327
child_a->set_size(Vector2(100, 100));
2328
MessageQueue::get_singleton()->flush();
2329
CHECK(split_container->get_split_offsets() == pos);
2330
CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2331
2332
child_a->set_visible(true);
2333
pos = { 100, (int)split_container->get_size().x / 2 + 50 };
2334
MessageQueue::get_singleton()->flush();
2335
CHECK(split_container->get_split_offsets() == pos);
2336
CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2337
CHECK(child_b->get_size().x == child_c->get_size().x);
2338
2339
// Second child is slightly larger than the last child.
2340
child_a->set_visible(false);
2341
pos = { (int)split_container->get_size().x / 2 - sep.x / 2 + 20 };
2342
split_container->set_split_offsets(pos);
2343
2344
MessageQueue::get_singleton()->flush();
2345
CHECK(split_container->get_split_offsets() == pos);
2346
CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2347
2348
child_a->set_size(Vector2(100, 100));
2349
MessageQueue::get_singleton()->flush();
2350
CHECK(split_container->get_split_offsets() == pos);
2351
CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2352
2353
child_a->set_visible(true);
2354
pos = { 100, (int)split_container->get_size().x / 2 + 50 };
2355
MessageQueue::get_singleton()->flush();
2356
CHECK(split_container->get_split_offsets() == pos);
2357
CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2358
CHECK(child_b->get_size().x == child_c->get_size().x);
2359
}
2360
2361
memdelete(split_container);
2362
}
2363
2364
} // namespace TestSplitContainer
2365
2366
#endif // ADVANCED_GUI_DISABLED
2367
2368