Debian Codegraph @

tests/scene/test_split_container.h

raw symbols SCIP
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 SceneTree::get_singleton()->get_root()->add_child(duplicate);
1788 MessageQueue::get_singleton()->flush();
1789 CHECK(duplicate->get_child_count(false) == split_container->get_child_count(false));
1790 CHECK(duplicate->get_child_count(true) == split_container->get_child_count(true));
1791 memdelete(duplicate);
1792 }
1793
1794 SUBCASE("[SplitContainer] Default position") {
1795 CHECK(split_container->get_split_offsets() == Vector<int>({ 0, 0 }));
1796
1797 set_size_flags(split_container, { -1, -1, -1 }); // None expanded.
1798 Vector<int> def_pos = { min_size.x, min_size.x * 2 + sep.x };
1799 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1800 split_container->clamp_split_offset();
1801 MessageQueue::get_singleton()->flush();
1802 CHECK(split_container->get_split_offsets() == Vector<int>({ min_size.x, min_size.x * 2 + sep.x }));
1803 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1804
1805 split_container->set_split_offsets({ 0, 0 });
1806
1807 set_size_flags(split_container, { 1, -1, -1 }); // First expanded.
1808 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 };
1809 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1810 split_container->clamp_split_offset();
1811 MessageQueue::get_singleton()->flush();
1812 CHECK(split_container->get_split_offsets() == Vector<int>({ -min_size.x * 2 - sep.x, -min_size.x }));
1813 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1814 split_container->set_split_offsets({ 0, 0 });
1815
1816 set_size_flags(split_container, { -1, 1, -1 }); // Second expanded.
1817 def_pos = { min_size.x, (int)split_container->get_size().x - min_size.x - sep.x };
1818 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1819 split_container->clamp_split_offset();
1820 MessageQueue::get_singleton()->flush();
1821 CHECK(split_container->get_split_offsets() == Vector<int>({ min_size.x, -min_size.x }));
1822 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1823 split_container->set_split_offsets({ 0, 0 });
1824
1825 set_size_flags(split_container, { -1, -1, 1 }); // Third expanded.
1826 def_pos = { min_size.x, min_size.x * 2 + sep.x };
1827 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1828 split_container->clamp_split_offset();
1829 MessageQueue::get_singleton()->flush();
1830 CHECK(split_container->get_split_offsets() == Vector<int>({ min_size.x, min_size.x * 2 + sep.x }));
1831 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1832 split_container->set_split_offsets({ 0, 0 });
1833
1834 set_size_flags(split_container, { 1, 1, -1 }); // First and second expanded.
1835 int child_2_expanded_size = ((int)split_container->get_size().x - min_size.x) / 2 - sep.x;
1836 def_pos = { child_2_expanded_size, (int)split_container->get_size().x - min_size.x - sep.x };
1837 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1838 split_container->clamp_split_offset();
1839 MessageQueue::get_singleton()->flush();
1840 CHECK(split_container->get_split_offsets() == Vector<int>({ 0, -min_size.x }));
1841 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1842 split_container->set_split_offsets({ 0, 0 });
1843
1844 set_size_flags(split_container, { 1, -1, 1 }); // First and third expanded.
1845 def_pos = { child_2_expanded_size, child_2_expanded_size + min_size.x + sep.x };
1846 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1847 split_container->clamp_split_offset();
1848 MessageQueue::get_singleton()->flush();
1849 CHECK(split_container->get_split_offsets() == Vector<int>({ 0, 0 }));
1850 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1851 split_container->set_split_offsets({ 0, 0 });
1852
1853 set_size_flags(split_container, { -1, 1, 1 }); // Second and third expanded.
1854 def_pos = { min_size.x, min_size.x + child_2_expanded_size + sep.x };
1855 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1856 split_container->clamp_split_offset();
1857 MessageQueue::get_singleton()->flush();
1858 CHECK(split_container->get_split_offsets() == Vector<int>({ min_size.x, 0 }));
1859 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1860 split_container->set_split_offsets({ 0, 0 });
1861
1862 set_size_flags(split_container, { 1, 1, 1 }); // All expanded.
1863 int child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
1864 // Add 1 due to pixel error accumulation.
1865 def_pos = { child_3_expanded_size, child_3_expanded_size * 2 + sep.x + 1 };
1866 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1867 split_container->clamp_split_offset();
1868 MessageQueue::get_singleton()->flush();
1869 CHECK(split_container->get_split_offsets() == Vector<int>({ 0, 0 }));
1870 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1871 split_container->set_split_offsets({ 0, 0 });
1872
1873 set_size_flags(split_container, { 1, 2, 3 }); // All expanded, different ratios.
1874 int child_6_expanded_size = (split_container->get_size().x - sep.x * 2) / 6;
1875 def_pos = { child_6_expanded_size, child_6_expanded_size * 3 + sep.x + 1 };
1876 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1877 split_container->clamp_split_offset();
1878 MessageQueue::get_singleton()->flush();
1879 CHECK(split_container->get_split_offsets() == Vector<int>({ 0, 0 }));
1880 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
1881 split_container->set_split_offsets({ 0, 0 });
1882 }
1883
1884 SUBCASE("[SplitContainer] Set split offset") {
1885 const int expanded_single_size = (int)split_container->get_size().x - min_size.x * 2 - sep.x * 2;
1886
1887 SUBCASE("[SplitContainer] No expand flags") {
1888 set_size_flags(split_container, { -1, -1, -1 }); // None expanded.
1889
1890 // First is positive.
1891 split_container->set_split_offsets({ 50, 0 });
1892 MessageQueue::get_singleton()->flush();
1893 CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 0 });
1894 CHECK_RECTS(get_rects_multi(split_container, { 50, 50 + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
1895
1896 // Second is positive.
1897 split_container->set_split_offsets({ 0, 50 });
1898 MessageQueue::get_singleton()->flush();
1899 CHECK(split_container->get_split_offsets() == Vector<int>{ 0, 50 });
1900 CHECK_RECTS(get_rects_multi(split_container, { min_size.x, 50 }, sep.x), get_child_rects(split_container));
1901
1902 // Both are positive and equal, the first will override since they both start at 0.
1903 split_container->set_split_offsets({ 50, 50 });
1904 MessageQueue::get_singleton()->flush();
1905 CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 50 });
1906 CHECK_RECTS(get_rects_multi(split_container, { 50, 50 + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
1907
1908 // Both are negative and clamped.
1909 split_container->set_split_offsets({ -50, -50 });
1910 MessageQueue::get_singleton()->flush();
1911 CHECK(split_container->get_split_offsets() == Vector<int>{ -50, -50 });
1912 CHECK_RECTS(get_rects_multi(split_container, { min_size.x, min_size.x * 2 + sep.x }, sep.x), get_child_rects(split_container));
1913
1914 // First positive, second negative. First takes priority.
1915 split_container->set_split_offsets({ 50, -50 });
1916 MessageQueue::get_singleton()->flush();
1917 CHECK(split_container->get_split_offsets() == Vector<int>{ 50, -50 });
1918 CHECK_RECTS(get_rects_multi(split_container, { 50, 50 + min_size.x + sep.x }, sep.x), get_child_rects(split_container));
1919
1920 // First is clamped and pushes second to the end.
1921 split_container->set_split_offsets({ 1000, 0 });
1922 MessageQueue::get_singleton()->flush();
1923 CHECK(split_container->get_split_offsets() == Vector<int>{ 1000, 0 });
1924 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));
1925
1926 // Second is clamped.
1927 split_container->set_split_offsets({ 0, 1000 });
1928 MessageQueue::get_singleton()->flush();
1929 CHECK(split_container->get_split_offsets() == Vector<int>{ 0, 1000 });
1930 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));
1931
1932 // Both are clamped positively, first one takes priority.
1933 split_container->set_split_offsets({ 1000, 1000 });
1934 MessageQueue::get_singleton()->flush();
1935 CHECK(split_container->get_split_offsets() == Vector<int>{ 1000, 1000 });
1936 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));
1937 }
1938
1939 SUBCASE("[SplitContainer] First child expanded") {
1940 set_size_flags(split_container, { 1, -1, -1 }); // First expanded.
1941
1942 // First is positive and clamped.
1943 split_container->set_split_offsets({ 50, 0 });
1944 MessageQueue::get_singleton()->flush();
1945 CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 0 });
1946 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));
1947
1948 // Second is positive and clamped.
1949 split_container->set_split_offsets({ 0, 50 });
1950 MessageQueue::get_singleton()->flush();
1951 CHECK(split_container->get_split_offsets() == Vector<int>{ 0, 50 });
1952 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));
1953
1954 // First is negative and moves left.
1955 split_container->set_split_offsets({ -50, 0 });
1956 MessageQueue::get_singleton()->flush();
1957 CHECK(split_container->get_split_offsets() == Vector<int>{ -50, 0 });
1958 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));
1959
1960 // Second is negative, but first has priority so it doesn't move.
1961 split_container->set_split_offsets({ 0, -50 });
1962 MessageQueue::get_singleton()->flush();
1963 CHECK(split_container->get_split_offsets() == Vector<int>{ 0, -50 });
1964 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));
1965
1966 // Both are negative and equal, they move left but the second doesn't move as much as wanted.
1967 split_container->set_split_offsets({ -50, -50 });
1968 MessageQueue::get_singleton()->flush();
1969 CHECK(split_container->get_split_offsets() == Vector<int>{ -50, -50 });
1970 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));
1971
1972 // Both are negative with space and move left.
1973 split_container->set_split_offsets({ -100, -50 });
1974 MessageQueue::get_singleton()->flush();
1975 CHECK(split_container->get_split_offsets() == Vector<int>{ -100, -50 });
1976 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));
1977
1978 // First moves all the way left.
1979 split_container->set_split_offsets({ -1000, 0 });
1980 MessageQueue::get_singleton()->flush();
1981 CHECK(split_container->get_split_offsets() == Vector<int>{ -1000, 0 });
1982 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));
1983
1984 // Second cannot move all the way left since first takes priority.
1985 split_container->set_split_offsets({ 0, -1000 });
1986 MessageQueue::get_singleton()->flush();
1987 CHECK(split_container->get_split_offsets() == Vector<int>{ 0, -1000 });
1988 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));
1989
1990 // First and second move all the way left.
1991 split_container->set_split_offsets({ -1000, -1000 });
1992 MessageQueue::get_singleton()->flush();
1993 CHECK(split_container->get_split_offsets() == Vector<int>{ -1000, -1000 });
1994 CHECK_RECTS(get_rects_multi(split_container, { min_size.x, min_size.x * 2 + sep.x }, sep.x), get_child_rects(split_container));
1995 }
1996
1997 SUBCASE("[SplitContainer] All children expanded") {
1998 set_size_flags(split_container, { 1, 1, 1 }); // All expanded.
1999 const int child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
2000
2001 // First is moved positive, does not affect second.
2002 split_container->set_split_offsets({ 50, 0 });
2003 MessageQueue::get_singleton()->flush();
2004 CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 0 });
2005 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));
2006
2007 // First is moved negative, does not affect second.
2008 split_container->set_split_offsets({ -50, 0 });
2009 MessageQueue::get_singleton()->flush();
2010 CHECK(split_container->get_split_offsets() == Vector<int>{ -50, 0 });
2011 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));
2012
2013 // Second is moved positive, does not affect first.
2014 split_container->set_split_offsets({ 0, 50 });
2015 MessageQueue::get_singleton()->flush();
2016 CHECK(split_container->get_split_offsets() == Vector<int>{ 0, 50 });
2017 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));
2018
2019 // Second is moved negative, does not affect first.
2020 split_container->set_split_offsets({ 0, -50 });
2021 MessageQueue::get_singleton()->flush();
2022 CHECK(split_container->get_split_offsets() == Vector<int>{ 0, -50 });
2023 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));
2024
2025 // First is moved positive enough to affect second.
2026 split_container->set_split_offsets({ 200, 0 });
2027 MessageQueue::get_singleton()->flush();
2028 CHECK(split_container->get_split_offsets() == Vector<int>{ 200, 0 });
2029 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));
2030
2031 // Second is moved enough to pass the first, but the first has priority.
2032 split_container->set_split_offsets({ 0, -200 });
2033 MessageQueue::get_singleton()->flush();
2034 CHECK(split_container->get_split_offsets() == Vector<int>{ 0, -200 });
2035 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));
2036 }
2037 }
2038
2039 SUBCASE("[SplitContainer] Resize") {
2040 SUBCASE("[SplitContainer] No expand flags") {
2041 Vector<int> def_pos = { min_size.x, min_size.x * 2 + sep.x };
2042 // Increase the size.
2043 split_container->set_size(Size2(600, 500));
2044 MessageQueue::get_singleton()->flush();
2045 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2046
2047 // Decrease the size.
2048 split_container->set_size(Size2(400, 500));
2049 MessageQueue::get_singleton()->flush();
2050 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2051
2052 // Change size with a split offset.
2053 split_container->set_split_offsets({ 50, 100 });
2054 split_container->set_size(Size2(500, 500));
2055 MessageQueue::get_singleton()->flush();
2056 CHECK_RECTS(get_rects_multi(split_container, { 50, 100 }, sep.x), get_child_rects(split_container));
2057 CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 100 });
2058
2059 // Change size so that the second child gets clamped and changes size.
2060 split_container->set_size(Size2(100, 500));
2061 MessageQueue::get_singleton()->flush();
2062 CHECK_RECTS(get_rects_multi(split_container, { 50, 100 - sep.x - min_size.x }, sep.x), get_child_rects(split_container));
2063 CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 100 });
2064
2065 // Change size so that the first child changes size.
2066 split_container->set_size(Size2(60, 500));
2067 MessageQueue::get_singleton()->flush();
2068 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));
2069 CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 100 });
2070
2071 // Increase size again.
2072 split_container->set_size(Size2(500, 500));
2073 MessageQueue::get_singleton()->flush();
2074 CHECK_RECTS(get_rects_multi(split_container, { 50, 100 }, sep.x), get_child_rects(split_container));
2075 CHECK(split_container->get_split_offsets() == Vector<int>{ 50, 100 });
2076 }
2077
2078 SUBCASE("[SplitContainer] First child expanded") {
2079 set_size_flags(split_container, { 1, -1, -1 });
2080 Vector<int> def_pos = { (int)split_container->get_size().x - sep.x * 2 - min_size.x, (int)split_container->get_size().x - sep.x };
2081 // Increase the size.
2082 split_container->set_size(Size2(600, 500));
2083 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 };
2084 MessageQueue::get_singleton()->flush();
2085 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2086
2087 // Decrease the size.
2088 split_container->set_size(Size2(400, 500));
2089 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 };
2090 MessageQueue::get_singleton()->flush();
2091 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2092
2093 // Change size with a split offset.
2094 split_container->set_split_offsets({ -100, -50 });
2095 split_container->set_size(Size2(500, 500));
2096 MessageQueue::get_singleton()->flush();
2097 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));
2098 CHECK(split_container->get_split_offsets() == Vector<int>{ -100, -50 });
2099
2100 // Change size so that the first child gets clamped and changes size.
2101 split_container->set_size(Size2(100, 500));
2102 MessageQueue::get_singleton()->flush();
2103 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));
2104 CHECK(split_container->get_split_offsets() == Vector<int>{ -100, -50 });
2105
2106 // Change size so that the second child changes size.
2107 split_container->set_size(Size2(50, 500));
2108 MessageQueue::get_singleton()->flush();
2109 CHECK_RECTS(get_rects_multi(split_container, { min_size.x, min_size.x * 2 + sep.x }, sep.x), get_child_rects(split_container));
2110 CHECK(split_container->get_split_offsets() == Vector<int>{ -100, -50 });
2111
2112 // Increase size again.
2113 split_container->set_size(Size2(500, 500));
2114 MessageQueue::get_singleton()->flush();
2115 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));
2116 CHECK(split_container->get_split_offsets() == Vector<int>{ -100, -50 });
2117 }
2118
2119 SUBCASE("[SplitContainer] All children expanded") {
2120 set_size_flags(split_container, { 1, 1, 1 });
2121 // Increase the size.
2122 split_container->set_size(Size2(600, 500));
2123 MessageQueue::get_singleton()->flush();
2124 int child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
2125 Vector<int> def_pos = { child_3_expanded_size, child_3_expanded_size * 2 + sep.x };
2126 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2127
2128 // Decrease the size.
2129 split_container->set_size(Size2(400, 500));
2130 MessageQueue::get_singleton()->flush();
2131 child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
2132 def_pos = { child_3_expanded_size, child_3_expanded_size * 2 + sep.x };
2133 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2134
2135 // Change size with a split offset.
2136 split_container->set_split_offsets({ -50, 50 });
2137 split_container->set_size(Size2(500, 500));
2138 MessageQueue::get_singleton()->flush();
2139 child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
2140 def_pos = { child_3_expanded_size, child_3_expanded_size * 2 + sep.x + 1 };
2141 CHECK_RECTS(get_rects_multi(split_container, { def_pos[0] - 50, def_pos[1] + 50 }, sep.x), get_child_rects(split_container));
2142 CHECK(split_container->get_split_offsets() == Vector<int>{ -50, 50 });
2143
2144 // Change size so that the children get clamped and change sizes.
2145 split_container->set_size(Size2(100, 500));
2146 MessageQueue::get_singleton()->flush();
2147 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));
2148 CHECK(split_container->get_split_offsets() == Vector<int>{ -50, 50 });
2149
2150 // Increase size again.
2151 split_container->set_size(Size2(500, 500));
2152 MessageQueue::get_singleton()->flush();
2153 child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
2154 def_pos = { child_3_expanded_size, child_3_expanded_size * 2 + sep.x + 1 };
2155 CHECK_RECTS(get_rects_multi(split_container, { def_pos[0] - 50, def_pos[1] + 50 }, sep.x), get_child_rects(split_container));
2156 CHECK(split_container->get_split_offsets() == Vector<int>{ -50, 50 });
2157 }
2158 }
2159
2160 SUBCASE("[SplitContainer] Visibility changes") {
2161 set_size_flags(split_container, { -1, -1, -1 }); // None expanded.
2162 split_container->set_split_offsets({ 50, 122 });
2163 MessageQueue::get_singleton()->flush();
2164 Vector<int> def_pos = { 50, 122 };
2165 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2166
2167 // Hide and show the first child.
2168 child_a->set_visible(false);
2169 MessageQueue::get_singleton()->flush();
2170 CHECK(split_container->get_split_offsets() == Vector<int>({ 60 }));
2171 CHECK_RECTS(get_rects_multi(split_container, { 60 }, sep.x), get_child_rects(split_container));
2172
2173 child_a->set_visible(true);
2174 MessageQueue::get_singleton()->flush();
2175 CHECK(split_container->get_split_offsets() == def_pos);
2176 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2177
2178 // Hide and show the second child.
2179 child_b->set_visible(false);
2180 MessageQueue::get_singleton()->flush();
2181 CHECK(split_container->get_split_offsets() == Vector<int>({ 50 }));
2182 CHECK_RECTS(get_rects_multi(split_container, { 50 }, sep.x), get_child_rects(split_container));
2183 child_b->set_visible(true);
2184 MessageQueue::get_singleton()->flush();
2185 CHECK(split_container->get_split_offsets() == def_pos);
2186 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2187
2188 // Hide and show the last child.
2189 child_c->set_visible(false);
2190 MessageQueue::get_singleton()->flush();
2191 CHECK(split_container->get_split_offsets() == Vector<int>({ 50 }));
2192 CHECK_RECTS(get_rects_multi(split_container, { 50 }, sep.x), get_child_rects(split_container));
2193 child_c->set_visible(true);
2194 MessageQueue::get_singleton()->flush();
2195 CHECK(split_container->get_split_offsets() == def_pos);
2196 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2197
2198 set_size_flags(split_container, { 1, 1, 1 }); // All expanded.
2199 split_container->set_split_offsets({ 50, 60 });
2200 MessageQueue::get_singleton()->flush();
2201 int child_3_expanded_size = (split_container->get_size().x - sep.x * 2) / 3;
2202 def_pos = { child_3_expanded_size + 50, child_3_expanded_size * 2 + sep.x + 1 + 60 };
2203 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2204
2205 // Hide and show the first child.
2206 int child_2_expanded_size = (split_container->get_size().x - sep.x) / 2;
2207 child_a->set_visible(false);
2208 MessageQueue::get_singleton()->flush();
2209 int half_point = (split_container->get_size().x - def_pos[0]) / 2 - sep.x;
2210 int so = child_3_expanded_size + 11 - half_point; // 11 is from 60 - 50 + 1 to get the second child's size.
2211 CHECK_RECTS(get_rects_multi(split_container, { child_2_expanded_size + so }, sep.x), get_child_rects(split_container));
2212 CHECK(split_container->get_split_offsets() == Vector<int>({ so }));
2213 child_a->set_visible(true);
2214 MessageQueue::get_singleton()->flush();
2215 CHECK_RECTS(get_rects_multi(split_container, def_pos, sep.x), get_child_rects(split_container));
2216 CHECK(split_container->get_split_offsets() == Vector<int>({ 50, 60 }));
2217
2218 // Hide and show the second child.
2219 child_b->set_visible(false);
2220 MessageQueue::get_singleton()->flush();
2221 half_point = (split_container->get_size().x - (def_pos[1] - def_pos[0] - sep.x)) / 2 - sep.x + 1;
2222 so = def_pos[0] - half_point;
2223 CHECK_RECTS(get_rects_multi(split_container, { child_2_expanded_size + so }, sep.x), get_child_rects(split_container));
2224 CHECK(split_container->get_split_offsets() == Vector<int>({ so }));
2225 child_b->set_visible(true);
2226 MessageQueue::get_singleton()->flush();
2227 // There is lost precision due to SplitContainer using ints, so this is off by one.
2228 CHECK_RECTS(get_rects_multi(split_container, { def_pos[0] - 1, def_pos[1] - 1 }, sep.x), get_child_rects(split_container));
2229 CHECK(split_container->get_split_offsets() == Vector<int>({ 49, 59 }));
2230
2231 // Hide and show the last child.
2232 split_container->set_split_offsets({ 50, 60 });
2233 child_c->set_visible(false);
2234 MessageQueue::get_singleton()->flush();
2235 half_point = (def_pos[1] - sep.x) / 2 + 1;
2236 so = def_pos[0] - half_point;
2237 CHECK_RECTS(get_rects_multi(split_container, { child_2_expanded_size + so }, sep.x), get_child_rects(split_container));
2238 CHECK(split_container->get_split_offsets() == Vector<int>({ so }));
2239 child_c->set_visible(true);
2240 MessageQueue::get_singleton()->flush();
2241 CHECK_RECTS(get_rects_multi(split_container, { def_pos[0] - 1, def_pos[1] - 1 }, sep.x), get_child_rects(split_container));
2242 CHECK(split_container->get_split_offsets() == Vector<int>({ 49, 59 }));
2243 }
2244
2245 SUBCASE("[SplitContainer] Adjust split offset when moving children") {
2246 split_container->set_split_offsets({ 50, 80 });
2247 split_container->move_child(child_a, 1);
2248 Vector<int> pos = { 30 - sep.x, 80 }; // 30 = 80 - 50.
2249 MessageQueue::get_singleton()->flush();
2250 CHECK(split_container->get_split_offsets() == pos);
2251 CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2252
2253 // Move last child to first.
2254 split_container->set_split_offsets({ 50, 80 });
2255 split_container->move_child(child_c, 0);
2256 pos = { (int)split_container->get_size().x - 80 - sep.x, (int)split_container->get_size().x - 30 };
2257 MessageQueue::get_singleton()->flush();
2258 CHECK(split_container->get_split_offsets() == pos);
2259 CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2260
2261 // Move it back.
2262 split_container->move_child(child_c, 2);
2263 pos = { 50, 80 };
2264 MessageQueue::get_singleton()->flush();
2265 CHECK(split_container->get_split_offsets() == pos);
2266 CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2267 }
2268
2269 SUBCASE("[SplitContainer] Showing child with not enough space shrinks the largest child first") {
2270 set_size_flags(split_container, { -1, -1, -1 }); // None expanded.
2271
2272 // Second child is largest.
2273 child_a->set_visible(false);
2274 Vector<int> pos = { 360 };
2275 split_container->set_split_offsets(pos);
2276
2277 MessageQueue::get_singleton()->flush();
2278 CHECK(split_container->get_split_offsets() == pos);
2279 CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2280
2281 child_a->set_size(Vector2(100, 100));
2282 MessageQueue::get_singleton()->flush();
2283 CHECK(split_container->get_split_offsets() == pos);
2284 CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2285
2286 child_a->set_visible(true);
2287 pos = { 100, 360 };
2288 MessageQueue::get_singleton()->flush();
2289 CHECK(split_container->get_split_offsets() == pos);
2290 CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2291
2292 // Last child is largest.
2293 child_a->set_visible(false);
2294 pos = { 60 };
2295 split_container->set_split_offsets(pos);
2296
2297 MessageQueue::get_singleton()->flush();
2298 CHECK(split_container->get_split_offsets() == pos);
2299 CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2300
2301 child_a->set_size(Vector2(100, 100));
2302 MessageQueue::get_singleton()->flush();
2303 CHECK(split_container->get_split_offsets() == pos);
2304 CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2305
2306 child_a->set_visible(true);
2307 pos = { 100, 160 + sep.x };
2308 MessageQueue::get_singleton()->flush();
2309 CHECK(split_container->get_split_offsets() == pos);
2310 CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2311
2312 // Both visible children are the same size.
2313 child_a->set_visible(false);
2314 pos = { (int)split_container->get_size().x / 2 - sep.x / 2 };
2315 split_container->set_split_offsets(pos);
2316
2317 MessageQueue::get_singleton()->flush();
2318 CHECK(split_container->get_split_offsets() == pos);
2319 CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2320 CHECK(child_b->get_size().x == child_c->get_size().x);
2321
2322 child_a->set_size(Vector2(100, 100));
2323 MessageQueue::get_singleton()->flush();
2324 CHECK(split_container->get_split_offsets() == pos);
2325 CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2326
2327 child_a->set_visible(true);
2328 pos = { 100, (int)split_container->get_size().x / 2 + 50 };
2329 MessageQueue::get_singleton()->flush();
2330 CHECK(split_container->get_split_offsets() == pos);
2331 CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2332 CHECK(child_b->get_size().x == child_c->get_size().x);
2333
2334 // Second child is slightly larger than the last child.
2335 child_a->set_visible(false);
2336 pos = { (int)split_container->get_size().x / 2 - sep.x / 2 + 20 };
2337 split_container->set_split_offsets(pos);
2338
2339 MessageQueue::get_singleton()->flush();
2340 CHECK(split_container->get_split_offsets() == pos);
2341 CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2342
2343 child_a->set_size(Vector2(100, 100));
2344 MessageQueue::get_singleton()->flush();
2345 CHECK(split_container->get_split_offsets() == pos);
2346 CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2347
2348 child_a->set_visible(true);
2349 pos = { 100, (int)split_container->get_size().x / 2 + 50 };
2350 MessageQueue::get_singleton()->flush();
2351 CHECK(split_container->get_split_offsets() == pos);
2352 CHECK_RECTS(get_rects_multi(split_container, pos, sep.x), get_child_rects(split_container));
2353 CHECK(child_b->get_size().x == child_c->get_size().x);
2354 }
2355
2356 memdelete(split_container);
2357 }
2358
2359 } // namespace TestSplitContainer