Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/tests/scene/test_panel_container.cpp
59209 views
1
/**************************************************************************/
2
/* test_panel_container.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "tests/test_macros.h"
32
33
TEST_FORCE_LINK(test_panel_container)
34
35
#include "scene/gui/control.h"
36
#include "scene/gui/panel_container.h"
37
#include "scene/main/scene_tree.h"
38
#include "scene/main/window.h"
39
#include "scene/resources/style_box.h"
40
41
namespace TestPanelContainer {
42
43
TEST_CASE("[SceneTree][PanelContainer] Default properties") {
44
PanelContainer *panel_container = memnew(PanelContainer);
45
Window *root = SceneTree::get_singleton()->get_root();
46
root->add_child(panel_container);
47
SceneTree::get_singleton()->process(0);
48
49
CHECK_MESSAGE(
50
panel_container->get_mouse_filter() == Control::MOUSE_FILTER_STOP,
51
"PanelContainer mouse filter is set to MOUSE_FILTER_STOP by default.");
52
53
memdelete(panel_container);
54
}
55
56
TEST_CASE("[SceneTree][PanelContainer] StyleBox affects layout and minimum size") {
57
PanelContainer *panel_container = memnew(PanelContainer);
58
Window *root = SceneTree::get_singleton()->get_root();
59
root->add_child(panel_container);
60
61
Ref<StyleBoxEmpty> panel_style = memnew(StyleBoxEmpty);
62
panel_style->set_content_margin_individual(5, 6, 7, 8);
63
panel_container->add_theme_style_override("panel", panel_style);
64
65
Control *child_control = memnew(Control);
66
child_control->set_custom_minimum_size(Size2(20, 10));
67
panel_container->add_child(child_control);
68
69
panel_container->set_size(Size2(100, 80));
70
SceneTree::get_singleton()->process(0);
71
72
CHECK_MESSAGE(
73
child_control->get_position().is_equal_approx(Point2(5, 6)),
74
"Child control is offset by the panel StyleBox margins.");
75
76
CHECK_MESSAGE(
77
child_control->get_size().is_equal_approx(Size2(88, 66)),
78
"Child control size is reduced by the panel StyleBox minimum size.");
79
80
CHECK_MESSAGE(
81
panel_container->get_minimum_size().is_equal_approx(Size2(32, 24)),
82
"Minimum size equals child minimum size plus panel StyleBox minimum size.");
83
84
memdelete(child_control);
85
memdelete(panel_container);
86
}
87
88
TEST_CASE("[SceneTree][PanelContainer] Multiple children use maximum minimum size") {
89
PanelContainer *panel_container = memnew(PanelContainer);
90
Window *root = SceneTree::get_singleton()->get_root();
91
root->add_child(panel_container);
92
93
Ref<StyleBoxEmpty> panel_style = memnew(StyleBoxEmpty);
94
panel_style->set_content_margin_individual(2, 3, 4, 5);
95
panel_container->add_theme_style_override("panel", panel_style);
96
97
Control *child_control_1 = memnew(Control);
98
Control *child_control_2 = memnew(Control);
99
child_control_1->set_custom_minimum_size(Size2(40, 10));
100
child_control_2->set_custom_minimum_size(Size2(20, 50));
101
panel_container->add_child(child_control_1);
102
panel_container->add_child(child_control_2);
103
SceneTree::get_singleton()->process(0);
104
105
CHECK_MESSAGE(
106
panel_container->get_minimum_size().is_equal_approx(Size2(46, 58)),
107
"Minimum size uses maximum child minimum width/height plus panel StyleBox minimum size.");
108
109
memdelete(child_control_2);
110
memdelete(child_control_1);
111
memdelete(panel_container);
112
}
113
114
} // namespace TestPanelContainer
115
116