Debian Codegraph @

scene/gui/margin_container.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* margin_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 "margin_container.h"
32
33 #include "scene/theme/theme_db.h"
34
35 Size2 MarginContainer::get_minimum_size() const {
36 Size2 max;
37
38 for (int i = 0; i < get_child_count(); i++) {
39 Control *c = as_sortable_control(get_child(i), SortableVisibilityMode::VISIBLE);
40 if (!c) {
41 continue;
42 }
43
44 Size2 s = c->get_combined_minimum_size();
45 if (s.width > max.width) {
46 max.width = s.width;
47 }
48 if (s.height > max.height) {
49 max.height = s.height;
50 }
51 }
52
53 max.width += (theme_cache.margin_left + theme_cache.margin_right);
54 max.height += (theme_cache.margin_top + theme_cache.margin_bottom);
55
56 return max;
57 }
58
59 Vector<int> MarginContainer::get_allowed_size_flags_horizontal() const {
60 Vector<int> flags;
61 flags.append(SIZE_FILL);
62 flags.append(SIZE_SHRINK_BEGIN);
63 flags.append(SIZE_SHRINK_CENTER);
64 flags.append(SIZE_SHRINK_END);
65 return flags;
66 }
67
68 Vector<int> MarginContainer::get_allowed_size_flags_vertical() const {
69 Vector<int> flags;
70 flags.append(SIZE_FILL);
71 flags.append(SIZE_SHRINK_BEGIN);
72 flags.append(SIZE_SHRINK_CENTER);
73 flags.append(SIZE_SHRINK_END);
74 return flags;
75 }
76
77 int MarginContainer::get_margin_size(Side p_side) const {
78 ERR_FAIL_INDEX_V((int)p_side, 4, 0);
79
80 switch (p_side) {
81 case SIDE_LEFT:
82 return theme_cache.margin_left;
83 case SIDE_RIGHT:
84 return theme_cache.margin_right;
85 case SIDE_TOP:
86 return theme_cache.margin_top;
87 case SIDE_BOTTOM:
88 return theme_cache.margin_bottom;
89 }
90
91 return 0;
92 }
93
94 void MarginContainer::_notification(int p_what) {
95 switch (p_what) {
96 case NOTIFICATION_SORT_CHILDREN: {
97 Size2 s = get_size();
98
99 for (int i = 0; i < get_child_count(); i++) {
100 Control *c = as_sortable_control(get_child(i));
101 if (!c) {
102 continue;
103 }
104
105 int w = s.width - theme_cache.margin_left - theme_cache.margin_right;
106 int h = s.height - theme_cache.margin_top - theme_cache.margin_bottom;
107 fit_child_in_rect(c, Rect2(theme_cache.margin_left, theme_cache.margin_top, w, h));
108 }
109 } break;
110
111 case NOTIFICATION_THEME_CHANGED: {
112 update_minimum_size();
113 } break;
114 }
115 }
116
117 void MarginContainer::_bind_methods() {
118 BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, MarginContainer, margin_left);
119 BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, MarginContainer, margin_top);
120 BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, MarginContainer, margin_right);
121 BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, MarginContainer, margin_bottom);
122 }
123
124 MarginContainer::MarginContainer() {
125 }