Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/tests/scene/test_split_container.h
10277 views
1
/**************************************************************************/
2
/* test_split_container.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "scene/gui/split_container.h"
34
#include "scene/main/window.h"
35
36
#include "tests/test_macros.h"
37
38
namespace TestSplitContainer {
39
40
static inline void check_positions(SplitContainer *p_sc, const Vector<int> &p_positions, int p_sep, bool p_horizontal = true) {
41
// Checks the rects of each split container child.
42
CHECK(p_sc->get_child_count(false) == p_positions.size() + 1);
43
int last_pos = 0;
44
for (int i = 0; i < p_sc->get_child_count(false); i++) {
45
// Assuming there is no invalid children.
46
Control *c = Object::cast_to<Control>(p_sc->get_child(i, false));
47
int pos = i >= p_positions.size() ? p_sc->get_size()[p_horizontal ? 0 : 1] : p_positions[i];
48
Rect2 rect;
49
if (p_horizontal) {
50
rect.size.y = p_sc->get_size().y;
51
rect.position.x = last_pos;
52
rect.size.x = pos - last_pos;
53
} else {
54
rect.size.x = p_sc->get_size().x;
55
rect.position.y = last_pos;
56
rect.size.y = pos - last_pos;
57
}
58
CHECK_MESSAGE(c->get_rect() == rect, vformat("Child %s is the wrong size.", i));
59
last_pos = pos + p_sep;
60
}
61
}
62
63
static inline void check_position(SplitContainer *p_sc, int p_position, int p_sep, bool p_horizontal = true) {
64
check_positions(p_sc, { p_position }, p_sep, p_horizontal);
65
}
66
67
static inline void check_positions_rtl(SplitContainer *p_sc, const Vector<int> &p_positions, int p_sep) {
68
// Checks the rects of each split container child. Right to left layout.
69
CHECK(p_sc->get_child_count(false) == p_positions.size() + 1);
70
int last_pos = p_sc->get_size().x;
71
for (int i = 0; i < p_sc->get_child_count(false); i++) {
72
// Assuming there is no invalid children.
73
Control *c = Object::cast_to<Control>(p_sc->get_child(i, false));
74
int pos = i >= p_positions.size() ? 0 : p_sc->get_size().x - p_positions[i];
75
Rect2 rect;
76
rect.size.y = p_sc->get_size().y;
77
rect.position.x = pos;
78
rect.size.x = last_pos - pos;
79
CHECK_MESSAGE(c->get_rect() == rect, vformat("Child %s is the wrong size.", i));
80
last_pos = pos - p_sep;
81
}
82
}
83
84
static inline void check_position_rtl(SplitContainer *p_sc, int p_position, int p_sep) {
85
check_positions_rtl(p_sc, { p_position }, p_sep);
86
}
87
88
TEST_CASE("[SceneTree][SplitContainer] Add children") {
89
SplitContainer *split_container = memnew(SplitContainer);
90
split_container->set_size(Size2(500, 500));
91
SceneTree::get_singleton()->get_root()->add_child(split_container);
92
93
SUBCASE("[SplitContainer] One child") {
94
Control *child_a = memnew(Control);
95
split_container->add_child(child_a);
96
MessageQueue::get_singleton()->flush();
97
98
// One child will fill the entire area.
99
CHECK(child_a->get_rect() == split_container->get_rect());
100
101
split_container->set_vertical(true);
102
CHECK(child_a->get_rect() == split_container->get_rect());
103
104
memdelete(child_a);
105
}
106
107
SUBCASE("[SplitContainer] Preserve split offset") {
108
// The split offset is preserved through adding, removing, and changing visibility of children.
109
split_container->set_split_offset(100);
110
CHECK(split_container->get_split_offset() == 100);
111
112
Control *child_a = memnew(Control);
113
split_container->add_child(child_a);
114
MessageQueue::get_singleton()->flush();
115
CHECK(split_container->get_split_offset() == 100);
116
117
Control *child_b = memnew(Control);
118
split_container->add_child(child_b);
119
MessageQueue::get_singleton()->flush();
120
CHECK(split_container->get_split_offset() == 100);
121
122
child_a->hide();
123
MessageQueue::get_singleton()->flush();
124
CHECK(split_container->get_split_offset() == 100);
125
126
child_b->hide();
127
MessageQueue::get_singleton()->flush();
128
CHECK(split_container->get_split_offset() == 100);
129
130
child_b->show();
131
MessageQueue::get_singleton()->flush();
132
CHECK(split_container->get_split_offset() == 100);
133
134
child_a->show();
135
MessageQueue::get_singleton()->flush();
136
CHECK(split_container->get_split_offset() == 100);
137
138
split_container->remove_child(child_a);
139
MessageQueue::get_singleton()->flush();
140
CHECK(split_container->get_split_offset() == 100);
141
142
split_container->add_child(child_a);
143
MessageQueue::get_singleton()->flush();
144
CHECK(split_container->get_split_offset() == 100);
145
146
memdelete(child_a);
147
memdelete(child_b);
148
}
149
150
memdelete(split_container);
151
}
152
153
TEST_CASE("[SceneTree][SplitContainer] Dragger visibility") {
154
SplitContainer *split_container = memnew(SplitContainer);
155
split_container->set_size(Size2(500, 500));
156
SceneTree::get_singleton()->get_root()->add_child(split_container);
157
Control *child_a = memnew(Control);
158
Control *child_b = memnew(Control);
159
split_container->add_child(child_a);
160
split_container->add_child(child_b);
161
SplitContainerDragger *dragger = Object::cast_to<SplitContainerDragger>(split_container->get_child(2, true));
162
163
split_container->add_theme_constant_override("autohide", 0);
164
MessageQueue::get_singleton()->flush();
165
166
const int sep_constant = split_container->get_theme_constant("separation");
167
const Size2i separator_size = 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()));
168
169
SUBCASE("[SplitContainer] Visibility based on child count") {
170
split_container->remove_child(child_a);
171
split_container->remove_child(child_b);
172
MessageQueue::get_singleton()->flush();
173
174
// No children, not visible.
175
CHECK_FALSE(dragger->is_visible());
176
177
// Add one child, not visible.
178
split_container->add_child(child_a);
179
MessageQueue::get_singleton()->flush();
180
CHECK_FALSE(dragger->is_visible());
181
182
// Two children, visible.
183
split_container->add_child(child_b);
184
MessageQueue::get_singleton()->flush();
185
CHECK(dragger->is_visible());
186
187
// Remove a child, not visible.
188
split_container->remove_child(child_b);
189
MessageQueue::get_singleton()->flush();
190
CHECK_FALSE(dragger->is_visible());
191
}
192
193
SUBCASE("[SplitContainer] Set dragger visibility") {
194
split_container->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN);
195
MessageQueue::get_singleton()->flush();
196
check_position(split_container, 0, separator_size.x);
197
// Can't check the visibility since it happens in draw.
198
199
split_container->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN_COLLAPSED);
200
MessageQueue::get_singleton()->flush();
201
check_position(split_container, 0, 0);
202
203
split_container->set_dragger_visibility(SplitContainer::DRAGGER_VISIBLE);
204
MessageQueue::get_singleton()->flush();
205
check_position(split_container, 0, separator_size.x);
206
}
207
208
SUBCASE("[SplitContainer] Not visible when collapsed") {
209
split_container->set_collapsed(true);
210
MessageQueue::get_singleton()->flush();
211
CHECK_FALSE(dragger->is_visible());
212
213
split_container->set_collapsed(false);
214
MessageQueue::get_singleton()->flush();
215
CHECK(dragger->is_visible());
216
}
217
218
memdelete(child_a);
219
memdelete(child_b);
220
memdelete(split_container);
221
}
222
223
TEST_CASE("[SceneTree][SplitContainer] Collapsed") {
224
DisplayServerMock *DS = (DisplayServerMock *)(DisplayServer::get_singleton());
225
226
SplitContainer *split_container = memnew(SplitContainer);
227
split_container->set_size(Size2(500, 500));
228
SceneTree::get_singleton()->get_root()->add_child(split_container);
229
Control *child_a = memnew(Control);
230
split_container->add_child(child_a);
231
Control *child_b = memnew(Control);
232
split_container->add_child(child_b);
233
MessageQueue::get_singleton()->flush();
234
235
const int sep_constant = split_container->get_theme_constant("separation");
236
const Size2i separator_size = 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()));
237
238
SUBCASE("[SplitContainer] Dragging and cursor") {
239
split_container->set_collapsed(true);
240
241
// Cursor is default.
242
SEND_GUI_MOUSE_MOTION_EVENT(Point2(1, 1), MouseButtonMask::NONE, Key::NONE);
243
CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_ARROW);
244
245
// Dragger is disabled, cannot drag.
246
SEND_GUI_MOUSE_BUTTON_EVENT(Point2(1, 1), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
247
MessageQueue::get_singleton()->flush();
248
check_position(split_container, 0, separator_size.x);
249
CHECK(split_container->get_split_offset() == 0);
250
SEND_GUI_MOUSE_MOTION_EVENT(Point2(10, 1), MouseButtonMask::LEFT, Key::NONE);
251
MessageQueue::get_singleton()->flush();
252
check_position(split_container, 0, separator_size.x);
253
CHECK(split_container->get_split_offset() == 0);
254
}
255
256
SUBCASE("[SplitContainer] No expand flags") {
257
int def_pos = 0;
258
259
split_container->set_split_offset(10);
260
MessageQueue::get_singleton()->flush();
261
check_position(split_container, def_pos + 10, separator_size.x);
262
263
split_container->set_collapsed(true);
264
MessageQueue::get_singleton()->flush();
265
266
// The split offset is treated as 0 when collapsed.
267
check_position(split_container, def_pos, separator_size.x);
268
CHECK(split_container->get_split_offset() == 10);
269
}
270
271
SUBCASE("[SplitContainer] First child expanded") {
272
int def_pos = split_container->get_size().x - separator_size.x;
273
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
274
split_container->set_split_offset(-10);
275
MessageQueue::get_singleton()->flush();
276
277
check_position(split_container, def_pos - 10, separator_size.x);
278
279
split_container->set_collapsed(true);
280
MessageQueue::get_singleton()->flush();
281
282
// The split offset is treated as 0 when collapsed.
283
check_position(split_container, def_pos, separator_size.x);
284
CHECK(split_container->get_split_offset() == -10);
285
}
286
287
SUBCASE("[SplitContainer] Second child expanded") {
288
int def_pos = 0;
289
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
290
split_container->set_split_offset(10);
291
MessageQueue::get_singleton()->flush();
292
293
check_position(split_container, def_pos + 10, separator_size.x);
294
295
split_container->set_collapsed(true);
296
MessageQueue::get_singleton()->flush();
297
298
// The split offset is treated as 0 when collapsed.
299
check_position(split_container, def_pos, separator_size.x);
300
CHECK(split_container->get_split_offset() == 10);
301
}
302
303
SUBCASE("[SplitContainer] Both children expanded") {
304
int def_pos = (split_container->get_size().y - separator_size.y) / 2;
305
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
306
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
307
split_container->set_split_offset(10);
308
MessageQueue::get_singleton()->flush();
309
310
check_position(split_container, def_pos + 10, separator_size.x);
311
312
split_container->set_collapsed(true);
313
MessageQueue::get_singleton()->flush();
314
315
// The split offset is treated as 0 when collapsed.
316
check_position(split_container, def_pos, separator_size.x);
317
CHECK(split_container->get_split_offset() == 10);
318
}
319
320
memdelete(child_a);
321
memdelete(child_b);
322
memdelete(split_container);
323
}
324
325
TEST_CASE("[SceneTree][SplitContainer] Cursor shape") {
326
DisplayServerMock *DS = (DisplayServerMock *)(DisplayServer::get_singleton());
327
328
SplitContainer *split_container = memnew(SplitContainer);
329
split_container->set_size(Size2(500, 500));
330
SceneTree::get_singleton()->get_root()->add_child(split_container);
331
Control *child_a = memnew(Control);
332
split_container->add_child(child_a);
333
Control *child_b = memnew(Control);
334
split_container->add_child(child_b);
335
MessageQueue::get_singleton()->flush();
336
337
Point2 on_dragger = Point2(1, 1);
338
Point2 not_on_dragger = Point2(50, 50);
339
340
// Default cursor shape.
341
SEND_GUI_MOUSE_MOTION_EVENT(not_on_dragger, MouseButtonMask::NONE, Key::NONE);
342
CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_ARROW);
343
344
// Horizontal cursor shape.
345
SEND_GUI_MOUSE_MOTION_EVENT(on_dragger, MouseButtonMask::NONE, Key::NONE);
346
CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_HSPLIT);
347
348
// Vertical cursor shape.
349
split_container->set_vertical(true);
350
SEND_GUI_MOUSE_MOTION_EVENT(on_dragger, MouseButtonMask::NONE, Key::NONE);
351
CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_VSPLIT);
352
353
// Move off, default cursor shape.
354
SEND_GUI_MOUSE_MOTION_EVENT(not_on_dragger, MouseButtonMask::NONE, Key::NONE);
355
CHECK(DS->get_cursor_shape() == DisplayServer::CURSOR_ARROW);
356
357
memdelete(child_a);
358
memdelete(child_b);
359
memdelete(split_container);
360
}
361
362
TEST_CASE("[SceneTree][SplitContainer] Two children") {
363
SplitContainer *split_container = memnew(SplitContainer);
364
split_container->set_size(Size2(500, 500));
365
SceneTree::get_singleton()->get_root()->add_child(split_container);
366
Control *child_a = memnew(Control);
367
Control *child_b = memnew(Control);
368
split_container->add_child(child_a);
369
split_container->add_child(child_b);
370
MessageQueue::get_singleton()->flush();
371
372
const int sep_constant = split_container->get_theme_constant("separation");
373
const Size2i separator_size = 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()));
374
375
SUBCASE("[SplitContainer] Minimum size") {
376
// Minimum size is the sum of both children's minimum sizes and the separator depending on the vertical axis.
377
child_a->set_custom_minimum_size(Size2(100, 200));
378
child_b->set_custom_minimum_size(Size2(100, 200));
379
MessageQueue::get_singleton()->flush();
380
381
Size2 min_size = split_container->get_minimum_size();
382
CHECK(min_size.x == 200 + separator_size.x);
383
CHECK(min_size.y == 200);
384
385
split_container->set_vertical(true);
386
MessageQueue::get_singleton()->flush();
387
min_size = split_container->get_minimum_size();
388
CHECK(min_size.x == 100);
389
CHECK(min_size.y == 400 + separator_size.y);
390
}
391
392
SUBCASE("[SplitContainer] Default position") {
393
SUBCASE("[SplitContainer] Vertical") {
394
// Make sure clamping the split offset doesn't change it or the position.
395
split_container->set_vertical(true);
396
397
// No expand flags set.
398
MessageQueue::get_singleton()->flush();
399
int def_pos = 0;
400
check_position(split_container, def_pos, separator_size.y, false);
401
split_container->clamp_split_offset();
402
MessageQueue::get_singleton()->flush();
403
CHECK(split_container->get_split_offset() == 0);
404
check_position(split_container, def_pos, separator_size.y, false);
405
406
// First expand flags set.
407
child_a->set_v_size_flags(Control::SIZE_EXPAND_FILL);
408
child_b->set_v_size_flags(Control::SIZE_FILL);
409
MessageQueue::get_singleton()->flush();
410
def_pos = split_container->get_size().y - separator_size.y;
411
check_position(split_container, def_pos, separator_size.y, false);
412
split_container->clamp_split_offset();
413
MessageQueue::get_singleton()->flush();
414
CHECK(split_container->get_split_offset() == 0);
415
check_position(split_container, def_pos, separator_size.y, false);
416
417
// Second expand flags set.
418
child_a->set_v_size_flags(Control::SIZE_FILL);
419
child_b->set_v_size_flags(Control::SIZE_EXPAND_FILL);
420
MessageQueue::get_singleton()->flush();
421
def_pos = 0;
422
check_position(split_container, 0, separator_size.y, false);
423
split_container->clamp_split_offset();
424
MessageQueue::get_singleton()->flush();
425
CHECK(split_container->get_split_offset() == 0);
426
check_position(split_container, def_pos, separator_size.y, false);
427
428
// Both expand flags set.
429
child_a->set_v_size_flags(Control::SIZE_EXPAND_FILL);
430
child_b->set_v_size_flags(Control::SIZE_EXPAND_FILL);
431
MessageQueue::get_singleton()->flush();
432
def_pos = (split_container->get_size().y - separator_size.y) / 2;
433
check_position(split_container, def_pos, separator_size.y, false);
434
split_container->clamp_split_offset();
435
MessageQueue::get_singleton()->flush();
436
CHECK(split_container->get_split_offset() == 0);
437
check_position(split_container, def_pos, separator_size.y, false);
438
439
// Unequal stretch ratios.
440
child_a->set_stretch_ratio(2.0);
441
MessageQueue::get_singleton()->flush();
442
def_pos = (split_container->get_size().y * 2 / 3) - separator_size.y / 2;
443
check_position(split_container, def_pos, separator_size.y, false);
444
split_container->clamp_split_offset();
445
MessageQueue::get_singleton()->flush();
446
CHECK(split_container->get_split_offset() == 0);
447
check_position(split_container, def_pos, separator_size.y, false);
448
}
449
450
SUBCASE("[SplitContainer] Right to left") {
451
split_container->set_layout_direction(Control::LAYOUT_DIRECTION_RTL);
452
split_container->set_position(Point2(0, 0));
453
454
// No expand flags set.
455
MessageQueue::get_singleton()->flush();
456
int def_pos = 0;
457
check_position_rtl(split_container, def_pos, separator_size.y);
458
split_container->clamp_split_offset();
459
MessageQueue::get_singleton()->flush();
460
CHECK(split_container->get_split_offset() == 0);
461
check_position_rtl(split_container, def_pos, separator_size.y);
462
463
// First expand flags set.
464
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
465
child_b->set_h_size_flags(Control::SIZE_FILL);
466
MessageQueue::get_singleton()->flush();
467
def_pos = split_container->get_size().y - separator_size.y;
468
check_position_rtl(split_container, def_pos, separator_size.y);
469
split_container->clamp_split_offset();
470
MessageQueue::get_singleton()->flush();
471
CHECK(split_container->get_split_offset() == 0);
472
check_position_rtl(split_container, def_pos, separator_size.y);
473
474
// Second expand flags set.
475
child_a->set_h_size_flags(Control::SIZE_FILL);
476
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
477
MessageQueue::get_singleton()->flush();
478
def_pos = 0;
479
check_position_rtl(split_container, 0, separator_size.y);
480
split_container->clamp_split_offset();
481
MessageQueue::get_singleton()->flush();
482
CHECK(split_container->get_split_offset() == 0);
483
check_position_rtl(split_container, def_pos, separator_size.y);
484
485
// Both expand flags set.
486
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
487
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
488
MessageQueue::get_singleton()->flush();
489
def_pos = (split_container->get_size().y - separator_size.y) / 2;
490
check_position_rtl(split_container, def_pos, separator_size.y);
491
split_container->clamp_split_offset();
492
MessageQueue::get_singleton()->flush();
493
CHECK(split_container->get_split_offset() == 0);
494
check_position_rtl(split_container, def_pos, separator_size.y);
495
496
// Unequal stretch ratios.
497
child_a->set_stretch_ratio(2.0);
498
MessageQueue::get_singleton()->flush();
499
def_pos = (split_container->get_size().y * 2 / 3) - separator_size.y / 2;
500
check_position_rtl(split_container, def_pos, separator_size.y);
501
split_container->clamp_split_offset();
502
MessageQueue::get_singleton()->flush();
503
CHECK(split_container->get_split_offset() == 0);
504
check_position_rtl(split_container, def_pos, separator_size.y);
505
}
506
507
SUBCASE("[SplitContainer] No expand flags") {
508
int def_pos = 0;
509
510
check_position(split_container, def_pos, separator_size.x);
511
512
split_container->clamp_split_offset();
513
MessageQueue::get_singleton()->flush();
514
CHECK(split_container->get_split_offset() == 0);
515
check_position(split_container, def_pos, separator_size.x);
516
517
// Minimum sizes affect default position.
518
519
// First child with minimum size.
520
child_a->set_custom_minimum_size(Size2(400, 0));
521
MessageQueue::get_singleton()->flush();
522
def_pos = 400;
523
check_position(split_container, def_pos, separator_size.x);
524
split_container->clamp_split_offset();
525
MessageQueue::get_singleton()->flush();
526
CHECK(split_container->get_split_offset() == def_pos);
527
check_position(split_container, def_pos, separator_size.x);
528
529
// Second child with minimum size.
530
child_a->set_custom_minimum_size(Size2(0, 0));
531
child_b->set_custom_minimum_size(Size2(400, 0));
532
MessageQueue::get_singleton()->flush();
533
def_pos = split_container->get_size().x - 400 - separator_size.x;
534
check_position(split_container, def_pos, separator_size.x);
535
split_container->clamp_split_offset();
536
MessageQueue::get_singleton()->flush();
537
CHECK(split_container->get_split_offset() == def_pos);
538
check_position(split_container, def_pos, separator_size.x);
539
540
// Both children with minimum size.
541
child_a->set_custom_minimum_size(Size2(200, 0));
542
child_b->set_custom_minimum_size(Size2(288, 0));
543
MessageQueue::get_singleton()->flush();
544
def_pos = 200;
545
check_position(split_container, def_pos, separator_size.x);
546
split_container->clamp_split_offset();
547
MessageQueue::get_singleton()->flush();
548
CHECK(split_container->get_split_offset() == def_pos);
549
check_position(split_container, def_pos, separator_size.x);
550
}
551
552
SUBCASE("[SplitContainer] First child expanded") {
553
const int def_pos = split_container->get_size().x - separator_size.x;
554
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
555
MessageQueue::get_singleton()->flush();
556
557
check_position(split_container, def_pos, separator_size.x);
558
559
split_container->clamp_split_offset();
560
MessageQueue::get_singleton()->flush();
561
CHECK(split_container->get_split_offset() == 0);
562
check_position(split_container, def_pos, separator_size.x);
563
564
// Minimum sizes affect default position.
565
566
// First child with minimum size.
567
child_a->set_custom_minimum_size(Size2(400, 0));
568
MessageQueue::get_singleton()->flush();
569
check_position(split_container, def_pos, separator_size.x);
570
split_container->clamp_split_offset();
571
MessageQueue::get_singleton()->flush();
572
CHECK(split_container->get_split_offset() == 0);
573
check_position(split_container, def_pos, separator_size.x);
574
575
// Second child with minimum size.
576
child_a->set_custom_minimum_size(Size2(0, 0));
577
child_b->set_custom_minimum_size(Size2(400, 0));
578
MessageQueue::get_singleton()->flush();
579
int pos = split_container->get_size().x - 400 - separator_size.x;
580
check_position(split_container, pos, separator_size.x);
581
split_container->clamp_split_offset();
582
MessageQueue::get_singleton()->flush();
583
CHECK(split_container->get_split_offset() == pos - def_pos);
584
check_position(split_container, pos, separator_size.x);
585
586
// Both children with minimum size.
587
child_a->set_custom_minimum_size(Size2(200, 0));
588
child_b->set_custom_minimum_size(Size2(288, 0));
589
MessageQueue::get_singleton()->flush();
590
pos = 200;
591
check_position(split_container, pos, separator_size.x);
592
split_container->clamp_split_offset();
593
MessageQueue::get_singleton()->flush();
594
CHECK(split_container->get_split_offset() == pos - def_pos);
595
check_position(split_container, pos, separator_size.x);
596
}
597
598
SUBCASE("[SplitContainer] Second child expanded") {
599
int def_pos = 0;
600
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
601
MessageQueue::get_singleton()->flush();
602
603
check_position(split_container, def_pos, separator_size.x);
604
605
split_container->clamp_split_offset();
606
MessageQueue::get_singleton()->flush();
607
CHECK(split_container->get_split_offset() == 0);
608
check_position(split_container, def_pos, separator_size.x);
609
610
// Minimum sizes affect default position.
611
612
// First child with minimum size.
613
child_a->set_custom_minimum_size(Size2(400, 0));
614
MessageQueue::get_singleton()->flush();
615
def_pos = 400;
616
check_position(split_container, def_pos, separator_size.x);
617
split_container->clamp_split_offset();
618
MessageQueue::get_singleton()->flush();
619
CHECK(split_container->get_split_offset() == def_pos);
620
check_position(split_container, def_pos, separator_size.x);
621
622
// Second child with minimum size.
623
child_a->set_custom_minimum_size(Size2(0, 0));
624
child_b->set_custom_minimum_size(Size2(400, 0));
625
MessageQueue::get_singleton()->flush();
626
def_pos = 500 - 400 - separator_size.x;
627
check_position(split_container, def_pos, separator_size.x);
628
split_container->clamp_split_offset();
629
MessageQueue::get_singleton()->flush();
630
CHECK(split_container->get_split_offset() == def_pos);
631
check_position(split_container, def_pos, separator_size.x);
632
633
// Both children with minimum size.
634
child_a->set_custom_minimum_size(Size2(200, 0));
635
child_b->set_custom_minimum_size(Size2(288, 0));
636
MessageQueue::get_singleton()->flush();
637
def_pos = 200;
638
check_position(split_container, def_pos, separator_size.x);
639
split_container->clamp_split_offset();
640
MessageQueue::get_singleton()->flush();
641
CHECK(split_container->get_split_offset() == def_pos);
642
check_position(split_container, def_pos, separator_size.x);
643
}
644
645
SUBCASE("[SplitContainer] Both children expanded") {
646
const int def_pos = (split_container->get_size().x - separator_size.x) / 2;
647
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
648
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
649
MessageQueue::get_singleton()->flush();
650
651
check_position(split_container, def_pos, separator_size.x);
652
653
split_container->clamp_split_offset();
654
MessageQueue::get_singleton()->flush();
655
CHECK(split_container->get_split_offset() == 0);
656
check_position(split_container, def_pos, separator_size.x);
657
658
// Minimum sizes affect default position.
659
660
// First child with minimum size.
661
child_a->set_custom_minimum_size(Size2(400, 0));
662
MessageQueue::get_singleton()->flush();
663
int pos = 400;
664
check_position(split_container, pos, separator_size.x);
665
split_container->clamp_split_offset();
666
MessageQueue::get_singleton()->flush();
667
CHECK(split_container->get_split_offset() == pos - def_pos);
668
check_position(split_container, pos, separator_size.x);
669
670
// Second child with minimum size.
671
child_a->set_custom_minimum_size(Size2(0, 0));
672
child_b->set_custom_minimum_size(Size2(400, 0));
673
MessageQueue::get_singleton()->flush();
674
pos = split_container->get_size().x - 400 - separator_size.x;
675
check_position(split_container, pos, separator_size.x);
676
split_container->clamp_split_offset();
677
MessageQueue::get_singleton()->flush();
678
CHECK(split_container->get_split_offset() == pos - def_pos);
679
check_position(split_container, pos, separator_size.x);
680
681
// Both children with minimum size.
682
child_a->set_custom_minimum_size(Size2(200, 0));
683
child_b->set_custom_minimum_size(Size2(288, 0));
684
MessageQueue::get_singleton()->flush();
685
pos = 200;
686
check_position(split_container, pos, separator_size.x);
687
split_container->clamp_split_offset();
688
MessageQueue::get_singleton()->flush();
689
CHECK(split_container->get_split_offset() == pos - def_pos);
690
check_position(split_container, pos, separator_size.x);
691
}
692
693
SUBCASE("[SplitContainer] Unequal stretch ratios") {
694
const int def_pos = (split_container->get_size().x * 2 / 3) - separator_size.x / 2;
695
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
696
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
697
child_a->set_stretch_ratio(2.0);
698
MessageQueue::get_singleton()->flush();
699
700
check_position(split_container, def_pos, separator_size.x);
701
702
split_container->clamp_split_offset();
703
MessageQueue::get_singleton()->flush();
704
CHECK(split_container->get_split_offset() == 0);
705
check_position(split_container, def_pos, separator_size.x);
706
707
// Minimum sizes affect default position.
708
709
// First child with minimum size.
710
child_a->set_custom_minimum_size(Size2(400, 0));
711
MessageQueue::get_singleton()->flush();
712
int pos = 400;
713
check_position(split_container, pos, separator_size.x);
714
split_container->clamp_split_offset();
715
MessageQueue::get_singleton()->flush();
716
CHECK(split_container->get_split_offset() == pos - def_pos);
717
check_position(split_container, pos, separator_size.x);
718
719
// Second child with minimum size.
720
child_a->set_custom_minimum_size(Size2(0, 0));
721
child_b->set_custom_minimum_size(Size2(400, 0));
722
MessageQueue::get_singleton()->flush();
723
pos = split_container->get_size().x - 400 - separator_size.x;
724
check_position(split_container, pos, separator_size.x);
725
split_container->clamp_split_offset();
726
MessageQueue::get_singleton()->flush();
727
CHECK(split_container->get_split_offset() == pos - def_pos);
728
check_position(split_container, pos, separator_size.x);
729
730
// Both children with minimum size.
731
child_a->set_custom_minimum_size(Size2(200, 0));
732
child_b->set_custom_minimum_size(Size2(288, 0));
733
MessageQueue::get_singleton()->flush();
734
pos = 200;
735
check_position(split_container, pos, separator_size.x);
736
split_container->clamp_split_offset();
737
MessageQueue::get_singleton()->flush();
738
CHECK(split_container->get_split_offset() == pos - def_pos);
739
check_position(split_container, pos, separator_size.x);
740
}
741
}
742
743
SUBCASE("[SplitContainer] Set split offset") {
744
SUBCASE("[SplitContainer] Right to left") {
745
split_container->set_layout_direction(Control::LAYOUT_DIRECTION_RTL);
746
split_container->set_position(Point2(0, 0));
747
int def_pos = 0;
748
// Positive.
749
split_container->set_split_offset(10);
750
MessageQueue::get_singleton()->flush();
751
CHECK(split_container->get_split_offset() == 10);
752
check_position_rtl(split_container, def_pos + 10, separator_size.x);
753
754
// Negative.
755
split_container->set_split_offset(-10);
756
MessageQueue::get_singleton()->flush();
757
CHECK(split_container->get_split_offset() == -10);
758
check_position_rtl(split_container, def_pos, separator_size.x);
759
}
760
761
SUBCASE("[SplitContainer] No expand flags") {
762
int def_pos = 0;
763
764
// Positive.
765
split_container->set_split_offset(10);
766
MessageQueue::get_singleton()->flush();
767
CHECK(split_container->get_split_offset() == 10);
768
check_position(split_container, def_pos + 10, separator_size.x);
769
770
// Negative.
771
split_container->set_split_offset(-10);
772
MessageQueue::get_singleton()->flush();
773
CHECK(split_container->get_split_offset() == -10);
774
check_position(split_container, def_pos, separator_size.x);
775
776
// Clamped.
777
split_container->set_split_offset(1000);
778
MessageQueue::get_singleton()->flush();
779
CHECK(split_container->get_split_offset() == 1000);
780
check_position(split_container, split_container->get_size().x - separator_size.x, separator_size.x);
781
}
782
783
SUBCASE("[SplitContainer] First child expanded") {
784
int def_pos = split_container->get_size().x - separator_size.x;
785
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
786
MessageQueue::get_singleton()->flush();
787
788
// Positive.
789
split_container->set_split_offset(10);
790
MessageQueue::get_singleton()->flush();
791
CHECK(split_container->get_split_offset() == 10);
792
check_position(split_container, def_pos, separator_size.x);
793
794
// Negative.
795
split_container->set_split_offset(-10);
796
MessageQueue::get_singleton()->flush();
797
CHECK(split_container->get_split_offset() == -10);
798
check_position(split_container, def_pos - 10, separator_size.x);
799
800
// Clamped.
801
split_container->set_split_offset(-1000);
802
MessageQueue::get_singleton()->flush();
803
CHECK(split_container->get_split_offset() == -1000);
804
check_position(split_container, 0, separator_size.x);
805
}
806
807
SUBCASE("[SplitContainer] Second child expanded") {
808
int def_pos = 0;
809
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
810
MessageQueue::get_singleton()->flush();
811
812
// Positive.
813
split_container->set_split_offset(10);
814
MessageQueue::get_singleton()->flush();
815
CHECK(split_container->get_split_offset() == 10);
816
check_position(split_container, def_pos + 10, separator_size.x);
817
818
// Negative.
819
split_container->set_split_offset(-10);
820
MessageQueue::get_singleton()->flush();
821
CHECK(split_container->get_split_offset() == -10);
822
check_position(split_container, def_pos, separator_size.x);
823
824
// Clamped.
825
split_container->set_split_offset(1000);
826
MessageQueue::get_singleton()->flush();
827
CHECK(split_container->get_split_offset() == 1000);
828
check_position(split_container, split_container->get_size().x - separator_size.x, separator_size.x);
829
}
830
831
SUBCASE("[SplitContainer] Both children expanded") {
832
int def_pos = (split_container->get_size().x - separator_size.x) / 2;
833
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
834
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
835
MessageQueue::get_singleton()->flush();
836
837
// Positive.
838
split_container->set_split_offset(10);
839
MessageQueue::get_singleton()->flush();
840
CHECK(split_container->get_split_offset() == 10);
841
check_position(split_container, def_pos + 10, separator_size.x);
842
843
// Negative.
844
split_container->set_split_offset(-10);
845
MessageQueue::get_singleton()->flush();
846
CHECK(split_container->get_split_offset() == -10);
847
check_position(split_container, def_pos - 10, separator_size.x);
848
849
// Clamped positive.
850
split_container->set_split_offset(1000);
851
MessageQueue::get_singleton()->flush();
852
CHECK(split_container->get_split_offset() == 1000);
853
check_position(split_container, split_container->get_size().x - separator_size.x, separator_size.x);
854
855
// Clamped negative.
856
split_container->set_split_offset(-1000);
857
MessageQueue::get_singleton()->flush();
858
CHECK(split_container->get_split_offset() == -1000);
859
check_position(split_container, 0, separator_size.x);
860
}
861
862
SUBCASE("[SplitContainer] Unequal stretch ratios") {
863
int def_pos = (split_container->get_size().x * 2 / 3) - separator_size.x / 2;
864
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
865
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
866
child_a->set_stretch_ratio(2.0);
867
MessageQueue::get_singleton()->flush();
868
869
// Positive.
870
split_container->set_split_offset(10);
871
MessageQueue::get_singleton()->flush();
872
CHECK(split_container->get_split_offset() == 10);
873
check_position(split_container, def_pos + 10, separator_size.x);
874
875
// Negative.
876
split_container->set_split_offset(-10);
877
MessageQueue::get_singleton()->flush();
878
CHECK(split_container->get_split_offset() == -10);
879
check_position(split_container, def_pos - 10, separator_size.x);
880
881
// Clamped positive.
882
split_container->set_split_offset(1000);
883
MessageQueue::get_singleton()->flush();
884
CHECK(split_container->get_split_offset() == 1000);
885
check_position(split_container, split_container->get_size().x - separator_size.x, separator_size.x);
886
887
// Clamped negative.
888
split_container->set_split_offset(-1000);
889
MessageQueue::get_singleton()->flush();
890
CHECK(split_container->get_split_offset() == -1000);
891
check_position(split_container, 0, separator_size.x);
892
}
893
}
894
895
SUBCASE("[SplitContainer] Keep split offset when changing minimum size") {
896
SUBCASE("[SplitContainer] No expand flags") {
897
int def_pos = 0;
898
899
split_container->set_split_offset(100);
900
child_a->set_custom_minimum_size(Size2(10, 0));
901
MessageQueue::get_singleton()->flush();
902
CHECK(split_container->get_split_offset() == 100);
903
check_position(split_container, def_pos + 100, separator_size.x);
904
905
child_a->set_custom_minimum_size(Size2(50, 0));
906
MessageQueue::get_singleton()->flush();
907
CHECK(split_container->get_split_offset() == 100);
908
check_position(split_container, def_pos + 100, separator_size.x);
909
}
910
911
SUBCASE("[SplitContainer] First child expanded") {
912
int def_pos = split_container->get_size().x - separator_size.x;
913
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
914
MessageQueue::get_singleton()->flush();
915
916
split_container->set_split_offset(-100);
917
child_b->set_custom_minimum_size(Size2(10, 0));
918
MessageQueue::get_singleton()->flush();
919
CHECK(split_container->get_split_offset() == -100);
920
check_position(split_container, def_pos - 100, separator_size.x);
921
922
child_b->set_custom_minimum_size(Size2(50, 0));
923
MessageQueue::get_singleton()->flush();
924
CHECK(split_container->get_split_offset() == -100);
925
check_position(split_container, def_pos - 100, separator_size.x);
926
}
927
928
SUBCASE("[SplitContainer] Second child expanded") {
929
int def_pos = 0;
930
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
931
MessageQueue::get_singleton()->flush();
932
933
split_container->set_split_offset(100);
934
child_a->set_custom_minimum_size(Size2(10, 0));
935
MessageQueue::get_singleton()->flush();
936
CHECK(split_container->get_split_offset() == 100);
937
check_position(split_container, def_pos + 100, separator_size.x);
938
939
child_a->set_custom_minimum_size(Size2(50, 0));
940
MessageQueue::get_singleton()->flush();
941
CHECK(split_container->get_split_offset() == 100);
942
check_position(split_container, def_pos + 100, separator_size.x);
943
}
944
945
SUBCASE("[SplitContainer] Both children expanded") {
946
int def_pos = (split_container->get_size().x - separator_size.x) / 2;
947
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
948
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
949
MessageQueue::get_singleton()->flush();
950
951
split_container->set_split_offset(20);
952
child_a->set_custom_minimum_size(Size2(10, 0));
953
child_b->set_custom_minimum_size(Size2(10, 0));
954
MessageQueue::get_singleton()->flush();
955
CHECK(split_container->get_split_offset() == 20);
956
check_position(split_container, def_pos + 20, separator_size.x);
957
958
child_a->set_custom_minimum_size(Size2(50, 0));
959
child_b->set_custom_minimum_size(Size2(50, 0));
960
MessageQueue::get_singleton()->flush();
961
CHECK(split_container->get_split_offset() == 20);
962
check_position(split_container, def_pos + 20, separator_size.x);
963
}
964
}
965
966
SUBCASE("[SplitContainer] Resize split container") {
967
SUBCASE("[SplitContainer] No expand flags") {
968
int def_pos = 0;
969
// Increase the size.
970
split_container->set_size(Size2(600, 500));
971
MessageQueue::get_singleton()->flush();
972
check_position(split_container, def_pos, separator_size.x);
973
974
// Decrease the size.
975
split_container->set_size(Size2(400, 500));
976
MessageQueue::get_singleton()->flush();
977
check_position(split_container, def_pos, separator_size.x);
978
979
// Change size with a split offset.
980
split_container->set_split_offset(100);
981
MessageQueue::get_singleton()->flush();
982
check_position(split_container, def_pos + 100, separator_size.x);
983
984
split_container->set_size(Size2(500, 500));
985
MessageQueue::get_singleton()->flush();
986
check_position(split_container, def_pos + 100, separator_size.x);
987
CHECK(split_container->get_split_offset() == 100);
988
989
// Change size so that the first child changes size.
990
split_container->set_size(Size2(80, 500));
991
MessageQueue::get_singleton()->flush();
992
check_position(split_container, 80 - separator_size.x, separator_size.x);
993
CHECK(split_container->get_split_offset() == 100);
994
995
// Increase size again.
996
split_container->set_size(Size2(500, 500));
997
MessageQueue::get_singleton()->flush();
998
check_position(split_container, def_pos + 100, separator_size.x);
999
CHECK(split_container->get_split_offset() == 100);
1000
}
1001
1002
SUBCASE("[SplitContainer] First child expanded") {
1003
int def_pos = split_container->get_size().x - separator_size.x;
1004
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1005
MessageQueue::get_singleton()->flush();
1006
1007
// Increase the size.
1008
split_container->set_size(Size2(600, 500));
1009
def_pos = split_container->get_size().x - separator_size.x;
1010
MessageQueue::get_singleton()->flush();
1011
check_position(split_container, def_pos, separator_size.x);
1012
1013
// Decrease the size.
1014
split_container->set_size(Size2(400, 500));
1015
def_pos = split_container->get_size().x - separator_size.x;
1016
MessageQueue::get_singleton()->flush();
1017
check_position(split_container, def_pos, separator_size.x);
1018
1019
// Change size with a split offset.
1020
split_container->set_split_offset(-100);
1021
MessageQueue::get_singleton()->flush();
1022
check_position(split_container, def_pos - 100, separator_size.x);
1023
1024
split_container->set_size(Size2(500, 500));
1025
def_pos = split_container->get_size().x - separator_size.x;
1026
MessageQueue::get_singleton()->flush();
1027
check_position(split_container, def_pos - 100, separator_size.x);
1028
CHECK(split_container->get_split_offset() == -100);
1029
1030
// Change size so that the second child changes size.
1031
split_container->set_size(Size2(80, 500));
1032
MessageQueue::get_singleton()->flush();
1033
check_position(split_container, 0, separator_size.x);
1034
CHECK(split_container->get_split_offset() == -100);
1035
1036
// Increase size again.
1037
split_container->set_size(Size2(500, 500));
1038
MessageQueue::get_singleton()->flush();
1039
check_position(split_container, def_pos - 100, separator_size.x);
1040
CHECK(split_container->get_split_offset() == -100);
1041
}
1042
1043
SUBCASE("[SplitContainer] Second child expanded") {
1044
int def_pos = 0;
1045
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1046
MessageQueue::get_singleton()->flush();
1047
1048
// Increase the size.
1049
split_container->set_size(Size2(600, 500));
1050
MessageQueue::get_singleton()->flush();
1051
check_position(split_container, def_pos, separator_size.x);
1052
1053
// Decrease the size.
1054
split_container->set_size(Size2(400, 500));
1055
MessageQueue::get_singleton()->flush();
1056
check_position(split_container, def_pos, separator_size.x);
1057
1058
// Change size with a split offset.
1059
split_container->set_split_offset(100);
1060
MessageQueue::get_singleton()->flush();
1061
check_position(split_container, def_pos + 100, separator_size.x);
1062
1063
split_container->set_size(Size2(500, 500));
1064
MessageQueue::get_singleton()->flush();
1065
check_position(split_container, def_pos + 100, separator_size.x);
1066
CHECK(split_container->get_split_offset() == 100);
1067
1068
// Change size so that the first child changes size.
1069
split_container->set_size(Size2(80, 500));
1070
MessageQueue::get_singleton()->flush();
1071
check_position(split_container, 80 - separator_size.x, separator_size.x);
1072
CHECK(split_container->get_split_offset() == 100);
1073
1074
// Increase size again.
1075
split_container->set_size(Size2(500, 500));
1076
MessageQueue::get_singleton()->flush();
1077
check_position(split_container, def_pos + 100, separator_size.x);
1078
CHECK(split_container->get_split_offset() == 100);
1079
}
1080
1081
SUBCASE("[SplitContainer] Both children expanded") {
1082
int def_pos = (split_container->get_size().x - separator_size.x) / 2;
1083
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1084
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1085
MessageQueue::get_singleton()->flush();
1086
1087
// Increase the size.
1088
split_container->set_size(Size2(600, 500));
1089
def_pos = (split_container->get_size().x - separator_size.x) / 2;
1090
MessageQueue::get_singleton()->flush();
1091
check_position(split_container, def_pos, separator_size.x);
1092
1093
// Decrease the size.
1094
split_container->set_size(Size2(400, 500));
1095
def_pos = (split_container->get_size().x - separator_size.x) / 2;
1096
MessageQueue::get_singleton()->flush();
1097
check_position(split_container, def_pos, separator_size.x);
1098
1099
// Change size with a split offset.
1100
split_container->set_split_offset(100);
1101
MessageQueue::get_singleton()->flush();
1102
check_position(split_container, def_pos + 100, separator_size.x);
1103
1104
split_container->set_size(Size2(500, 500));
1105
def_pos = (split_container->get_size().x - separator_size.x) / 2;
1106
MessageQueue::get_singleton()->flush();
1107
check_position(split_container, def_pos + 100, separator_size.x);
1108
CHECK(split_container->get_split_offset() == 100);
1109
1110
// Change size so that the second child is minimized.
1111
split_container->set_size(Size2(80, 500));
1112
MessageQueue::get_singleton()->flush();
1113
check_position(split_container, 80 - separator_size.x, separator_size.x);
1114
CHECK(split_container->get_split_offset() == 100);
1115
1116
// Increase size again.
1117
split_container->set_size(Size2(500, 500));
1118
def_pos = (split_container->get_size().x - separator_size.x) / 2;
1119
MessageQueue::get_singleton()->flush();
1120
check_position(split_container, def_pos + 100, separator_size.x);
1121
CHECK(split_container->get_split_offset() == 100);
1122
}
1123
1124
SUBCASE("[SplitContainer] Unequal stretch ratios") {
1125
int def_pos = (split_container->get_size().x * 2 / 3) - separator_size.x / 2;
1126
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1127
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1128
child_a->set_stretch_ratio(2.0);
1129
MessageQueue::get_singleton()->flush();
1130
1131
// Increase the size.
1132
split_container->set_size(Size2(600, 500));
1133
def_pos = (split_container->get_size().x * 2 / 3) - separator_size.x / 2;
1134
MessageQueue::get_singleton()->flush();
1135
check_position(split_container, def_pos, separator_size.x);
1136
1137
// Decrease the size.
1138
split_container->set_size(Size2(400, 500));
1139
def_pos = (split_container->get_size().x * 2 / 3) - separator_size.x / 2;
1140
MessageQueue::get_singleton()->flush();
1141
check_position(split_container, def_pos, separator_size.x);
1142
1143
// Change size with a split offset.
1144
split_container->set_split_offset(100);
1145
MessageQueue::get_singleton()->flush();
1146
check_position(split_container, def_pos + 100, separator_size.x);
1147
1148
split_container->set_size(Size2(500, 500));
1149
def_pos = (split_container->get_size().x * 2 / 3) - separator_size.x / 2;
1150
MessageQueue::get_singleton()->flush();
1151
check_position(split_container, def_pos + 100, separator_size.x);
1152
CHECK(split_container->get_split_offset() == 100);
1153
1154
// Change size so that the second child is minimized.
1155
split_container->set_size(Size2(80, 500));
1156
MessageQueue::get_singleton()->flush();
1157
check_position(split_container, 80 - separator_size.x, separator_size.x);
1158
CHECK(split_container->get_split_offset() == 100);
1159
1160
// Increase size again.
1161
split_container->set_size(Size2(500, 500));
1162
def_pos = (split_container->get_size().x * 2 / 3) - separator_size.x / 2;
1163
MessageQueue::get_singleton()->flush();
1164
check_position(split_container, def_pos + 100, separator_size.x);
1165
CHECK(split_container->get_split_offset() == 100);
1166
}
1167
}
1168
1169
SUBCASE("[SplitContainer] Drag") {
1170
SUBCASE("[SplitContainer] Vertical, no expand flags") {
1171
SIGNAL_WATCH(split_container, "dragged");
1172
Array signal_args = { { 0 } };
1173
1174
split_container->set_vertical(true);
1175
Point2 mouse_offset = Point2(1, 1);
1176
int dragger_pos = 0;
1177
int split_dragger_ofs = 0;
1178
1179
// Grab the dragger.
1180
SEND_GUI_MOUSE_BUTTON_EVENT(mouse_offset + Point2(0, dragger_pos), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
1181
MessageQueue::get_singleton()->flush();
1182
check_position(split_container, dragger_pos, separator_size.y, false);
1183
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1184
SIGNAL_CHECK_FALSE("dragged");
1185
1186
// Move the dragger.
1187
dragger_pos = 10;
1188
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(0, dragger_pos), MouseButtonMask::LEFT, Key::NONE);
1189
MessageQueue::get_singleton()->flush();
1190
check_position(split_container, dragger_pos, separator_size.y, false);
1191
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1192
// It is clamped.
1193
split_container->clamp_split_offset();
1194
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1195
((Array)signal_args[0])[0] = split_container->get_split_offset();
1196
SIGNAL_CHECK("dragged", signal_args);
1197
1198
// Move down.
1199
dragger_pos = 400;
1200
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(0, dragger_pos), MouseButtonMask::LEFT, Key::NONE);
1201
MessageQueue::get_singleton()->flush();
1202
check_position(split_container, dragger_pos, separator_size.y, false);
1203
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1204
((Array)signal_args[0])[0] = split_container->get_split_offset();
1205
SIGNAL_CHECK("dragged", signal_args);
1206
1207
// Moves even when mouse is outside.
1208
dragger_pos = split_container->get_size().y - separator_size.y;
1209
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(0, 1000), MouseButtonMask::LEFT, Key::NONE);
1210
MessageQueue::get_singleton()->flush();
1211
check_position(split_container, dragger_pos, separator_size.y, false);
1212
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1213
((Array)signal_args[0])[0] = split_container->get_split_offset();
1214
SIGNAL_CHECK("dragged", signal_args);
1215
1216
// Move up.
1217
dragger_pos = 100;
1218
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(0, dragger_pos), MouseButtonMask::LEFT, Key::NONE);
1219
MessageQueue::get_singleton()->flush();
1220
check_position(split_container, dragger_pos, separator_size.y, false);
1221
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1222
((Array)signal_args[0])[0] = split_container->get_split_offset();
1223
SIGNAL_CHECK("dragged", signal_args);
1224
1225
// Release.
1226
SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(mouse_offset + Point2(0, dragger_pos), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
1227
MessageQueue::get_singleton()->flush();
1228
check_position(split_container, dragger_pos, separator_size.y, false);
1229
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1230
SIGNAL_CHECK_FALSE("dragged");
1231
1232
// No longer moves with the mouse.
1233
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(0, 200), MouseButtonMask::NONE, Key::NONE);
1234
MessageQueue::get_singleton()->flush();
1235
check_position(split_container, dragger_pos, separator_size.y, false);
1236
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1237
SIGNAL_CHECK_FALSE("dragged");
1238
1239
SIGNAL_UNWATCH(split_container, "dragged");
1240
}
1241
1242
SUBCASE("[SplitContainer] No expand flags") {
1243
Point2 mouse_offset = Point2(1, 1);
1244
int dragger_pos = 0;
1245
int split_dragger_ofs = 0;
1246
1247
// Grab the dragger.
1248
SEND_GUI_MOUSE_BUTTON_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
1249
MessageQueue::get_singleton()->flush();
1250
check_position(split_container, dragger_pos, separator_size.x);
1251
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1252
1253
// Move the dragger.
1254
dragger_pos = 10;
1255
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1256
MessageQueue::get_singleton()->flush();
1257
check_position(split_container, dragger_pos, separator_size.x);
1258
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1259
// It is clamped.
1260
split_container->clamp_split_offset();
1261
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1262
1263
// Continue moving.
1264
dragger_pos = 400;
1265
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1266
MessageQueue::get_singleton()->flush();
1267
check_position(split_container, dragger_pos, separator_size.x);
1268
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1269
1270
// Moves even when mouse is outside.
1271
dragger_pos = split_container->get_size().x - separator_size.x;
1272
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(1000, 0), MouseButtonMask::LEFT, Key::NONE);
1273
MessageQueue::get_singleton()->flush();
1274
check_position(split_container, dragger_pos, separator_size.x);
1275
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1276
1277
// Move back in.
1278
dragger_pos = 100;
1279
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1280
MessageQueue::get_singleton()->flush();
1281
check_position(split_container, dragger_pos, separator_size.x);
1282
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1283
1284
// Release.
1285
SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
1286
MessageQueue::get_singleton()->flush();
1287
check_position(split_container, dragger_pos, separator_size.x);
1288
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1289
1290
// No longer moves with the mouse.
1291
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(200, 0), MouseButtonMask::NONE, Key::NONE);
1292
MessageQueue::get_singleton()->flush();
1293
check_position(split_container, dragger_pos, separator_size.x);
1294
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1295
}
1296
1297
SUBCASE("[SplitContainer] First child expanded") {
1298
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1299
MessageQueue::get_singleton()->flush();
1300
Point2 mouse_offset = Point2(1, 1);
1301
int dragger_pos = split_container->get_size().x - separator_size.x;
1302
int split_dragger_ofs = -dragger_pos;
1303
1304
// Grab the dragger.
1305
SEND_GUI_MOUSE_BUTTON_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
1306
MessageQueue::get_singleton()->flush();
1307
check_position(split_container, dragger_pos, separator_size.x);
1308
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1309
1310
// Move the dragger.
1311
dragger_pos -= 10;
1312
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1313
MessageQueue::get_singleton()->flush();
1314
check_position(split_container, dragger_pos, separator_size.x);
1315
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1316
// It is clamped.
1317
split_container->clamp_split_offset();
1318
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1319
1320
// Continue moving.
1321
dragger_pos = 400;
1322
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1323
MessageQueue::get_singleton()->flush();
1324
check_position(split_container, dragger_pos, separator_size.x);
1325
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1326
1327
// Moves even when mouse is outside.
1328
dragger_pos = split_container->get_size().x - separator_size.x;
1329
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(1000, 0), MouseButtonMask::LEFT, Key::NONE);
1330
MessageQueue::get_singleton()->flush();
1331
check_position(split_container, dragger_pos, separator_size.x);
1332
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1333
1334
// Move back in.
1335
dragger_pos = 100;
1336
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1337
MessageQueue::get_singleton()->flush();
1338
check_position(split_container, dragger_pos, separator_size.x);
1339
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1340
1341
// Release.
1342
SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
1343
MessageQueue::get_singleton()->flush();
1344
check_position(split_container, dragger_pos, separator_size.x);
1345
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1346
1347
// No longer moves with the mouse.
1348
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(200, 0), MouseButtonMask::NONE, Key::NONE);
1349
MessageQueue::get_singleton()->flush();
1350
check_position(split_container, dragger_pos, separator_size.x);
1351
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1352
}
1353
1354
SUBCASE("[SplitContainer] Second child expanded") {
1355
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1356
MessageQueue::get_singleton()->flush();
1357
Point2 mouse_offset = Point2(1, 1);
1358
int dragger_pos = 0;
1359
int split_dragger_ofs = 0;
1360
1361
// Grab the dragger.
1362
SEND_GUI_MOUSE_BUTTON_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
1363
MessageQueue::get_singleton()->flush();
1364
check_position(split_container, dragger_pos, separator_size.x);
1365
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1366
1367
// Move the dragger.
1368
dragger_pos = 10;
1369
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1370
MessageQueue::get_singleton()->flush();
1371
check_position(split_container, dragger_pos, separator_size.x);
1372
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1373
// It is clamped.
1374
split_container->clamp_split_offset();
1375
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1376
1377
// Continue moving.
1378
dragger_pos = 400;
1379
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1380
MessageQueue::get_singleton()->flush();
1381
check_position(split_container, dragger_pos, separator_size.x);
1382
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1383
1384
// Moves even when mouse is outside.
1385
dragger_pos = split_container->get_size().x - separator_size.x;
1386
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(1000, 0), MouseButtonMask::LEFT, Key::NONE);
1387
MessageQueue::get_singleton()->flush();
1388
check_position(split_container, dragger_pos, separator_size.x);
1389
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1390
1391
// Move back in.
1392
dragger_pos = 100;
1393
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1394
MessageQueue::get_singleton()->flush();
1395
check_position(split_container, dragger_pos, separator_size.x);
1396
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1397
1398
// Release.
1399
SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
1400
MessageQueue::get_singleton()->flush();
1401
check_position(split_container, dragger_pos, separator_size.x);
1402
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1403
1404
// No longer moves with the mouse.
1405
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(200, 0), MouseButtonMask::NONE, Key::NONE);
1406
MessageQueue::get_singleton()->flush();
1407
check_position(split_container, dragger_pos, separator_size.x);
1408
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1409
}
1410
1411
SUBCASE("[SplitContainer] Both children expanded") {
1412
child_a->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1413
child_b->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1414
MessageQueue::get_singleton()->flush();
1415
Point2 mouse_offset = Point2(1, 1);
1416
int dragger_pos = (split_container->get_size().x - separator_size.x) / 2;
1417
int split_dragger_ofs = -dragger_pos;
1418
1419
// Grab the dragger.
1420
SEND_GUI_MOUSE_BUTTON_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::LEFT, Key::NONE);
1421
MessageQueue::get_singleton()->flush();
1422
check_position(split_container, dragger_pos, separator_size.x);
1423
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1424
1425
// Move the dragger.
1426
dragger_pos += 10;
1427
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1428
MessageQueue::get_singleton()->flush();
1429
check_position(split_container, dragger_pos, separator_size.x);
1430
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1431
// It is clamped.
1432
split_container->clamp_split_offset();
1433
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1434
1435
// Continue moving.
1436
dragger_pos = 400;
1437
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1438
MessageQueue::get_singleton()->flush();
1439
check_position(split_container, dragger_pos, separator_size.x);
1440
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1441
1442
// Moves even when mouse is outside.
1443
dragger_pos = split_container->get_size().x - separator_size.x;
1444
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(1000, 0), MouseButtonMask::LEFT, Key::NONE);
1445
MessageQueue::get_singleton()->flush();
1446
check_position(split_container, dragger_pos, separator_size.x);
1447
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1448
1449
// Move back in.
1450
dragger_pos = 100;
1451
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButtonMask::LEFT, Key::NONE);
1452
MessageQueue::get_singleton()->flush();
1453
check_position(split_container, dragger_pos, separator_size.x);
1454
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1455
1456
// Release.
1457
SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(mouse_offset + Point2(dragger_pos, 0), MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
1458
MessageQueue::get_singleton()->flush();
1459
check_position(split_container, dragger_pos, separator_size.x);
1460
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1461
1462
// No longer moves with the mouse.
1463
SEND_GUI_MOUSE_MOTION_EVENT(mouse_offset + Point2(200, 0), MouseButtonMask::NONE, Key::NONE);
1464
MessageQueue::get_singleton()->flush();
1465
check_position(split_container, dragger_pos, separator_size.x);
1466
CHECK(split_container->get_split_offset() == dragger_pos + split_dragger_ofs);
1467
}
1468
}
1469
1470
memdelete(child_b);
1471
memdelete(child_a);
1472
memdelete(split_container);
1473
}
1474
1475
} // namespace TestSplitContainer
1476
1477