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