1/**************************************************************************/
2/* control.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 "control.h"
32
33#include "container.h"
34#include "core/config/project_settings.h"
35#include "core/math/geometry_2d.h"
36#include "core/object/message_queue.h"
37#include "core/os/keyboard.h"
38#include "core/os/os.h"
39#include "core/string/print_string.h"
40#include "core/string/translation.h"
41#include "scene/gui/label.h"
42#include "scene/gui/panel.h"
43#include "scene/main/canvas_layer.h"
44#include "scene/main/window.h"
45#include "scene/scene_string_names.h"
46#include "scene/theme/theme_db.h"
47#include "scene/theme/theme_owner.h"
48#include "servers/rendering_server.h"
49#include "servers/text_server.h"
50
51#ifdef TOOLS_ENABLED
52#include "editor/plugins/control_editor_plugin.h"
53#endif
54
55// Editor plugin interoperability.
56
57// TODO: Decouple controls from their editor plugin and get rid of this.
58#ifdef TOOLS_ENABLED
59Dictionary Control::_edit_get_state() const {
60 Dictionary s;
61 s["rotation"] = get_rotation();
62 s["scale"] = get_scale();
63 s["pivot"] = get_pivot_offset();
64
65 Array anchors;
66 anchors.push_back(get_anchor(SIDE_LEFT));
67 anchors.push_back(get_anchor(SIDE_TOP));
68 anchors.push_back(get_anchor(SIDE_RIGHT));
69 anchors.push_back(get_anchor(SIDE_BOTTOM));
70 s["anchors"] = anchors;
71
72 Array offsets;
73 offsets.push_back(get_offset(SIDE_LEFT));
74 offsets.push_back(get_offset(SIDE_TOP));
75 offsets.push_back(get_offset(SIDE_RIGHT));
76 offsets.push_back(get_offset(SIDE_BOTTOM));
77 s["offsets"] = offsets;
78
79 s["layout_mode"] = _get_layout_mode();
80 s["anchors_layout_preset"] = _get_anchors_layout_preset();
81
82 return s;
83}
84
85void Control::_edit_set_state(const Dictionary &p_state) {
86 ERR_FAIL_COND((p_state.size() <= 0) ||
87 !p_state.has("rotation") || !p_state.has("scale") ||
88 !p_state.has("pivot") || !p_state.has("anchors") || !p_state.has("offsets") ||
89 !p_state.has("layout_mode") || !p_state.has("anchors_layout_preset"));
90 Dictionary state = p_state;
91
92 set_rotation(state["rotation"]);
93 set_scale(state["scale"]);
94 set_pivot_offset(state["pivot"]);
95
96 Array anchors = state["anchors"];
97
98 // If anchors are not in their default position, force the anchor layout mode in place of position.
99 LayoutMode _layout = (LayoutMode)(int)state["layout_mode"];
100 if (_layout == LayoutMode::LAYOUT_MODE_POSITION) {
101 bool anchors_mode = ((real_t)anchors[0] != 0.0 || (real_t)anchors[1] != 0.0 || (real_t)anchors[2] != 0.0 || (real_t)anchors[3] != 0.0);
102 if (anchors_mode) {
103 _layout = LayoutMode::LAYOUT_MODE_ANCHORS;
104 }
105 }
106
107 _set_layout_mode(_layout);
108 if (_layout == LayoutMode::LAYOUT_MODE_ANCHORS || _layout == LayoutMode::LAYOUT_MODE_UNCONTROLLED) {
109 _set_anchors_layout_preset((int)state["anchors_layout_preset"]);
110 }
111
112 data.anchor[SIDE_LEFT] = anchors[0];
113 data.anchor[SIDE_TOP] = anchors[1];
114 data.anchor[SIDE_RIGHT] = anchors[2];
115 data.anchor[SIDE_BOTTOM] = anchors[3];
116
117 Array offsets = state["offsets"];
118 data.offset[SIDE_LEFT] = offsets[0];
119 data.offset[SIDE_TOP] = offsets[1];
120 data.offset[SIDE_RIGHT] = offsets[2];
121 data.offset[SIDE_BOTTOM] = offsets[3];
122
123 _size_changed();
124}
125
126void Control::_edit_set_position(const Point2 &p_position) {
127 ERR_FAIL_COND_MSG(!Engine::get_singleton()->is_editor_hint(), "This function can only be used from editor plugins.");
128 set_position(p_position, ControlEditorToolbar::get_singleton()->is_anchors_mode_enabled() && get_parent_control());
129};
130
131Point2 Control::_edit_get_position() const {
132 return get_position();
133};
134
135void Control::_edit_set_scale(const Size2 &p_scale) {
136 set_scale(p_scale);
137}
138
139Size2 Control::_edit_get_scale() const {
140 return data.scale;
141}
142
143void Control::_edit_set_rect(const Rect2 &p_edit_rect) {
144 ERR_FAIL_COND_MSG(!Engine::get_singleton()->is_editor_hint(), "This function can only be used from editor plugins.");
145 set_position((get_position() + get_transform().basis_xform(p_edit_rect.position)).snapped(Vector2(1, 1)), ControlEditorToolbar::get_singleton()->is_anchors_mode_enabled());
146 set_size(p_edit_rect.size.snapped(Vector2(1, 1)), ControlEditorToolbar::get_singleton()->is_anchors_mode_enabled());
147}
148
149Rect2 Control::_edit_get_rect() const {
150 return Rect2(Point2(), get_size());
151}
152
153bool Control::_edit_use_rect() const {
154 return true;
155}
156
157void Control::_edit_set_rotation(real_t p_rotation) {
158 set_rotation(p_rotation);
159}
160
161real_t Control::_edit_get_rotation() const {
162 return get_rotation();
163}
164
165bool Control::_edit_use_rotation() const {
166 return true;
167}
168
169void Control::_edit_set_pivot(const Point2 &p_pivot) {
170 Vector2 delta_pivot = p_pivot - get_pivot_offset();
171 Vector2 move = Vector2((cos(data.rotation) - 1.0) * delta_pivot.x - sin(data.rotation) * delta_pivot.y, sin(data.rotation) * delta_pivot.x + (cos(data.rotation) - 1.0) * delta_pivot.y);
172 set_position(get_position() + move);
173 set_pivot_offset(p_pivot);
174}
175
176Point2 Control::_edit_get_pivot() const {
177 return get_pivot_offset();
178}
179
180bool Control::_edit_use_pivot() const {
181 return true;
182}
183
184Size2 Control::_edit_get_minimum_size() const {
185 return get_combined_minimum_size();
186}
187#endif
188
189void Control::reparent(Node *p_parent, bool p_keep_global_transform) {
190 ERR_MAIN_THREAD_GUARD;
191 Transform2D temp = get_global_transform();
192 Node::reparent(p_parent);
193 if (p_keep_global_transform) {
194 set_global_position(temp.get_origin());
195 }
196}
197
198// Editor integration.
199
200void Control::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
201 ERR_READ_THREAD_GUARD;
202 Node::get_argument_options(p_function, p_idx, r_options);
203
204 if (p_idx == 0) {
205 List<StringName> sn;
206 String pf = p_function;
207 if (pf == "add_theme_color_override" || pf == "has_theme_color" || pf == "has_theme_color_override" || pf == "get_theme_color") {
208 ThemeDB::get_singleton()->get_default_theme()->get_color_list(get_class(), &sn);
209 } else if (pf == "add_theme_style_override" || pf == "has_theme_style" || pf == "has_theme_style_override" || pf == "get_theme_style") {
210 ThemeDB::get_singleton()->get_default_theme()->get_stylebox_list(get_class(), &sn);
211 } else if (pf == "add_theme_font_override" || pf == "has_theme_font" || pf == "has_theme_font_override" || pf == "get_theme_font") {
212 ThemeDB::get_singleton()->get_default_theme()->get_font_list(get_class(), &sn);
213 } else if (pf == "add_theme_font_size_override" || pf == "has_theme_font_size" || pf == "has_theme_font_size_override" || pf == "get_theme_font_size") {
214 ThemeDB::get_singleton()->get_default_theme()->get_font_size_list(get_class(), &sn);
215 } else if (pf == "add_theme_constant_override" || pf == "has_theme_constant" || pf == "has_theme_constant_override" || pf == "get_theme_constant") {
216 ThemeDB::get_singleton()->get_default_theme()->get_constant_list(get_class(), &sn);
217 }
218
219 sn.sort_custom<StringName::AlphCompare>();
220 for (const StringName &name : sn) {
221 r_options->push_back(String(name).quote());
222 }
223 }
224}
225
226PackedStringArray Control::get_configuration_warnings() const {
227 ERR_READ_THREAD_GUARD_V(PackedStringArray());
228 PackedStringArray warnings = Node::get_configuration_warnings();
229
230 if (data.mouse_filter == MOUSE_FILTER_IGNORE && !data.tooltip.is_empty()) {
231 warnings.push_back(RTR("The Hint Tooltip won't be displayed as the control's Mouse Filter is set to \"Ignore\". To solve this, set the Mouse Filter to \"Stop\" or \"Pass\"."));
232 }
233
234 if (get_z_index() != 0) {
235 warnings.push_back(RTR("Changing the Z index of a control only affects the drawing order, not the input event handling order."));
236 }
237
238 return warnings;
239}
240
241bool Control::is_text_field() const {
242 ERR_READ_THREAD_GUARD_V(false);
243 return false;
244}
245
246// Dynamic properties.
247
248String Control::properties_managed_by_container[] = {
249 "offset_left",
250 "offset_top",
251 "offset_right",
252 "offset_bottom",
253 "anchor_left",
254 "anchor_top",
255 "anchor_right",
256 "anchor_bottom",
257 "position",
258 "rotation",
259 "scale",
260 "size"
261};
262
263bool Control::_set(const StringName &p_name, const Variant &p_value) {
264 ERR_MAIN_THREAD_GUARD_V(false);
265 String name = p_name;
266 if (!name.begins_with("theme_override")) {
267 return false;
268 }
269
270 if (p_value.get_type() == Variant::NIL || (p_value.get_type() == Variant::OBJECT && (Object *)p_value == nullptr)) {
271 if (name.begins_with("theme_override_icons/")) {
272 String dname = name.get_slicec('/', 1);
273 if (data.theme_icon_override.has(dname)) {
274 data.theme_icon_override[dname]->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed));
275 }
276 data.theme_icon_override.erase(dname);
277 _notify_theme_override_changed();
278 } else if (name.begins_with("theme_override_styles/")) {
279 String dname = name.get_slicec('/', 1);
280 if (data.theme_style_override.has(dname)) {
281 data.theme_style_override[dname]->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed));
282 }
283 data.theme_style_override.erase(dname);
284 _notify_theme_override_changed();
285 } else if (name.begins_with("theme_override_fonts/")) {
286 String dname = name.get_slicec('/', 1);
287 if (data.theme_font_override.has(dname)) {
288 data.theme_font_override[dname]->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed));
289 }
290 data.theme_font_override.erase(dname);
291 _notify_theme_override_changed();
292 } else if (name.begins_with("theme_override_font_sizes/")) {
293 String dname = name.get_slicec('/', 1);
294 data.theme_font_size_override.erase(dname);
295 _notify_theme_override_changed();
296 } else if (name.begins_with("theme_override_colors/")) {
297 String dname = name.get_slicec('/', 1);
298 data.theme_color_override.erase(dname);
299 _notify_theme_override_changed();
300 } else if (name.begins_with("theme_override_constants/")) {
301 String dname = name.get_slicec('/', 1);
302 data.theme_constant_override.erase(dname);
303 _notify_theme_override_changed();
304 } else {
305 return false;
306 }
307
308 } else {
309 if (name.begins_with("theme_override_icons/")) {
310 String dname = name.get_slicec('/', 1);
311 add_theme_icon_override(dname, p_value);
312 } else if (name.begins_with("theme_override_styles/")) {
313 String dname = name.get_slicec('/', 1);
314 add_theme_style_override(dname, p_value);
315 } else if (name.begins_with("theme_override_fonts/")) {
316 String dname = name.get_slicec('/', 1);
317 add_theme_font_override(dname, p_value);
318 } else if (name.begins_with("theme_override_font_sizes/")) {
319 String dname = name.get_slicec('/', 1);
320 add_theme_font_size_override(dname, p_value);
321 } else if (name.begins_with("theme_override_colors/")) {
322 String dname = name.get_slicec('/', 1);
323 add_theme_color_override(dname, p_value);
324 } else if (name.begins_with("theme_override_constants/")) {
325 String dname = name.get_slicec('/', 1);
326 add_theme_constant_override(dname, p_value);
327 } else {
328 return false;
329 }
330 }
331 return true;
332}
333
334bool Control::_get(const StringName &p_name, Variant &r_ret) const {
335 ERR_MAIN_THREAD_GUARD_V(false);
336 String sname = p_name;
337 if (!sname.begins_with("theme_override")) {
338 return false;
339 }
340
341 if (sname.begins_with("theme_override_icons/")) {
342 String name = sname.get_slicec('/', 1);
343 r_ret = data.theme_icon_override.has(name) ? Variant(data.theme_icon_override[name]) : Variant();
344 } else if (sname.begins_with("theme_override_styles/")) {
345 String name = sname.get_slicec('/', 1);
346 r_ret = data.theme_style_override.has(name) ? Variant(data.theme_style_override[name]) : Variant();
347 } else if (sname.begins_with("theme_override_fonts/")) {
348 String name = sname.get_slicec('/', 1);
349 r_ret = data.theme_font_override.has(name) ? Variant(data.theme_font_override[name]) : Variant();
350 } else if (sname.begins_with("theme_override_font_sizes/")) {
351 String name = sname.get_slicec('/', 1);
352 r_ret = data.theme_font_size_override.has(name) ? Variant(data.theme_font_size_override[name]) : Variant();
353 } else if (sname.begins_with("theme_override_colors/")) {
354 String name = sname.get_slicec('/', 1);
355 r_ret = data.theme_color_override.has(name) ? Variant(data.theme_color_override[name]) : Variant();
356 } else if (sname.begins_with("theme_override_constants/")) {
357 String name = sname.get_slicec('/', 1);
358 r_ret = data.theme_constant_override.has(name) ? Variant(data.theme_constant_override[name]) : Variant();
359 } else {
360 return false;
361 }
362
363 return true;
364}
365
366void Control::_get_property_list(List<PropertyInfo> *p_list) const {
367 ERR_MAIN_THREAD_GUARD;
368 Ref<Theme> default_theme = ThemeDB::get_singleton()->get_default_theme();
369
370 p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Theme Overrides", "theme_override_"), PROPERTY_HINT_NONE, "theme_override_", PROPERTY_USAGE_GROUP));
371
372 {
373 List<StringName> names;
374 default_theme->get_color_list(get_class_name(), &names);
375 for (const StringName &E : names) {
376 uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
377 if (data.theme_color_override.has(E)) {
378 usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
379 }
380
381 p_list->push_back(PropertyInfo(Variant::COLOR, PNAME("theme_override_colors") + String("/") + E, PROPERTY_HINT_NONE, "", usage));
382 }
383 }
384 {
385 List<StringName> names;
386 default_theme->get_constant_list(get_class_name(), &names);
387 for (const StringName &E : names) {
388 uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
389 if (data.theme_constant_override.has(E)) {
390 usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
391 }
392
393 p_list->push_back(PropertyInfo(Variant::INT, PNAME("theme_override_constants") + String("/") + E, PROPERTY_HINT_RANGE, "-16384,16384", usage));
394 }
395 }
396 {
397 List<StringName> names;
398 default_theme->get_font_list(get_class_name(), &names);
399 for (const StringName &E : names) {
400 uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
401 if (data.theme_font_override.has(E)) {
402 usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
403 }
404
405 p_list->push_back(PropertyInfo(Variant::OBJECT, PNAME("theme_override_fonts") + String("/") + E, PROPERTY_HINT_RESOURCE_TYPE, "Font", usage));
406 }
407 }
408 {
409 List<StringName> names;
410 default_theme->get_font_size_list(get_class_name(), &names);
411 for (const StringName &E : names) {
412 uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
413 if (data.theme_font_size_override.has(E)) {
414 usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
415 }
416
417 p_list->push_back(PropertyInfo(Variant::INT, PNAME("theme_override_font_sizes") + String("/") + E, PROPERTY_HINT_RANGE, "1,256,1,or_greater,suffix:px", usage));
418 }
419 }
420 {
421 List<StringName> names;
422 default_theme->get_icon_list(get_class_name(), &names);
423 for (const StringName &E : names) {
424 uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
425 if (data.theme_icon_override.has(E)) {
426 usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
427 }
428
429 p_list->push_back(PropertyInfo(Variant::OBJECT, PNAME("theme_override_icons") + String("/") + E, PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", usage));
430 }
431 }
432 {
433 List<StringName> names;
434 default_theme->get_stylebox_list(get_class_name(), &names);
435 for (const StringName &E : names) {
436 uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
437 if (data.theme_style_override.has(E)) {
438 usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
439 }
440
441 p_list->push_back(PropertyInfo(Variant::OBJECT, PNAME("theme_override_styles") + String("/") + E, PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", usage));
442 }
443 }
444}
445
446void Control::_validate_property(PropertyInfo &p_property) const {
447 // Update theme type variation options.
448 if (p_property.name == "theme_type_variation") {
449 List<StringName> names;
450
451 // Only the default theme and the project theme are used for the list of options.
452 // This is an imposed limitation to simplify the logic needed to leverage those options.
453 ThemeDB::get_singleton()->get_default_theme()->get_type_variation_list(get_class_name(), &names);
454 if (ThemeDB::get_singleton()->get_project_theme().is_valid()) {
455 ThemeDB::get_singleton()->get_project_theme()->get_type_variation_list(get_class_name(), &names);
456 }
457 names.sort_custom<StringName::AlphCompare>();
458
459 Vector<StringName> unique_names;
460 String hint_string;
461 for (const StringName &E : names) {
462 // Skip duplicate values.
463 if (unique_names.has(E)) {
464 continue;
465 }
466
467 hint_string += String(E) + ",";
468 unique_names.append(E);
469 }
470
471 p_property.hint_string = hint_string;
472 }
473
474 if (p_property.name == "mouse_force_pass_scroll_events") {
475 // Disable force pass if the control is not stopping the event.
476 if (data.mouse_filter != MOUSE_FILTER_STOP) {
477 p_property.usage |= PROPERTY_USAGE_READ_ONLY;
478 }
479 }
480
481 if (p_property.name == "scale") {
482 p_property.hint = PROPERTY_HINT_LINK;
483 }
484
485 // Validate which positioning properties should be displayed depending on the parent and the layout mode.
486 Node *parent_node = get_parent_control();
487 if (!parent_node) {
488 // If there is no parent, display both anchor and container options.
489
490 // Set the layout mode to be disabled with the proper value.
491 if (p_property.name == "layout_mode") {
492 p_property.hint_string = "Position,Anchors,Container,Uncontrolled";
493 p_property.usage |= PROPERTY_USAGE_READ_ONLY;
494 }
495
496 // Use the layout mode to display or hide advanced anchoring properties.
497 bool use_custom_anchors = _get_anchors_layout_preset() == -1; // Custom "preset".
498 if (!use_custom_anchors && (p_property.name.begins_with("anchor_") || p_property.name.begins_with("offset_") || p_property.name.begins_with("grow_"))) {
499 p_property.usage ^= PROPERTY_USAGE_EDITOR;
500 }
501 } else if (Object::cast_to<Container>(parent_node)) {
502 // If the parent is a container, display only container-related properties.
503 if (p_property.name.begins_with("anchor_") || p_property.name.begins_with("offset_") || p_property.name.begins_with("grow_") || p_property.name == "anchors_preset") {
504 p_property.usage ^= PROPERTY_USAGE_DEFAULT;
505 } else if (p_property.name == "position" || p_property.name == "rotation" || p_property.name == "scale" || p_property.name == "size" || p_property.name == "pivot_offset") {
506 p_property.usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_READ_ONLY;
507 } else if (p_property.name == "layout_mode") {
508 // Set the layout mode to be disabled with the proper value.
509 p_property.hint_string = "Position,Anchors,Container,Uncontrolled";
510 p_property.usage |= PROPERTY_USAGE_READ_ONLY;
511 } else if (p_property.name == "size_flags_horizontal" || p_property.name == "size_flags_vertical") {
512 // Filter allowed size flags based on the parent container configuration.
513 Container *parent_container = Object::cast_to<Container>(parent_node);
514 Vector<int> size_flags;
515 if (p_property.name == "size_flags_horizontal") {
516 size_flags = parent_container->get_allowed_size_flags_horizontal();
517 } else if (p_property.name == "size_flags_vertical") {
518 size_flags = parent_container->get_allowed_size_flags_vertical();
519 }
520
521 // Enforce the order of the options, regardless of what the container provided.
522 String hint_string;
523 if (size_flags.has(SIZE_FILL)) {
524 hint_string += "Fill:1";
525 }
526 if (size_flags.has(SIZE_EXPAND)) {
527 if (!hint_string.is_empty()) {
528 hint_string += ",";
529 }
530 hint_string += "Expand:2";
531 }
532 if (size_flags.has(SIZE_SHRINK_CENTER)) {
533 if (!hint_string.is_empty()) {
534 hint_string += ",";
535 }
536 hint_string += "Shrink Center:4";
537 }
538 if (size_flags.has(SIZE_SHRINK_END)) {
539 if (!hint_string.is_empty()) {
540 hint_string += ",";
541 }
542 hint_string += "Shrink End:8";
543 }
544
545 if (hint_string.is_empty()) {
546 p_property.hint_string = "";
547 p_property.usage |= PROPERTY_USAGE_READ_ONLY;
548 } else {
549 p_property.hint_string = hint_string;
550 }
551 }
552 } else {
553 // If the parent is NOT a container or not a control at all, display only anchoring-related properties.
554 if (p_property.name.begins_with("size_flags_")) {
555 p_property.usage ^= PROPERTY_USAGE_EDITOR;
556
557 } else if (p_property.name == "layout_mode") {
558 // Set the layout mode to be enabled with proper options.
559 p_property.hint_string = "Position,Anchors";
560 }
561
562 // Use the layout mode to display or hide advanced anchoring properties.
563 LayoutMode _layout = _get_layout_mode();
564 bool use_anchors = (_layout == LayoutMode::LAYOUT_MODE_ANCHORS || _layout == LayoutMode::LAYOUT_MODE_UNCONTROLLED);
565 if (!use_anchors && p_property.name == "anchors_preset") {
566 p_property.usage ^= PROPERTY_USAGE_EDITOR;
567 }
568 bool use_custom_anchors = use_anchors && _get_anchors_layout_preset() == -1; // Custom "preset".
569 if (!use_custom_anchors && (p_property.name.begins_with("anchor_") || p_property.name.begins_with("offset_") || p_property.name.begins_with("grow_"))) {
570 p_property.usage ^= PROPERTY_USAGE_EDITOR;
571 }
572 }
573
574 // Disable the property if it's managed by the parent container.
575 if (!Object::cast_to<Container>(parent_node)) {
576 return;
577 }
578 bool property_is_managed_by_container = false;
579 for (unsigned i = 0; i < properties_managed_by_container_count; i++) {
580 property_is_managed_by_container = properties_managed_by_container[i] == p_property.name;
581 if (property_is_managed_by_container) {
582 break;
583 }
584 }
585 if (property_is_managed_by_container) {
586 p_property.usage |= PROPERTY_USAGE_READ_ONLY;
587 }
588}
589
590bool Control::_property_can_revert(const StringName &p_name) const {
591 if (p_name == "layout_mode" || p_name == "anchors_preset") {
592 return true;
593 }
594
595 return false;
596}
597
598bool Control::_property_get_revert(const StringName &p_name, Variant &r_property) const {
599 if (p_name == "layout_mode") {
600 r_property = _get_default_layout_mode();
601 return true;
602 } else if (p_name == "anchors_preset") {
603 r_property = LayoutPreset::PRESET_TOP_LEFT;
604 return true;
605 }
606
607 return false;
608}
609
610// Global relations.
611
612bool Control::is_top_level_control() const {
613 ERR_READ_THREAD_GUARD_V(false);
614 return is_inside_tree() && (!data.parent_canvas_item && !data.RI && is_set_as_top_level());
615}
616
617Control *Control::get_parent_control() const {
618 ERR_READ_THREAD_GUARD_V(nullptr);
619 return data.parent_control;
620}
621
622Window *Control::get_parent_window() const {
623 ERR_READ_THREAD_GUARD_V(nullptr);
624 return data.parent_window;
625}
626
627Control *Control::get_root_parent_control() const {
628 ERR_READ_THREAD_GUARD_V(nullptr);
629 const CanvasItem *ci = this;
630 const Control *root = this;
631
632 while (ci) {
633 const Control *c = Object::cast_to<Control>(ci);
634 if (c) {
635 root = c;
636
637 if (c->data.RI || c->is_top_level_control()) {
638 break;
639 }
640 }
641
642 ci = ci->get_parent_item();
643 }
644
645 return const_cast<Control *>(root);
646}
647
648Rect2 Control::get_parent_anchorable_rect() const {
649 ERR_READ_THREAD_GUARD_V(Rect2());
650 if (!is_inside_tree()) {
651 return Rect2();
652 }
653
654 Rect2 parent_rect;
655 if (data.parent_canvas_item) {
656 parent_rect = data.parent_canvas_item->get_anchorable_rect();
657 } else {
658#ifdef TOOLS_ENABLED
659 Node *edited_scene_root = get_tree()->get_edited_scene_root();
660 Node *scene_root_parent = edited_scene_root ? edited_scene_root->get_parent() : nullptr;
661
662 if (scene_root_parent && get_viewport() == scene_root_parent->get_viewport()) {
663 parent_rect.size = Size2(GLOBAL_GET("display/window/size/viewport_width"), GLOBAL_GET("display/window/size/viewport_height"));
664 } else {
665 parent_rect = get_viewport()->get_visible_rect();
666 }
667
668#else
669 parent_rect = get_viewport()->get_visible_rect();
670#endif
671 }
672
673 return parent_rect;
674}
675
676Size2 Control::get_parent_area_size() const {
677 ERR_READ_THREAD_GUARD_V(Size2());
678 return get_parent_anchorable_rect().size;
679}
680
681// Positioning and sizing.
682
683Transform2D Control::_get_internal_transform() const {
684 Transform2D rot_scale;
685 rot_scale.set_rotation_and_scale(data.rotation, data.scale);
686 Transform2D offset;
687 offset.set_origin(-data.pivot_offset);
688
689 return offset.affine_inverse() * (rot_scale * offset);
690}
691
692void Control::_update_canvas_item_transform() {
693 Transform2D xform = _get_internal_transform();
694 xform[2] += get_position();
695
696 // We use a little workaround to avoid flickering when moving the pivot with _edit_set_pivot()
697 if (is_inside_tree() && Math::abs(Math::sin(data.rotation * 4.0f)) < 0.00001f && get_viewport()->is_snap_controls_to_pixels_enabled()) {
698 xform[2] = xform[2].round();
699 }
700
701 RenderingServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), xform);
702}
703
704Transform2D Control::get_transform() const {
705 ERR_READ_THREAD_GUARD_V(Transform2D());
706 Transform2D xform = _get_internal_transform();
707 xform[2] += get_position();
708 return xform;
709}
710
711void Control::_top_level_changed_on_parent() {
712 // Update root control status.
713 _notification(NOTIFICATION_EXIT_CANVAS);
714 _notification(NOTIFICATION_ENTER_CANVAS);
715}
716
717/// Anchors and offsets.
718
719void Control::_set_anchor(Side p_side, real_t p_anchor) {
720 set_anchor(p_side, p_anchor);
721}
722
723void Control::set_anchor(Side p_side, real_t p_anchor, bool p_keep_offset, bool p_push_opposite_anchor) {
724 ERR_MAIN_THREAD_GUARD;
725 ERR_FAIL_INDEX((int)p_side, 4);
726
727 Rect2 parent_rect = get_parent_anchorable_rect();
728 real_t parent_range = (p_side == SIDE_LEFT || p_side == SIDE_RIGHT) ? parent_rect.size.x : parent_rect.size.y;
729 real_t previous_pos = data.offset[p_side] + data.anchor[p_side] * parent_range;
730 real_t previous_opposite_pos = data.offset[(p_side + 2) % 4] + data.anchor[(p_side + 2) % 4] * parent_range;
731
732 data.anchor[p_side] = p_anchor;
733
734 if (((p_side == SIDE_LEFT || p_side == SIDE_TOP) && data.anchor[p_side] > data.anchor[(p_side + 2) % 4]) ||
735 ((p_side == SIDE_RIGHT || p_side == SIDE_BOTTOM) && data.anchor[p_side] < data.anchor[(p_side + 2) % 4])) {
736 if (p_push_opposite_anchor) {
737 data.anchor[(p_side + 2) % 4] = data.anchor[p_side];
738 } else {
739 data.anchor[p_side] = data.anchor[(p_side + 2) % 4];
740 }
741 }
742
743 if (!p_keep_offset) {
744 data.offset[p_side] = previous_pos - data.anchor[p_side] * parent_range;
745 if (p_push_opposite_anchor) {
746 data.offset[(p_side + 2) % 4] = previous_opposite_pos - data.anchor[(p_side + 2) % 4] * parent_range;
747 }
748 }
749 if (is_inside_tree()) {
750 _size_changed();
751 }
752
753 queue_redraw();
754}
755
756real_t Control::get_anchor(Side p_side) const {
757 ERR_READ_THREAD_GUARD_V(0);
758 ERR_FAIL_INDEX_V(int(p_side), 4, 0.0);
759
760 return data.anchor[p_side];
761}
762
763void Control::set_offset(Side p_side, real_t p_value) {
764 ERR_MAIN_THREAD_GUARD;
765 ERR_FAIL_INDEX((int)p_side, 4);
766 if (data.offset[p_side] == p_value) {
767 return;
768 }
769
770 data.offset[p_side] = p_value;
771 _size_changed();
772}
773
774real_t Control::get_offset(Side p_side) const {
775 ERR_READ_THREAD_GUARD_V(0);
776 ERR_FAIL_INDEX_V((int)p_side, 4, 0);
777
778 return data.offset[p_side];
779}
780
781void Control::set_anchor_and_offset(Side p_side, real_t p_anchor, real_t p_pos, bool p_push_opposite_anchor) {
782 ERR_MAIN_THREAD_GUARD;
783 set_anchor(p_side, p_anchor, false, p_push_opposite_anchor);
784 set_offset(p_side, p_pos);
785}
786
787void Control::set_begin(const Point2 &p_point) {
788 ERR_MAIN_THREAD_GUARD;
789 ERR_FAIL_COND(!isfinite(p_point.x) || !isfinite(p_point.y));
790 if (data.offset[0] == p_point.x && data.offset[1] == p_point.y) {
791 return;
792 }
793
794 data.offset[0] = p_point.x;
795 data.offset[1] = p_point.y;
796 _size_changed();
797}
798
799Point2 Control::get_begin() const {
800 ERR_READ_THREAD_GUARD_V(Vector2());
801 return Point2(data.offset[0], data.offset[1]);
802}
803
804void Control::set_end(const Point2 &p_point) {
805 ERR_MAIN_THREAD_GUARD;
806 if (data.offset[2] == p_point.x && data.offset[3] == p_point.y) {
807 return;
808 }
809
810 data.offset[2] = p_point.x;
811 data.offset[3] = p_point.y;
812 _size_changed();
813}
814
815Point2 Control::get_end() const {
816 ERR_READ_THREAD_GUARD_V(Point2());
817 return Point2(data.offset[2], data.offset[3]);
818}
819
820void Control::set_h_grow_direction(GrowDirection p_direction) {
821 ERR_MAIN_THREAD_GUARD;
822 if (data.h_grow == p_direction) {
823 return;
824 }
825
826 ERR_FAIL_INDEX((int)p_direction, 3);
827
828 data.h_grow = p_direction;
829 _size_changed();
830}
831
832Control::GrowDirection Control::get_h_grow_direction() const {
833 ERR_READ_THREAD_GUARD_V(GROW_DIRECTION_BEGIN);
834 return data.h_grow;
835}
836
837void Control::set_v_grow_direction(GrowDirection p_direction) {
838 ERR_MAIN_THREAD_GUARD;
839 if (data.v_grow == p_direction) {
840 return;
841 }
842
843 ERR_FAIL_INDEX((int)p_direction, 3);
844
845 data.v_grow = p_direction;
846 _size_changed();
847}
848
849Control::GrowDirection Control::get_v_grow_direction() const {
850 ERR_READ_THREAD_GUARD_V(GROW_DIRECTION_BEGIN);
851 return data.v_grow;
852}
853
854void Control::_compute_anchors(Rect2 p_rect, const real_t p_offsets[4], real_t (&r_anchors)[4]) {
855 Size2 parent_rect_size = get_parent_anchorable_rect().size;
856 ERR_FAIL_COND(parent_rect_size.x == 0.0);
857 ERR_FAIL_COND(parent_rect_size.y == 0.0);
858
859 real_t x = p_rect.position.x;
860 if (is_layout_rtl()) {
861 x = parent_rect_size.x - x - p_rect.size.x;
862 }
863 r_anchors[0] = (x - p_offsets[0]) / parent_rect_size.x;
864 r_anchors[1] = (p_rect.position.y - p_offsets[1]) / parent_rect_size.y;
865 r_anchors[2] = (x + p_rect.size.x - p_offsets[2]) / parent_rect_size.x;
866 r_anchors[3] = (p_rect.position.y + p_rect.size.y - p_offsets[3]) / parent_rect_size.y;
867}
868
869void Control::_compute_offsets(Rect2 p_rect, const real_t p_anchors[4], real_t (&r_offsets)[4]) {
870 Size2 parent_rect_size = get_parent_anchorable_rect().size;
871
872 real_t x = p_rect.position.x;
873 if (is_layout_rtl()) {
874 x = parent_rect_size.x - x - p_rect.size.x;
875 }
876 r_offsets[0] = x - (p_anchors[0] * parent_rect_size.x);
877 r_offsets[1] = p_rect.position.y - (p_anchors[1] * parent_rect_size.y);
878 r_offsets[2] = x + p_rect.size.x - (p_anchors[2] * parent_rect_size.x);
879 r_offsets[3] = p_rect.position.y + p_rect.size.y - (p_anchors[3] * parent_rect_size.y);
880}
881
882/// Presets and layout modes.
883
884void Control::_set_layout_mode(LayoutMode p_mode) {
885 bool list_changed = false;
886
887 if (data.stored_layout_mode != p_mode) {
888 list_changed = true;
889 data.stored_layout_mode = p_mode;
890 }
891
892 if (data.stored_layout_mode == LayoutMode::LAYOUT_MODE_POSITION) {
893 data.stored_use_custom_anchors = false;
894 set_anchors_and_offsets_preset(LayoutPreset::PRESET_TOP_LEFT, LayoutPresetMode::PRESET_MODE_KEEP_SIZE);
895 set_grow_direction_preset(LayoutPreset::PRESET_TOP_LEFT);
896 }
897
898 if (list_changed) {
899 notify_property_list_changed();
900 }
901}
902
903void Control::_update_layout_mode() {
904 LayoutMode computed_layout = _get_layout_mode();
905 if (data.stored_layout_mode != computed_layout) {
906 data.stored_layout_mode = computed_layout;
907 notify_property_list_changed();
908 }
909}
910
911Control::LayoutMode Control::_get_layout_mode() const {
912 Node *parent_node = get_parent_control();
913 // In these modes the property is read-only.
914 if (!parent_node) {
915 return LayoutMode::LAYOUT_MODE_UNCONTROLLED;
916 } else if (Object::cast_to<Container>(parent_node)) {
917 return LayoutMode::LAYOUT_MODE_CONTAINER;
918 }
919
920 // If anchors are not in the top-left position, this is definitely in anchors mode.
921 if (_get_anchors_layout_preset() != (int)LayoutPreset::PRESET_TOP_LEFT) {
922 return LayoutMode::LAYOUT_MODE_ANCHORS;
923 }
924
925 // Otherwise fallback on what's stored.
926 return data.stored_layout_mode;
927}
928
929Control::LayoutMode Control::_get_default_layout_mode() const {
930 Node *parent_node = get_parent_control();
931 // In these modes the property is read-only.
932 if (!parent_node) {
933 return LayoutMode::LAYOUT_MODE_UNCONTROLLED;
934 } else if (Object::cast_to<Container>(parent_node)) {
935 return LayoutMode::LAYOUT_MODE_CONTAINER;
936 }
937
938 // Otherwise fallback on the position mode.
939 return LayoutMode::LAYOUT_MODE_POSITION;
940}
941
942void Control::_set_anchors_layout_preset(int p_preset) {
943 if (data.stored_layout_mode != LayoutMode::LAYOUT_MODE_UNCONTROLLED && data.stored_layout_mode != LayoutMode::LAYOUT_MODE_ANCHORS) {
944 // In other modes the anchor preset is non-operational and shouldn't be set to anything.
945 return;
946 }
947
948 if (p_preset == -1) {
949 if (!data.stored_use_custom_anchors) {
950 data.stored_use_custom_anchors = true;
951 notify_property_list_changed();
952 }
953 return; // Keep settings as is.
954 }
955
956 bool list_changed = false;
957
958 if (data.stored_use_custom_anchors) {
959 list_changed = true;
960 data.stored_use_custom_anchors = false;
961 }
962
963 LayoutPreset preset = (LayoutPreset)p_preset;
964 // Set correct anchors.
965 set_anchors_preset(preset);
966
967 // Select correct preset mode.
968 switch (preset) {
969 case PRESET_TOP_LEFT:
970 case PRESET_TOP_RIGHT:
971 case PRESET_BOTTOM_LEFT:
972 case PRESET_BOTTOM_RIGHT:
973 case PRESET_CENTER_LEFT:
974 case PRESET_CENTER_TOP:
975 case PRESET_CENTER_RIGHT:
976 case PRESET_CENTER_BOTTOM:
977 case PRESET_CENTER:
978 set_offsets_preset(preset, LayoutPresetMode::PRESET_MODE_KEEP_SIZE);
979 break;
980 case PRESET_LEFT_WIDE:
981 case PRESET_TOP_WIDE:
982 case PRESET_RIGHT_WIDE:
983 case PRESET_BOTTOM_WIDE:
984 case PRESET_VCENTER_WIDE:
985 case PRESET_HCENTER_WIDE:
986 case PRESET_FULL_RECT:
987 set_offsets_preset(preset, LayoutPresetMode::PRESET_MODE_MINSIZE);
988 break;
989 }
990
991 // Select correct grow directions.
992 set_grow_direction_preset(preset);
993
994 if (list_changed) {
995 notify_property_list_changed();
996 }
997}
998
999int Control::_get_anchors_layout_preset() const {
1000 // If this is a layout mode that doesn't rely on anchors, avoid excessive checks.
1001 if (data.stored_layout_mode != LayoutMode::LAYOUT_MODE_UNCONTROLLED && data.stored_layout_mode != LayoutMode::LAYOUT_MODE_ANCHORS) {
1002 return LayoutPreset::PRESET_TOP_LEFT;
1003 }
1004
1005 // If the custom preset was selected by user, use it.
1006 if (data.stored_use_custom_anchors) {
1007 return -1;
1008 }
1009
1010 // Check anchors to determine if the current state matches a preset, or not.
1011
1012 float left = get_anchor(SIDE_LEFT);
1013 float right = get_anchor(SIDE_RIGHT);
1014 float top = get_anchor(SIDE_TOP);
1015 float bottom = get_anchor(SIDE_BOTTOM);
1016
1017 if (left == ANCHOR_BEGIN && right == ANCHOR_BEGIN && top == ANCHOR_BEGIN && bottom == ANCHOR_BEGIN) {
1018 return (int)LayoutPreset::PRESET_TOP_LEFT;
1019 }
1020 if (left == ANCHOR_END && right == ANCHOR_END && top == ANCHOR_BEGIN && bottom == ANCHOR_BEGIN) {
1021 return (int)LayoutPreset::PRESET_TOP_RIGHT;
1022 }
1023 if (left == ANCHOR_BEGIN && right == ANCHOR_BEGIN && top == ANCHOR_END && bottom == ANCHOR_END) {
1024 return (int)LayoutPreset::PRESET_BOTTOM_LEFT;
1025 }
1026 if (left == ANCHOR_END && right == ANCHOR_END && top == ANCHOR_END && bottom == ANCHOR_END) {
1027 return (int)LayoutPreset::PRESET_BOTTOM_RIGHT;
1028 }
1029
1030 if (left == ANCHOR_BEGIN && right == ANCHOR_BEGIN && top == 0.5 && bottom == 0.5) {
1031 return (int)LayoutPreset::PRESET_CENTER_LEFT;
1032 }
1033 if (left == ANCHOR_END && right == ANCHOR_END && top == 0.5 && bottom == 0.5) {
1034 return (int)LayoutPreset::PRESET_CENTER_RIGHT;
1035 }
1036 if (left == 0.5 && right == 0.5 && top == ANCHOR_BEGIN && bottom == ANCHOR_BEGIN) {
1037 return (int)LayoutPreset::PRESET_CENTER_TOP;
1038 }
1039 if (left == 0.5 && right == 0.5 && top == ANCHOR_END && bottom == ANCHOR_END) {
1040 return (int)LayoutPreset::PRESET_CENTER_BOTTOM;
1041 }
1042 if (left == 0.5 && right == 0.5 && top == 0.5 && bottom == 0.5) {
1043 return (int)LayoutPreset::PRESET_CENTER;
1044 }
1045
1046 if (left == ANCHOR_BEGIN && right == ANCHOR_BEGIN && top == ANCHOR_BEGIN && bottom == ANCHOR_END) {
1047 return (int)LayoutPreset::PRESET_LEFT_WIDE;
1048 }
1049 if (left == ANCHOR_END && right == ANCHOR_END && top == ANCHOR_BEGIN && bottom == ANCHOR_END) {
1050 return (int)LayoutPreset::PRESET_RIGHT_WIDE;
1051 }
1052 if (left == ANCHOR_BEGIN && right == ANCHOR_END && top == ANCHOR_BEGIN && bottom == ANCHOR_BEGIN) {
1053 return (int)LayoutPreset::PRESET_TOP_WIDE;
1054 }
1055 if (left == ANCHOR_BEGIN && right == ANCHOR_END && top == ANCHOR_END && bottom == ANCHOR_END) {
1056 return (int)LayoutPreset::PRESET_BOTTOM_WIDE;
1057 }
1058
1059 if (left == 0.5 && right == 0.5 && top == ANCHOR_BEGIN && bottom == ANCHOR_END) {
1060 return (int)LayoutPreset::PRESET_VCENTER_WIDE;
1061 }
1062 if (left == ANCHOR_BEGIN && right == ANCHOR_END && top == 0.5 && bottom == 0.5) {
1063 return (int)LayoutPreset::PRESET_HCENTER_WIDE;
1064 }
1065
1066 if (left == ANCHOR_BEGIN && right == ANCHOR_END && top == ANCHOR_BEGIN && bottom == ANCHOR_END) {
1067 return (int)LayoutPreset::PRESET_FULL_RECT;
1068 }
1069
1070 // Does not match any preset, return "Custom".
1071 return -1;
1072}
1073
1074void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_offsets) {
1075 ERR_MAIN_THREAD_GUARD;
1076 ERR_FAIL_INDEX((int)p_preset, 16);
1077
1078 //Left
1079 switch (p_preset) {
1080 case PRESET_TOP_LEFT:
1081 case PRESET_BOTTOM_LEFT:
1082 case PRESET_CENTER_LEFT:
1083 case PRESET_TOP_WIDE:
1084 case PRESET_BOTTOM_WIDE:
1085 case PRESET_LEFT_WIDE:
1086 case PRESET_HCENTER_WIDE:
1087 case PRESET_FULL_RECT:
1088 set_anchor(SIDE_LEFT, ANCHOR_BEGIN, p_keep_offsets);
1089 break;
1090
1091 case PRESET_CENTER_TOP:
1092 case PRESET_CENTER_BOTTOM:
1093 case PRESET_CENTER:
1094 case PRESET_VCENTER_WIDE:
1095 set_anchor(SIDE_LEFT, 0.5, p_keep_offsets);
1096 break;
1097
1098 case PRESET_TOP_RIGHT:
1099 case PRESET_BOTTOM_RIGHT:
1100 case PRESET_CENTER_RIGHT:
1101 case PRESET_RIGHT_WIDE:
1102 set_anchor(SIDE_LEFT, ANCHOR_END, p_keep_offsets);
1103 break;
1104 }
1105
1106 // Top
1107 switch (p_preset) {
1108 case PRESET_TOP_LEFT:
1109 case PRESET_TOP_RIGHT:
1110 case PRESET_CENTER_TOP:
1111 case PRESET_LEFT_WIDE:
1112 case PRESET_RIGHT_WIDE:
1113 case PRESET_TOP_WIDE:
1114 case PRESET_VCENTER_WIDE:
1115 case PRESET_FULL_RECT:
1116 set_anchor(SIDE_TOP, ANCHOR_BEGIN, p_keep_offsets);
1117 break;
1118
1119 case PRESET_CENTER_LEFT:
1120 case PRESET_CENTER_RIGHT:
1121 case PRESET_CENTER:
1122 case PRESET_HCENTER_WIDE:
1123 set_anchor(SIDE_TOP, 0.5, p_keep_offsets);
1124 break;
1125
1126 case PRESET_BOTTOM_LEFT:
1127 case PRESET_BOTTOM_RIGHT:
1128 case PRESET_CENTER_BOTTOM:
1129 case PRESET_BOTTOM_WIDE:
1130 set_anchor(SIDE_TOP, ANCHOR_END, p_keep_offsets);
1131 break;
1132 }
1133
1134 // Right
1135 switch (p_preset) {
1136 case PRESET_TOP_LEFT:
1137 case PRESET_BOTTOM_LEFT:
1138 case PRESET_CENTER_LEFT:
1139 case PRESET_LEFT_WIDE:
1140 set_anchor(SIDE_RIGHT, ANCHOR_BEGIN, p_keep_offsets);
1141 break;
1142
1143 case PRESET_CENTER_TOP:
1144 case PRESET_CENTER_BOTTOM:
1145 case PRESET_CENTER:
1146 case PRESET_VCENTER_WIDE:
1147 set_anchor(SIDE_RIGHT, 0.5, p_keep_offsets);
1148 break;
1149
1150 case PRESET_TOP_RIGHT:
1151 case PRESET_BOTTOM_RIGHT:
1152 case PRESET_CENTER_RIGHT:
1153 case PRESET_TOP_WIDE:
1154 case PRESET_RIGHT_WIDE:
1155 case PRESET_BOTTOM_WIDE:
1156 case PRESET_HCENTER_WIDE:
1157 case PRESET_FULL_RECT:
1158 set_anchor(SIDE_RIGHT, ANCHOR_END, p_keep_offsets);
1159 break;
1160 }
1161
1162 // Bottom
1163 switch (p_preset) {
1164 case PRESET_TOP_LEFT:
1165 case PRESET_TOP_RIGHT:
1166 case PRESET_CENTER_TOP:
1167 case PRESET_TOP_WIDE:
1168 set_anchor(SIDE_BOTTOM, ANCHOR_BEGIN, p_keep_offsets);
1169 break;
1170
1171 case PRESET_CENTER_LEFT:
1172 case PRESET_CENTER_RIGHT:
1173 case PRESET_CENTER:
1174 case PRESET_HCENTER_WIDE:
1175 set_anchor(SIDE_BOTTOM, 0.5, p_keep_offsets);
1176 break;
1177
1178 case PRESET_BOTTOM_LEFT:
1179 case PRESET_BOTTOM_RIGHT:
1180 case PRESET_CENTER_BOTTOM:
1181 case PRESET_LEFT_WIDE:
1182 case PRESET_RIGHT_WIDE:
1183 case PRESET_BOTTOM_WIDE:
1184 case PRESET_VCENTER_WIDE:
1185 case PRESET_FULL_RECT:
1186 set_anchor(SIDE_BOTTOM, ANCHOR_END, p_keep_offsets);
1187 break;
1188 }
1189}
1190
1191void Control::set_offsets_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode, int p_margin) {
1192 ERR_MAIN_THREAD_GUARD;
1193 ERR_FAIL_INDEX((int)p_preset, 16);
1194 ERR_FAIL_INDEX((int)p_resize_mode, 4);
1195
1196 // Calculate the size if the node is not resized
1197 Size2 min_size = get_minimum_size();
1198 Size2 new_size = get_size();
1199 if (p_resize_mode == PRESET_MODE_MINSIZE || p_resize_mode == PRESET_MODE_KEEP_HEIGHT) {
1200 new_size.x = min_size.x;
1201 }
1202 if (p_resize_mode == PRESET_MODE_MINSIZE || p_resize_mode == PRESET_MODE_KEEP_WIDTH) {
1203 new_size.y = min_size.y;
1204 }
1205
1206 Rect2 parent_rect = get_parent_anchorable_rect();
1207
1208 real_t x = parent_rect.size.x;
1209 if (is_layout_rtl()) {
1210 x = parent_rect.size.x - x - new_size.x;
1211 }
1212 //Left
1213 switch (p_preset) {
1214 case PRESET_TOP_LEFT:
1215 case PRESET_BOTTOM_LEFT:
1216 case PRESET_CENTER_LEFT:
1217 case PRESET_TOP_WIDE:
1218 case PRESET_BOTTOM_WIDE:
1219 case PRESET_LEFT_WIDE:
1220 case PRESET_HCENTER_WIDE:
1221 case PRESET_FULL_RECT:
1222 data.offset[0] = x * (0.0 - data.anchor[0]) + p_margin + parent_rect.position.x;
1223 break;
1224
1225 case PRESET_CENTER_TOP:
1226 case PRESET_CENTER_BOTTOM:
1227 case PRESET_CENTER:
1228 case PRESET_VCENTER_WIDE:
1229 data.offset[0] = x * (0.5 - data.anchor[0]) - new_size.x / 2 + parent_rect.position.x;
1230 break;
1231
1232 case PRESET_TOP_RIGHT:
1233 case PRESET_BOTTOM_RIGHT:
1234 case PRESET_CENTER_RIGHT:
1235 case PRESET_RIGHT_WIDE:
1236 data.offset[0] = x * (1.0 - data.anchor[0]) - new_size.x - p_margin + parent_rect.position.x;
1237 break;
1238 }
1239
1240 // Top
1241 switch (p_preset) {
1242 case PRESET_TOP_LEFT:
1243 case PRESET_TOP_RIGHT:
1244 case PRESET_CENTER_TOP:
1245 case PRESET_LEFT_WIDE:
1246 case PRESET_RIGHT_WIDE:
1247 case PRESET_TOP_WIDE:
1248 case PRESET_VCENTER_WIDE:
1249 case PRESET_FULL_RECT:
1250 data.offset[1] = parent_rect.size.y * (0.0 - data.anchor[1]) + p_margin + parent_rect.position.y;
1251 break;
1252
1253 case PRESET_CENTER_LEFT:
1254 case PRESET_CENTER_RIGHT:
1255 case PRESET_CENTER:
1256 case PRESET_HCENTER_WIDE:
1257 data.offset[1] = parent_rect.size.y * (0.5 - data.anchor[1]) - new_size.y / 2 + parent_rect.position.y;
1258 break;
1259
1260 case PRESET_BOTTOM_LEFT:
1261 case PRESET_BOTTOM_RIGHT:
1262 case PRESET_CENTER_BOTTOM:
1263 case PRESET_BOTTOM_WIDE:
1264 data.offset[1] = parent_rect.size.y * (1.0 - data.anchor[1]) - new_size.y - p_margin + parent_rect.position.y;
1265 break;
1266 }
1267
1268 // Right
1269 switch (p_preset) {
1270 case PRESET_TOP_LEFT:
1271 case PRESET_BOTTOM_LEFT:
1272 case PRESET_CENTER_LEFT:
1273 case PRESET_LEFT_WIDE:
1274 data.offset[2] = x * (0.0 - data.anchor[2]) + new_size.x + p_margin + parent_rect.position.x;
1275 break;
1276
1277 case PRESET_CENTER_TOP:
1278 case PRESET_CENTER_BOTTOM:
1279 case PRESET_CENTER:
1280 case PRESET_VCENTER_WIDE:
1281 data.offset[2] = x * (0.5 - data.anchor[2]) + new_size.x / 2 + parent_rect.position.x;
1282 break;
1283
1284 case PRESET_TOP_RIGHT:
1285 case PRESET_BOTTOM_RIGHT:
1286 case PRESET_CENTER_RIGHT:
1287 case PRESET_TOP_WIDE:
1288 case PRESET_RIGHT_WIDE:
1289 case PRESET_BOTTOM_WIDE:
1290 case PRESET_HCENTER_WIDE:
1291 case PRESET_FULL_RECT:
1292 data.offset[2] = x * (1.0 - data.anchor[2]) - p_margin + parent_rect.position.x;
1293 break;
1294 }
1295
1296 // Bottom
1297 switch (p_preset) {
1298 case PRESET_TOP_LEFT:
1299 case PRESET_TOP_RIGHT:
1300 case PRESET_CENTER_TOP:
1301 case PRESET_TOP_WIDE:
1302 data.offset[3] = parent_rect.size.y * (0.0 - data.anchor[3]) + new_size.y + p_margin + parent_rect.position.y;
1303 break;
1304
1305 case PRESET_CENTER_LEFT:
1306 case PRESET_CENTER_RIGHT:
1307 case PRESET_CENTER:
1308 case PRESET_HCENTER_WIDE:
1309 data.offset[3] = parent_rect.size.y * (0.5 - data.anchor[3]) + new_size.y / 2 + parent_rect.position.y;
1310 break;
1311
1312 case PRESET_BOTTOM_LEFT:
1313 case PRESET_BOTTOM_RIGHT:
1314 case PRESET_CENTER_BOTTOM:
1315 case PRESET_LEFT_WIDE:
1316 case PRESET_RIGHT_WIDE:
1317 case PRESET_BOTTOM_WIDE:
1318 case PRESET_VCENTER_WIDE:
1319 case PRESET_FULL_RECT:
1320 data.offset[3] = parent_rect.size.y * (1.0 - data.anchor[3]) - p_margin + parent_rect.position.y;
1321 break;
1322 }
1323
1324 _size_changed();
1325}
1326
1327void Control::set_anchors_and_offsets_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode, int p_margin) {
1328 ERR_MAIN_THREAD_GUARD;
1329 set_anchors_preset(p_preset);
1330 set_offsets_preset(p_preset, p_resize_mode, p_margin);
1331}
1332
1333void Control::set_grow_direction_preset(LayoutPreset p_preset) {
1334 ERR_MAIN_THREAD_GUARD;
1335 // Select correct horizontal grow direction.
1336 switch (p_preset) {
1337 case PRESET_TOP_LEFT:
1338 case PRESET_BOTTOM_LEFT:
1339 case PRESET_CENTER_LEFT:
1340 case PRESET_LEFT_WIDE:
1341 set_h_grow_direction(GrowDirection::GROW_DIRECTION_END);
1342 break;
1343 case PRESET_TOP_RIGHT:
1344 case PRESET_BOTTOM_RIGHT:
1345 case PRESET_CENTER_RIGHT:
1346 case PRESET_RIGHT_WIDE:
1347 set_h_grow_direction(GrowDirection::GROW_DIRECTION_BEGIN);
1348 break;
1349 case PRESET_CENTER_TOP:
1350 case PRESET_CENTER_BOTTOM:
1351 case PRESET_CENTER:
1352 case PRESET_TOP_WIDE:
1353 case PRESET_BOTTOM_WIDE:
1354 case PRESET_VCENTER_WIDE:
1355 case PRESET_HCENTER_WIDE:
1356 case PRESET_FULL_RECT:
1357 set_h_grow_direction(GrowDirection::GROW_DIRECTION_BOTH);
1358 break;
1359 }
1360
1361 // Select correct vertical grow direction.
1362 switch (p_preset) {
1363 case PRESET_TOP_LEFT:
1364 case PRESET_TOP_RIGHT:
1365 case PRESET_CENTER_TOP:
1366 case PRESET_TOP_WIDE:
1367 set_v_grow_direction(GrowDirection::GROW_DIRECTION_END);
1368 break;
1369
1370 case PRESET_BOTTOM_LEFT:
1371 case PRESET_BOTTOM_RIGHT:
1372 case PRESET_CENTER_BOTTOM:
1373 case PRESET_BOTTOM_WIDE:
1374 set_v_grow_direction(GrowDirection::GROW_DIRECTION_BEGIN);
1375 break;
1376
1377 case PRESET_CENTER_LEFT:
1378 case PRESET_CENTER_RIGHT:
1379 case PRESET_CENTER:
1380 case PRESET_LEFT_WIDE:
1381 case PRESET_RIGHT_WIDE:
1382 case PRESET_VCENTER_WIDE:
1383 case PRESET_HCENTER_WIDE:
1384 case PRESET_FULL_RECT:
1385 set_v_grow_direction(GrowDirection::GROW_DIRECTION_BOTH);
1386 break;
1387 }
1388}
1389
1390/// Manual positioning.
1391
1392void Control::_set_position(const Point2 &p_point) {
1393 set_position(p_point);
1394}
1395
1396void Control::set_position(const Point2 &p_point, bool p_keep_offsets) {
1397 ERR_MAIN_THREAD_GUARD;
1398 if (p_keep_offsets) {
1399 _compute_anchors(Rect2(p_point, data.size_cache), data.offset, data.anchor);
1400 } else {
1401 _compute_offsets(Rect2(p_point, data.size_cache), data.anchor, data.offset);
1402 }
1403 _size_changed();
1404}
1405
1406Size2 Control::get_position() const {
1407 ERR_READ_THREAD_GUARD_V(Size2());
1408 return data.pos_cache;
1409}
1410
1411void Control::_set_global_position(const Point2 &p_point) {
1412 set_global_position(p_point);
1413}
1414
1415void Control::set_global_position(const Point2 &p_point, bool p_keep_offsets) {
1416 ERR_MAIN_THREAD_GUARD;
1417 Transform2D inv;
1418
1419 if (data.parent_canvas_item) {
1420 inv = data.parent_canvas_item->get_global_transform().affine_inverse();
1421 }
1422
1423 set_position(inv.xform(p_point), p_keep_offsets);
1424}
1425
1426Point2 Control::get_global_position() const {
1427 ERR_READ_THREAD_GUARD_V(Point2());
1428 return get_global_transform().get_origin();
1429}
1430
1431Point2 Control::get_screen_position() const {
1432 ERR_READ_THREAD_GUARD_V(Point2());
1433 ERR_FAIL_COND_V(!is_inside_tree(), Point2());
1434 return get_screen_transform().get_origin();
1435}
1436
1437void Control::_set_size(const Size2 &p_size) {
1438#ifdef DEBUG_ENABLED
1439 if (data.size_warning && (data.anchor[SIDE_LEFT] != data.anchor[SIDE_RIGHT] || data.anchor[SIDE_TOP] != data.anchor[SIDE_BOTTOM])) {
1440 WARN_PRINT("Nodes with non-equal opposite anchors will have their size overridden after _ready(). \nIf you want to set size, change the anchors or consider using set_deferred().");
1441 }
1442#endif
1443 set_size(p_size);
1444}
1445
1446void Control::set_size(const Size2 &p_size, bool p_keep_offsets) {
1447 ERR_MAIN_THREAD_GUARD;
1448 ERR_FAIL_COND(!isfinite(p_size.x) || !isfinite(p_size.y));
1449 Size2 new_size = p_size;
1450 Size2 min = get_combined_minimum_size();
1451 if (new_size.x < min.x) {
1452 new_size.x = min.x;
1453 }
1454 if (new_size.y < min.y) {
1455 new_size.y = min.y;
1456 }
1457
1458 if (p_keep_offsets) {
1459 _compute_anchors(Rect2(data.pos_cache, new_size), data.offset, data.anchor);
1460 } else {
1461 _compute_offsets(Rect2(data.pos_cache, new_size), data.anchor, data.offset);
1462 }
1463 _size_changed();
1464}
1465
1466Size2 Control::get_size() const {
1467 ERR_READ_THREAD_GUARD_V(Size2());
1468 return data.size_cache;
1469}
1470
1471void Control::reset_size() {
1472 ERR_MAIN_THREAD_GUARD;
1473 set_size(Size2());
1474}
1475
1476void Control::set_rect(const Rect2 &p_rect) {
1477 ERR_MAIN_THREAD_GUARD;
1478 for (int i = 0; i < 4; i++) {
1479 data.anchor[i] = ANCHOR_BEGIN;
1480 }
1481
1482 _compute_offsets(p_rect, data.anchor, data.offset);
1483 if (is_inside_tree()) {
1484 _size_changed();
1485 }
1486}
1487
1488Rect2 Control::get_rect() const {
1489 ERR_READ_THREAD_GUARD_V(Rect2());
1490 Transform2D xform = get_transform();
1491 return Rect2(xform.get_origin(), xform.get_scale() * get_size());
1492}
1493
1494Rect2 Control::get_global_rect() const {
1495 ERR_READ_THREAD_GUARD_V(Rect2());
1496 Transform2D xform = get_global_transform();
1497 return Rect2(xform.get_origin(), xform.get_scale() * get_size());
1498}
1499
1500Rect2 Control::get_screen_rect() const {
1501 ERR_READ_THREAD_GUARD_V(Rect2());
1502 ERR_FAIL_COND_V(!is_inside_tree(), Rect2());
1503
1504 Transform2D xform = get_screen_transform();
1505 return Rect2(xform.get_origin(), xform.get_scale() * get_size());
1506}
1507
1508Rect2 Control::get_anchorable_rect() const {
1509 ERR_READ_THREAD_GUARD_V(Rect2());
1510 return Rect2(Point2(), get_size());
1511}
1512
1513void Control::set_scale(const Vector2 &p_scale) {
1514 ERR_MAIN_THREAD_GUARD;
1515 if (data.scale == p_scale) {
1516 return;
1517 }
1518
1519 data.scale = p_scale;
1520 // Avoid having 0 scale values, can lead to errors in physics and rendering.
1521 if (data.scale.x == 0) {
1522 data.scale.x = CMP_EPSILON;
1523 }
1524 if (data.scale.y == 0) {
1525 data.scale.y = CMP_EPSILON;
1526 }
1527 queue_redraw();
1528 _notify_transform();
1529}
1530
1531Vector2 Control::get_scale() const {
1532 ERR_READ_THREAD_GUARD_V(Vector2());
1533 return data.scale;
1534}
1535
1536void Control::set_rotation(real_t p_radians) {
1537 ERR_MAIN_THREAD_GUARD;
1538 if (data.rotation == p_radians) {
1539 return;
1540 }
1541
1542 data.rotation = p_radians;
1543 queue_redraw();
1544 _notify_transform();
1545}
1546
1547void Control::set_rotation_degrees(real_t p_degrees) {
1548 ERR_MAIN_THREAD_GUARD;
1549 set_rotation(Math::deg_to_rad(p_degrees));
1550}
1551
1552real_t Control::get_rotation() const {
1553 ERR_READ_THREAD_GUARD_V(0);
1554 return data.rotation;
1555}
1556
1557real_t Control::get_rotation_degrees() const {
1558 ERR_READ_THREAD_GUARD_V(0);
1559 return Math::rad_to_deg(get_rotation());
1560}
1561
1562void Control::set_pivot_offset(const Vector2 &p_pivot) {
1563 ERR_MAIN_THREAD_GUARD;
1564 if (data.pivot_offset == p_pivot) {
1565 return;
1566 }
1567
1568 data.pivot_offset = p_pivot;
1569 queue_redraw();
1570 _notify_transform();
1571}
1572
1573Vector2 Control::get_pivot_offset() const {
1574 ERR_READ_THREAD_GUARD_V(Vector2());
1575 return data.pivot_offset;
1576}
1577
1578/// Sizes.
1579
1580void Control::_update_minimum_size() {
1581 if (!is_inside_tree()) {
1582 data.updating_last_minimum_size = false;
1583 return;
1584 }
1585
1586 Size2 minsize = get_combined_minimum_size();
1587 data.updating_last_minimum_size = false;
1588
1589 if (minsize != data.last_minimum_size) {
1590 data.last_minimum_size = minsize;
1591 _size_changed();
1592 emit_signal(SceneStringNames::get_singleton()->minimum_size_changed);
1593 }
1594}
1595
1596void Control::update_minimum_size() {
1597 ERR_MAIN_THREAD_GUARD;
1598 if (!is_inside_tree() || data.block_minimum_size_adjust) {
1599 return;
1600 }
1601
1602 // Invalidate cache upwards.
1603 Control *invalidate = this;
1604 while (invalidate && invalidate->data.minimum_size_valid) {
1605 invalidate->data.minimum_size_valid = false;
1606 if (invalidate->is_set_as_top_level()) {
1607 break; // Do not go further up.
1608 }
1609
1610 Window *parent_window = invalidate->get_parent_window();
1611 if (parent_window && parent_window->is_wrapping_controls()) {
1612 parent_window->child_controls_changed();
1613 break; // Stop on a window as well.
1614 }
1615
1616 invalidate = invalidate->get_parent_control();
1617 }
1618
1619 if (!is_visible_in_tree()) {
1620 return;
1621 }
1622
1623 if (data.updating_last_minimum_size) {
1624 return;
1625 }
1626 data.updating_last_minimum_size = true;
1627
1628 MessageQueue::get_singleton()->push_callable(callable_mp(this, &Control::_update_minimum_size));
1629}
1630
1631void Control::set_block_minimum_size_adjust(bool p_block) {
1632 ERR_MAIN_THREAD_GUARD;
1633 data.block_minimum_size_adjust = p_block;
1634}
1635
1636Size2 Control::get_minimum_size() const {
1637 ERR_READ_THREAD_GUARD_V(Size2());
1638 Vector2 ms;
1639 GDVIRTUAL_CALL(_get_minimum_size, ms);
1640 return ms;
1641}
1642
1643void Control::set_custom_minimum_size(const Size2 &p_custom) {
1644 ERR_MAIN_THREAD_GUARD;
1645 if (p_custom == data.custom_minimum_size) {
1646 return;
1647 }
1648
1649 if (!isfinite(p_custom.x) || !isfinite(p_custom.y)) {
1650 // Prevent infinite loop.
1651 return;
1652 }
1653
1654 data.custom_minimum_size = p_custom;
1655 update_minimum_size();
1656}
1657
1658Size2 Control::get_custom_minimum_size() const {
1659 ERR_READ_THREAD_GUARD_V(Size2());
1660 return data.custom_minimum_size;
1661}
1662
1663void Control::_update_minimum_size_cache() {
1664 Size2 minsize = get_minimum_size();
1665 minsize.x = MAX(minsize.x, data.custom_minimum_size.x);
1666 minsize.y = MAX(minsize.y, data.custom_minimum_size.y);
1667
1668 data.minimum_size_cache = minsize;
1669 data.minimum_size_valid = true;
1670}
1671
1672Size2 Control::get_combined_minimum_size() const {
1673 ERR_READ_THREAD_GUARD_V(Size2());
1674 if (!data.minimum_size_valid) {
1675 const_cast<Control *>(this)->_update_minimum_size_cache();
1676 }
1677 return data.minimum_size_cache;
1678}
1679
1680void Control::_size_changed() {
1681 Rect2 parent_rect = get_parent_anchorable_rect();
1682
1683 real_t edge_pos[4];
1684
1685 for (int i = 0; i < 4; i++) {
1686 real_t area = parent_rect.size[i & 1];
1687 edge_pos[i] = data.offset[i] + (data.anchor[i] * area);
1688 }
1689
1690 Point2 new_pos_cache = Point2(edge_pos[0], edge_pos[1]);
1691 Size2 new_size_cache = Point2(edge_pos[2], edge_pos[3]) - new_pos_cache;
1692
1693 Size2 minimum_size = get_combined_minimum_size();
1694
1695 if (minimum_size.width > new_size_cache.width) {
1696 if (data.h_grow == GROW_DIRECTION_BEGIN) {
1697 new_pos_cache.x += new_size_cache.width - minimum_size.width;
1698 } else if (data.h_grow == GROW_DIRECTION_BOTH) {
1699 new_pos_cache.x += 0.5 * (new_size_cache.width - minimum_size.width);
1700 }
1701
1702 new_size_cache.width = minimum_size.width;
1703 }
1704
1705 if (is_layout_rtl()) {
1706 new_pos_cache.x = parent_rect.size.x + 2 * parent_rect.position.x - new_pos_cache.x - new_size_cache.x;
1707 }
1708
1709 if (minimum_size.height > new_size_cache.height) {
1710 if (data.v_grow == GROW_DIRECTION_BEGIN) {
1711 new_pos_cache.y += new_size_cache.height - minimum_size.height;
1712 } else if (data.v_grow == GROW_DIRECTION_BOTH) {
1713 new_pos_cache.y += 0.5 * (new_size_cache.height - minimum_size.height);
1714 }
1715
1716 new_size_cache.height = minimum_size.height;
1717 }
1718
1719 bool pos_changed = new_pos_cache != data.pos_cache;
1720 bool size_changed = new_size_cache != data.size_cache;
1721
1722 data.pos_cache = new_pos_cache;
1723 data.size_cache = new_size_cache;
1724
1725 if (is_inside_tree()) {
1726 if (size_changed) {
1727 notification(NOTIFICATION_RESIZED);
1728 }
1729 if (pos_changed || size_changed) {
1730 item_rect_changed(size_changed);
1731 _notify_transform();
1732 }
1733
1734 if (pos_changed && !size_changed) {
1735 _update_canvas_item_transform(); //move because it won't be updated
1736 }
1737 } else {
1738 if (pos_changed) {
1739 _notify_transform();
1740 }
1741 }
1742}
1743
1744void Control::_clear_size_warning() {
1745 data.size_warning = false;
1746}
1747
1748// Container sizing.
1749
1750void Control::set_h_size_flags(BitField<SizeFlags> p_flags) {
1751 ERR_MAIN_THREAD_GUARD;
1752 if ((int)data.h_size_flags == (int)p_flags) {
1753 return;
1754 }
1755 data.h_size_flags = p_flags;
1756 emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
1757}
1758
1759BitField<Control::SizeFlags> Control::get_h_size_flags() const {
1760 ERR_READ_THREAD_GUARD_V(SIZE_EXPAND_FILL);
1761 return data.h_size_flags;
1762}
1763
1764void Control::set_v_size_flags(BitField<SizeFlags> p_flags) {
1765 ERR_MAIN_THREAD_GUARD;
1766 if ((int)data.v_size_flags == (int)p_flags) {
1767 return;
1768 }
1769 data.v_size_flags = p_flags;
1770 emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
1771}
1772
1773BitField<Control::SizeFlags> Control::get_v_size_flags() const {
1774 ERR_READ_THREAD_GUARD_V(SIZE_EXPAND_FILL);
1775 return data.v_size_flags;
1776}
1777
1778void Control::set_stretch_ratio(real_t p_ratio) {
1779 ERR_MAIN_THREAD_GUARD;
1780 if (data.expand == p_ratio) {
1781 return;
1782 }
1783
1784 data.expand = p_ratio;
1785 emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
1786}
1787
1788real_t Control::get_stretch_ratio() const {
1789 ERR_READ_THREAD_GUARD_V(0);
1790 return data.expand;
1791}
1792
1793// Input events.
1794
1795void Control::_call_gui_input(const Ref<InputEvent> &p_event) {
1796 if (p_event->get_device() != InputEvent::DEVICE_ID_INTERNAL) {
1797 emit_signal(SceneStringNames::get_singleton()->gui_input, p_event); // Signal should be first, so it's possible to override an event (and then accept it).
1798 }
1799 if (!is_inside_tree() || get_viewport()->is_input_handled()) {
1800 return; // Input was handled, abort.
1801 }
1802
1803 if (p_event->get_device() != InputEvent::DEVICE_ID_INTERNAL) {
1804 GDVIRTUAL_CALL(_gui_input, p_event);
1805 }
1806 if (!is_inside_tree() || get_viewport()->is_input_handled()) {
1807 return; // Input was handled, abort.
1808 }
1809 gui_input(p_event);
1810}
1811
1812void Control::gui_input(const Ref<InputEvent> &p_event) {
1813}
1814
1815void Control::accept_event() {
1816 ERR_MAIN_THREAD_GUARD;
1817 if (is_inside_tree()) {
1818 get_viewport()->_gui_accept_event();
1819 }
1820}
1821
1822bool Control::has_point(const Point2 &p_point) const {
1823 ERR_READ_THREAD_GUARD_V(false);
1824 bool ret;
1825 if (GDVIRTUAL_CALL(_has_point, p_point, ret)) {
1826 return ret;
1827 }
1828 return Rect2(Point2(), get_size()).has_point(p_point);
1829}
1830
1831void Control::set_mouse_filter(MouseFilter p_filter) {
1832 ERR_MAIN_THREAD_GUARD;
1833 ERR_FAIL_INDEX(p_filter, 3);
1834 data.mouse_filter = p_filter;
1835 notify_property_list_changed();
1836 update_configuration_warnings();
1837}
1838
1839Control::MouseFilter Control::get_mouse_filter() const {
1840 ERR_READ_THREAD_GUARD_V(MOUSE_FILTER_IGNORE);
1841 return data.mouse_filter;
1842}
1843
1844void Control::set_force_pass_scroll_events(bool p_force_pass_scroll_events) {
1845 ERR_MAIN_THREAD_GUARD;
1846 data.force_pass_scroll_events = p_force_pass_scroll_events;
1847}
1848
1849bool Control::is_force_pass_scroll_events() const {
1850 ERR_READ_THREAD_GUARD_V(false);
1851 return data.force_pass_scroll_events;
1852}
1853
1854void Control::warp_mouse(const Point2 &p_position) {
1855 ERR_MAIN_THREAD_GUARD;
1856 ERR_FAIL_COND(!is_inside_tree());
1857 get_viewport()->warp_mouse(get_global_transform_with_canvas().xform(p_position));
1858}
1859
1860void Control::set_shortcut_context(const Node *p_node) {
1861 ERR_MAIN_THREAD_GUARD;
1862 if (p_node != nullptr) {
1863 data.shortcut_context = p_node->get_instance_id();
1864 } else {
1865 data.shortcut_context = ObjectID();
1866 }
1867}
1868
1869Node *Control::get_shortcut_context() const {
1870 ERR_READ_THREAD_GUARD_V(nullptr);
1871 Object *ctx_obj = ObjectDB::get_instance(data.shortcut_context);
1872 Node *ctx_node = Object::cast_to<Node>(ctx_obj);
1873
1874 return ctx_node;
1875}
1876
1877bool Control::is_focus_owner_in_shortcut_context() const {
1878 ERR_READ_THREAD_GUARD_V(false);
1879 if (data.shortcut_context == ObjectID()) {
1880 // No context, therefore global - always "in" context.
1881 return true;
1882 }
1883
1884 const Node *ctx_node = get_shortcut_context();
1885 const Control *vp_focus = get_viewport() ? get_viewport()->gui_get_focus_owner() : nullptr;
1886
1887 // If the context is valid and the viewport focus is valid, check if the context is the focus or is a parent of it.
1888 return ctx_node && vp_focus && (ctx_node == vp_focus || ctx_node->is_ancestor_of(vp_focus));
1889}
1890
1891// Drag and drop handling.
1892
1893void Control::set_drag_forwarding(const Callable &p_drag, const Callable &p_can_drop, const Callable &p_drop) {
1894 ERR_MAIN_THREAD_GUARD;
1895 data.forward_drag = p_drag;
1896 data.forward_can_drop = p_can_drop;
1897 data.forward_drop = p_drop;
1898}
1899
1900Variant Control::get_drag_data(const Point2 &p_point) {
1901 ERR_READ_THREAD_GUARD_V(Variant());
1902 Variant ret;
1903 if (data.forward_drag.is_valid()) {
1904 Variant p = p_point;
1905 const Variant *vp[1] = { &p };
1906 Callable::CallError ce;
1907 data.forward_drag.callp((const Variant **)vp, 1, ret, ce);
1908 if (ce.error != Callable::CallError::CALL_OK) {
1909 ERR_FAIL_V_MSG(Variant(), "Error calling forwarded method from 'get_drag_data': " + Variant::get_callable_error_text(data.forward_drag, (const Variant **)vp, 1, ce) + ".");
1910 }
1911 return ret;
1912 }
1913
1914 GDVIRTUAL_CALL(_get_drag_data, p_point, ret);
1915 return ret;
1916}
1917
1918bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
1919 ERR_READ_THREAD_GUARD_V(false);
1920 if (data.forward_can_drop.is_valid()) {
1921 Variant ret;
1922 Variant p = p_point;
1923 const Variant *vp[2] = { &p, &p_data };
1924 Callable::CallError ce;
1925 data.forward_can_drop.callp((const Variant **)vp, 2, ret, ce);
1926 if (ce.error != Callable::CallError::CALL_OK) {
1927 ERR_FAIL_V_MSG(Variant(), "Error calling forwarded method from 'can_drop_data': " + Variant::get_callable_error_text(data.forward_can_drop, (const Variant **)vp, 2, ce) + ".");
1928 }
1929 return ret;
1930 }
1931
1932 bool ret = false;
1933 GDVIRTUAL_CALL(_can_drop_data, p_point, p_data, ret);
1934 return ret;
1935}
1936
1937void Control::drop_data(const Point2 &p_point, const Variant &p_data) {
1938 ERR_READ_THREAD_GUARD;
1939 if (data.forward_drop.is_valid()) {
1940 Variant ret;
1941 Variant p = p_point;
1942 const Variant *vp[2] = { &p, &p_data };
1943 Callable::CallError ce;
1944 data.forward_drop.callp((const Variant **)vp, 2, ret, ce);
1945 if (ce.error != Callable::CallError::CALL_OK) {
1946 ERR_FAIL_MSG("Error calling forwarded method from 'drop_data': " + Variant::get_callable_error_text(data.forward_drop, (const Variant **)vp, 2, ce) + ".");
1947 }
1948 return;
1949 }
1950
1951 GDVIRTUAL_CALL(_drop_data, p_point, p_data);
1952}
1953
1954void Control::force_drag(const Variant &p_data, Control *p_control) {
1955 ERR_MAIN_THREAD_GUARD;
1956 ERR_FAIL_COND(!is_inside_tree());
1957 ERR_FAIL_COND(p_data.get_type() == Variant::NIL);
1958
1959 get_viewport()->_gui_force_drag(this, p_data, p_control);
1960}
1961
1962void Control::set_drag_preview(Control *p_control) {
1963 ERR_MAIN_THREAD_GUARD;
1964 ERR_FAIL_COND(!is_inside_tree());
1965 ERR_FAIL_COND(!get_viewport()->gui_is_dragging());
1966 get_viewport()->_gui_set_drag_preview(this, p_control);
1967}
1968
1969bool Control::is_drag_successful() const {
1970 ERR_READ_THREAD_GUARD_V(false);
1971 return is_inside_tree() && get_viewport()->gui_is_drag_successful();
1972}
1973
1974// Focus.
1975
1976void Control::set_focus_mode(FocusMode p_focus_mode) {
1977 ERR_MAIN_THREAD_GUARD;
1978 ERR_FAIL_INDEX((int)p_focus_mode, 3);
1979
1980 if (is_inside_tree() && p_focus_mode == FOCUS_NONE && data.focus_mode != FOCUS_NONE && has_focus()) {
1981 release_focus();
1982 }
1983
1984 data.focus_mode = p_focus_mode;
1985}
1986
1987Control::FocusMode Control::get_focus_mode() const {
1988 ERR_READ_THREAD_GUARD_V(FOCUS_NONE);
1989 return data.focus_mode;
1990}
1991
1992bool Control::has_focus() const {
1993 ERR_READ_THREAD_GUARD_V(false);
1994 return is_inside_tree() && get_viewport()->_gui_control_has_focus(this);
1995}
1996
1997void Control::grab_focus() {
1998 ERR_MAIN_THREAD_GUARD;
1999 ERR_FAIL_COND(!is_inside_tree());
2000
2001 if (data.focus_mode == FOCUS_NONE) {
2002 WARN_PRINT("This control can't grab focus. Use set_focus_mode() to allow a control to get focus.");
2003 return;
2004 }
2005
2006 get_viewport()->_gui_control_grab_focus(this);
2007}
2008
2009void Control::grab_click_focus() {
2010 ERR_MAIN_THREAD_GUARD;
2011 ERR_FAIL_COND(!is_inside_tree());
2012
2013 get_viewport()->_gui_grab_click_focus(this);
2014}
2015
2016void Control::release_focus() {
2017 ERR_MAIN_THREAD_GUARD;
2018 ERR_FAIL_COND(!is_inside_tree());
2019
2020 if (!has_focus()) {
2021 return;
2022 }
2023
2024 get_viewport()->gui_release_focus();
2025}
2026
2027static Control *_next_control(Control *p_from) {
2028 if (p_from->is_set_as_top_level()) {
2029 return nullptr; // Can't go above.
2030 }
2031
2032 Control *parent = Object::cast_to<Control>(p_from->get_parent());
2033
2034 if (!parent) {
2035 return nullptr;
2036 }
2037
2038 int next = p_from->get_index();
2039 ERR_FAIL_INDEX_V(next, parent->get_child_count(), nullptr);
2040 for (int i = (next + 1); i < parent->get_child_count(); i++) {
2041 Control *c = Object::cast_to<Control>(parent->get_child(i));
2042 if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) {
2043 continue;
2044 }
2045
2046 return c;
2047 }
2048
2049 // No next in parent, try the same in parent.
2050 return _next_control(parent);
2051}
2052
2053Control *Control::find_next_valid_focus() const {
2054 ERR_READ_THREAD_GUARD_V(nullptr);
2055 Control *from = const_cast<Control *>(this);
2056
2057 while (true) {
2058 // If the focus property is manually overwritten, attempt to use it.
2059
2060 if (!data.focus_next.is_empty()) {
2061 Node *n = get_node_or_null(data.focus_next);
2062 ERR_FAIL_NULL_V_MSG(n, nullptr, "Next focus node path is invalid: '" + data.focus_next + "'.");
2063 Control *c = Object::cast_to<Control>(n);
2064 ERR_FAIL_NULL_V_MSG(c, nullptr, "Next focus node is not a control: '" + n->get_name() + "'.");
2065 if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE) {
2066 return c;
2067 }
2068 }
2069
2070 // Find next child.
2071
2072 Control *next_child = nullptr;
2073
2074 for (int i = 0; i < from->get_child_count(); i++) {
2075 Control *c = Object::cast_to<Control>(from->get_child(i));
2076 if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) {
2077 continue;
2078 }
2079
2080 next_child = c;
2081 break;
2082 }
2083
2084 if (!next_child) {
2085 next_child = _next_control(from);
2086 if (!next_child) { // Nothing else. Go up and find either window or subwindow.
2087 next_child = const_cast<Control *>(this);
2088 while (next_child && !next_child->is_set_as_top_level()) {
2089 next_child = cast_to<Control>(next_child->get_parent());
2090 }
2091
2092 if (!next_child) {
2093 next_child = const_cast<Control *>(this);
2094 while (next_child) {
2095 if (next_child->data.RI) {
2096 break;
2097 }
2098 next_child = next_child->get_parent_control();
2099 }
2100 }
2101 }
2102 }
2103
2104 if (next_child == from || next_child == this) { // No next control.
2105 return (get_focus_mode() == FOCUS_ALL) ? next_child : nullptr;
2106 }
2107 if (next_child) {
2108 if (next_child->get_focus_mode() == FOCUS_ALL) {
2109 return next_child;
2110 }
2111 from = next_child;
2112 } else {
2113 break;
2114 }
2115 }
2116
2117 return nullptr;
2118}
2119
2120static Control *_prev_control(Control *p_from) {
2121 Control *child = nullptr;
2122 for (int i = p_from->get_child_count() - 1; i >= 0; i--) {
2123 Control *c = Object::cast_to<Control>(p_from->get_child(i));
2124 if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) {
2125 continue;
2126 }
2127
2128 child = c;
2129 break;
2130 }
2131
2132 if (!child) {
2133 return p_from;
2134 }
2135
2136 // No prev in parent, try the same in parent.
2137 return _prev_control(child);
2138}
2139
2140Control *Control::find_prev_valid_focus() const {
2141 ERR_READ_THREAD_GUARD_V(nullptr);
2142 Control *from = const_cast<Control *>(this);
2143
2144 while (true) {
2145 // If the focus property is manually overwritten, attempt to use it.
2146
2147 if (!data.focus_prev.is_empty()) {
2148 Node *n = get_node_or_null(data.focus_prev);
2149 ERR_FAIL_NULL_V_MSG(n, nullptr, "Previous focus node path is invalid: '" + data.focus_prev + "'.");
2150 Control *c = Object::cast_to<Control>(n);
2151 ERR_FAIL_NULL_V_MSG(c, nullptr, "Previous focus node is not a control: '" + n->get_name() + "'.");
2152 if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE) {
2153 return c;
2154 }
2155 }
2156
2157 // Find prev child.
2158
2159 Control *prev_child = nullptr;
2160
2161 if (from->is_set_as_top_level() || !Object::cast_to<Control>(from->get_parent())) {
2162 // Find last of the children.
2163
2164 prev_child = _prev_control(from);
2165
2166 } else {
2167 for (int i = (from->get_index() - 1); i >= 0; i--) {
2168 Control *c = Object::cast_to<Control>(from->get_parent()->get_child(i));
2169
2170 if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) {
2171 continue;
2172 }
2173
2174 prev_child = c;
2175 break;
2176 }
2177
2178 if (!prev_child) {
2179 prev_child = Object::cast_to<Control>(from->get_parent());
2180 } else {
2181 prev_child = _prev_control(prev_child);
2182 }
2183 }
2184
2185 if (prev_child == from || prev_child == this) { // No prev control.
2186 return (get_focus_mode() == FOCUS_ALL) ? prev_child : nullptr;
2187 }
2188
2189 if (prev_child->get_focus_mode() == FOCUS_ALL) {
2190 return prev_child;
2191 }
2192
2193 from = prev_child;
2194 }
2195
2196 return nullptr;
2197}
2198
2199void Control::set_focus_neighbor(Side p_side, const NodePath &p_neighbor) {
2200 ERR_MAIN_THREAD_GUARD;
2201 ERR_FAIL_INDEX((int)p_side, 4);
2202 data.focus_neighbor[p_side] = p_neighbor;
2203}
2204
2205NodePath Control::get_focus_neighbor(Side p_side) const {
2206 ERR_READ_THREAD_GUARD_V(NodePath());
2207 ERR_FAIL_INDEX_V((int)p_side, 4, NodePath());
2208 return data.focus_neighbor[p_side];
2209}
2210
2211void Control::set_focus_next(const NodePath &p_next) {
2212 ERR_MAIN_THREAD_GUARD;
2213 data.focus_next = p_next;
2214}
2215
2216NodePath Control::get_focus_next() const {
2217 ERR_READ_THREAD_GUARD_V(NodePath());
2218 return data.focus_next;
2219}
2220
2221void Control::set_focus_previous(const NodePath &p_prev) {
2222 ERR_MAIN_THREAD_GUARD;
2223 data.focus_prev = p_prev;
2224}
2225
2226NodePath Control::get_focus_previous() const {
2227 ERR_READ_THREAD_GUARD_V(NodePath());
2228 return data.focus_prev;
2229}
2230
2231#define MAX_NEIGHBOR_SEARCH_COUNT 512
2232
2233Control *Control::_get_focus_neighbor(Side p_side, int p_count) {
2234 ERR_FAIL_INDEX_V((int)p_side, 4, nullptr);
2235
2236 if (p_count >= MAX_NEIGHBOR_SEARCH_COUNT) {
2237 return nullptr;
2238 }
2239 if (!data.focus_neighbor[p_side].is_empty()) {
2240 Node *n = get_node_or_null(data.focus_neighbor[p_side]);
2241 ERR_FAIL_NULL_V_MSG(n, nullptr, "Neighbor focus node path is invalid: '" + data.focus_neighbor[p_side] + "'.");
2242 Control *c = Object::cast_to<Control>(n);
2243 ERR_FAIL_NULL_V_MSG(c, nullptr, "Neighbor focus node is not a control: '" + n->get_name() + "'.");
2244 bool valid = true;
2245 if (!c->is_visible()) {
2246 valid = false;
2247 }
2248 if (c->get_focus_mode() == FOCUS_NONE) {
2249 valid = false;
2250 }
2251 if (valid) {
2252 return c;
2253 }
2254
2255 c = c->_get_focus_neighbor(p_side, p_count + 1);
2256 return c;
2257 }
2258
2259 real_t dist = 1e7;
2260 Control *result = nullptr;
2261
2262 Point2 points[4];
2263
2264 Transform2D xform = get_global_transform();
2265
2266 points[0] = xform.xform(Point2());
2267 points[1] = xform.xform(Point2(get_size().x, 0));
2268 points[2] = xform.xform(get_size());
2269 points[3] = xform.xform(Point2(0, get_size().y));
2270
2271 const Vector2 dir[4] = {
2272 Vector2(-1, 0),
2273 Vector2(0, -1),
2274 Vector2(1, 0),
2275 Vector2(0, 1)
2276 };
2277
2278 Vector2 vdir = dir[p_side];
2279
2280 real_t maxd = -1e7;
2281
2282 for (int i = 0; i < 4; i++) {
2283 real_t d = vdir.dot(points[i]);
2284 if (d > maxd) {
2285 maxd = d;
2286 }
2287 }
2288
2289 Node *base = this;
2290
2291 while (base) {
2292 Control *c = Object::cast_to<Control>(base);
2293 if (c) {
2294 if (c->data.RI) {
2295 break;
2296 }
2297 }
2298 base = base->get_parent();
2299 }
2300
2301 if (!base) {
2302 return nullptr;
2303 }
2304
2305 _window_find_focus_neighbor(vdir, base, points, maxd, dist, &result);
2306
2307 return result;
2308}
2309
2310void Control::_window_find_focus_neighbor(const Vector2 &p_dir, Node *p_at, const Point2 *p_points, real_t p_min, real_t &r_closest_dist, Control **r_closest) {
2311 if (Object::cast_to<Viewport>(p_at)) {
2312 return; //bye
2313 }
2314
2315 Control *c = Object::cast_to<Control>(p_at);
2316
2317 if (c && c != this && c->get_focus_mode() == FOCUS_ALL && c->is_visible_in_tree()) {
2318 Point2 points[4];
2319
2320 Transform2D xform = c->get_global_transform();
2321
2322 points[0] = xform.xform(Point2());
2323 points[1] = xform.xform(Point2(c->get_size().x, 0));
2324 points[2] = xform.xform(c->get_size());
2325 points[3] = xform.xform(Point2(0, c->get_size().y));
2326
2327 real_t min = 1e7;
2328
2329 for (int i = 0; i < 4; i++) {
2330 real_t d = p_dir.dot(points[i]);
2331 if (d < min) {
2332 min = d;
2333 }
2334 }
2335
2336 if (min > (p_min - CMP_EPSILON)) {
2337 for (int i = 0; i < 4; i++) {
2338 Vector2 la = p_points[i];
2339 Vector2 lb = p_points[(i + 1) % 4];
2340
2341 for (int j = 0; j < 4; j++) {
2342 Vector2 fa = points[j];
2343 Vector2 fb = points[(j + 1) % 4];
2344
2345 Vector2 pa, pb;
2346 real_t d = Geometry2D::get_closest_points_between_segments(la, lb, fa, fb, pa, pb);
2347 //real_t d = Geometry2D::get_closest_distance_between_segments(Vector3(la.x,la.y,0),Vector3(lb.x,lb.y,0),Vector3(fa.x,fa.y,0),Vector3(fb.x,fb.y,0));
2348 if (d < r_closest_dist) {
2349 r_closest_dist = d;
2350 *r_closest = c;
2351 }
2352 }
2353 }
2354 }
2355 }
2356
2357 for (int i = 0; i < p_at->get_child_count(); i++) {
2358 Node *child = p_at->get_child(i);
2359 Control *childc = Object::cast_to<Control>(child);
2360 if (childc && childc->data.RI) {
2361 continue; //subwindow, ignore
2362 }
2363 _window_find_focus_neighbor(p_dir, p_at->get_child(i), p_points, p_min, r_closest_dist, r_closest);
2364 }
2365}
2366
2367// Rendering.
2368
2369void Control::set_default_cursor_shape(CursorShape p_shape) {
2370 ERR_MAIN_THREAD_GUARD;
2371 ERR_FAIL_INDEX(int(p_shape), CURSOR_MAX);
2372
2373 if (data.default_cursor == p_shape) {
2374 return;
2375 }
2376 data.default_cursor = p_shape;
2377
2378 if (!is_inside_tree()) {
2379 return;
2380 }
2381 if (!get_global_rect().has_point(get_global_mouse_position())) {
2382 return;
2383 }
2384
2385 // Display the new cursor shape instantly.
2386 get_viewport()->update_mouse_cursor_state();
2387}
2388
2389Control::CursorShape Control::get_default_cursor_shape() const {
2390 ERR_READ_THREAD_GUARD_V(CURSOR_ARROW);
2391 return data.default_cursor;
2392}
2393
2394Control::CursorShape Control::get_cursor_shape(const Point2 &p_pos) const {
2395 ERR_READ_THREAD_GUARD_V(CURSOR_ARROW);
2396 return data.default_cursor;
2397}
2398
2399void Control::set_disable_visibility_clip(bool p_ignore) {
2400 ERR_MAIN_THREAD_GUARD;
2401 if (data.disable_visibility_clip == p_ignore) {
2402 return;
2403 }
2404 data.disable_visibility_clip = p_ignore;
2405 queue_redraw();
2406}
2407
2408bool Control::is_visibility_clip_disabled() const {
2409 ERR_READ_THREAD_GUARD_V(false);
2410 return data.disable_visibility_clip;
2411}
2412
2413void Control::set_clip_contents(bool p_clip) {
2414 ERR_MAIN_THREAD_GUARD;
2415 if (data.clip_contents == p_clip) {
2416 return;
2417 }
2418 data.clip_contents = p_clip;
2419 queue_redraw();
2420}
2421
2422bool Control::is_clipping_contents() {
2423 ERR_READ_THREAD_GUARD_V(false);
2424 return data.clip_contents;
2425}
2426
2427// Theming.
2428
2429void Control::_theme_changed() {
2430 if (is_inside_tree()) {
2431 data.theme_owner->propagate_theme_changed(this, this, true, false);
2432 }
2433}
2434
2435void Control::_notify_theme_override_changed() {
2436 if (!data.bulk_theme_override && is_inside_tree()) {
2437 notification(NOTIFICATION_THEME_CHANGED);
2438 }
2439}
2440
2441void Control::_invalidate_theme_cache() {
2442 data.theme_icon_cache.clear();
2443 data.theme_style_cache.clear();
2444 data.theme_font_cache.clear();
2445 data.theme_font_size_cache.clear();
2446 data.theme_color_cache.clear();
2447 data.theme_constant_cache.clear();
2448}
2449
2450void Control::_update_theme_item_cache() {
2451 ThemeDB::get_singleton()->update_class_instance_items(this);
2452}
2453
2454void Control::set_theme_owner_node(Node *p_node) {
2455 ERR_MAIN_THREAD_GUARD;
2456 data.theme_owner->set_owner_node(p_node);
2457}
2458
2459Node *Control::get_theme_owner_node() const {
2460 ERR_READ_THREAD_GUARD_V(nullptr);
2461 return data.theme_owner->get_owner_node();
2462}
2463
2464bool Control::has_theme_owner_node() const {
2465 ERR_READ_THREAD_GUARD_V(false);
2466 return data.theme_owner->has_owner_node();
2467}
2468
2469void Control::set_theme_context(ThemeContext *p_context, bool p_propagate) {
2470 ERR_MAIN_THREAD_GUARD;
2471 data.theme_owner->set_owner_context(p_context, p_propagate);
2472}
2473
2474void Control::set_theme(const Ref<Theme> &p_theme) {
2475 ERR_MAIN_THREAD_GUARD;
2476 if (data.theme == p_theme) {
2477 return;
2478 }
2479
2480 if (data.theme.is_valid()) {
2481 data.theme->disconnect_changed(callable_mp(this, &Control::_theme_changed));
2482 }
2483
2484 data.theme = p_theme;
2485 if (data.theme.is_valid()) {
2486 data.theme_owner->propagate_theme_changed(this, this, is_inside_tree(), true);
2487 data.theme->connect_changed(callable_mp(this, &Control::_theme_changed), CONNECT_DEFERRED);
2488 return;
2489 }
2490
2491 Control *parent_c = Object::cast_to<Control>(get_parent());
2492 if (parent_c && parent_c->has_theme_owner_node()) {
2493 data.theme_owner->propagate_theme_changed(this, parent_c->get_theme_owner_node(), is_inside_tree(), true);
2494 return;
2495 }
2496
2497 Window *parent_w = cast_to<Window>(get_parent());
2498 if (parent_w && parent_w->has_theme_owner_node()) {
2499 data.theme_owner->propagate_theme_changed(this, parent_w->get_theme_owner_node(), is_inside_tree(), true);
2500 return;
2501 }
2502
2503 data.theme_owner->propagate_theme_changed(this, nullptr, is_inside_tree(), true);
2504}
2505
2506Ref<Theme> Control::get_theme() const {
2507 ERR_READ_THREAD_GUARD_V(Ref<Theme>());
2508 return data.theme;
2509}
2510
2511void Control::set_theme_type_variation(const StringName &p_theme_type) {
2512 ERR_MAIN_THREAD_GUARD;
2513 if (data.theme_type_variation == p_theme_type) {
2514 return;
2515 }
2516 data.theme_type_variation = p_theme_type;
2517 if (is_inside_tree()) {
2518 notification(NOTIFICATION_THEME_CHANGED);
2519 }
2520}
2521
2522StringName Control::get_theme_type_variation() const {
2523 ERR_READ_THREAD_GUARD_V(StringName());
2524 return data.theme_type_variation;
2525}
2526
2527/// Theme property lookup.
2528
2529Ref<Texture2D> Control::get_theme_icon(const StringName &p_name, const StringName &p_theme_type) const {
2530 ERR_READ_THREAD_GUARD_V(Ref<Texture2D>());
2531 if (!data.initialized) {
2532 WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED");
2533 }
2534
2535 if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
2536 const Ref<Texture2D> *tex = data.theme_icon_override.getptr(p_name);
2537 if (tex) {
2538 return *tex;
2539 }
2540 }
2541
2542 if (data.theme_icon_cache.has(p_theme_type) && data.theme_icon_cache[p_theme_type].has(p_name)) {
2543 return data.theme_icon_cache[p_theme_type][p_name];
2544 }
2545
2546 List<StringName> theme_types;
2547 data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2548 Ref<Texture2D> icon = data.theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_ICON, p_name, theme_types);
2549 data.theme_icon_cache[p_theme_type][p_name] = icon;
2550 return icon;
2551}
2552
2553Ref<StyleBox> Control::get_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const {
2554 ERR_READ_THREAD_GUARD_V(Ref<StyleBox>());
2555 if (!data.initialized) {
2556 WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED");
2557 }
2558
2559 if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
2560 const Ref<StyleBox> *style = data.theme_style_override.getptr(p_name);
2561 if (style) {
2562 return *style;
2563 }
2564 }
2565
2566 if (data.theme_style_cache.has(p_theme_type) && data.theme_style_cache[p_theme_type].has(p_name)) {
2567 return data.theme_style_cache[p_theme_type][p_name];
2568 }
2569
2570 List<StringName> theme_types;
2571 data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2572 Ref<StyleBox> style = data.theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_STYLEBOX, p_name, theme_types);
2573 data.theme_style_cache[p_theme_type][p_name] = style;
2574 return style;
2575}
2576
2577Ref<Font> Control::get_theme_font(const StringName &p_name, const StringName &p_theme_type) const {
2578 ERR_READ_THREAD_GUARD_V(Ref<Font>());
2579 if (!data.initialized) {
2580 WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED");
2581 }
2582
2583 if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
2584 const Ref<Font> *font = data.theme_font_override.getptr(p_name);
2585 if (font) {
2586 return *font;
2587 }
2588 }
2589
2590 if (data.theme_font_cache.has(p_theme_type) && data.theme_font_cache[p_theme_type].has(p_name)) {
2591 return data.theme_font_cache[p_theme_type][p_name];
2592 }
2593
2594 List<StringName> theme_types;
2595 data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2596 Ref<Font> font = data.theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_FONT, p_name, theme_types);
2597 data.theme_font_cache[p_theme_type][p_name] = font;
2598 return font;
2599}
2600
2601int Control::get_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const {
2602 ERR_READ_THREAD_GUARD_V(0);
2603 if (!data.initialized) {
2604 WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED");
2605 }
2606
2607 if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
2608 const int *font_size = data.theme_font_size_override.getptr(p_name);
2609 if (font_size && (*font_size) > 0) {
2610 return *font_size;
2611 }
2612 }
2613
2614 if (data.theme_font_size_cache.has(p_theme_type) && data.theme_font_size_cache[p_theme_type].has(p_name)) {
2615 return data.theme_font_size_cache[p_theme_type][p_name];
2616 }
2617
2618 List<StringName> theme_types;
2619 data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2620 int font_size = data.theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_FONT_SIZE, p_name, theme_types);
2621 data.theme_font_size_cache[p_theme_type][p_name] = font_size;
2622 return font_size;
2623}
2624
2625Color Control::get_theme_color(const StringName &p_name, const StringName &p_theme_type) const {
2626 ERR_READ_THREAD_GUARD_V(Color());
2627 if (!data.initialized) {
2628 WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED");
2629 }
2630
2631 if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
2632 const Color *color = data.theme_color_override.getptr(p_name);
2633 if (color) {
2634 return *color;
2635 }
2636 }
2637
2638 if (data.theme_color_cache.has(p_theme_type) && data.theme_color_cache[p_theme_type].has(p_name)) {
2639 return data.theme_color_cache[p_theme_type][p_name];
2640 }
2641
2642 List<StringName> theme_types;
2643 data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2644 Color color = data.theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_COLOR, p_name, theme_types);
2645 data.theme_color_cache[p_theme_type][p_name] = color;
2646 return color;
2647}
2648
2649int Control::get_theme_constant(const StringName &p_name, const StringName &p_theme_type) const {
2650 ERR_READ_THREAD_GUARD_V(0);
2651 if (!data.initialized) {
2652 WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED");
2653 }
2654
2655 if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
2656 const int *constant = data.theme_constant_override.getptr(p_name);
2657 if (constant) {
2658 return *constant;
2659 }
2660 }
2661
2662 if (data.theme_constant_cache.has(p_theme_type) && data.theme_constant_cache[p_theme_type].has(p_name)) {
2663 return data.theme_constant_cache[p_theme_type][p_name];
2664 }
2665
2666 List<StringName> theme_types;
2667 data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2668 int constant = data.theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_CONSTANT, p_name, theme_types);
2669 data.theme_constant_cache[p_theme_type][p_name] = constant;
2670 return constant;
2671}
2672
2673Variant Control::get_theme_item(Theme::DataType p_data_type, const StringName &p_name, const StringName &p_theme_type) const {
2674 switch (p_data_type) {
2675 case Theme::DATA_TYPE_COLOR:
2676 return get_theme_color(p_name, p_theme_type);
2677 case Theme::DATA_TYPE_CONSTANT:
2678 return get_theme_constant(p_name, p_theme_type);
2679 case Theme::DATA_TYPE_FONT:
2680 return get_theme_font(p_name, p_theme_type);
2681 case Theme::DATA_TYPE_FONT_SIZE:
2682 return get_theme_font_size(p_name, p_theme_type);
2683 case Theme::DATA_TYPE_ICON:
2684 return get_theme_icon(p_name, p_theme_type);
2685 case Theme::DATA_TYPE_STYLEBOX:
2686 return get_theme_stylebox(p_name, p_theme_type);
2687 case Theme::DATA_TYPE_MAX:
2688 break; // Can't happen, but silences warning.
2689 }
2690
2691 return Variant();
2692}
2693
2694#ifdef TOOLS_ENABLED
2695Ref<Texture2D> Control::get_editor_theme_icon(const StringName &p_name) const {
2696 return get_theme_icon(p_name, SNAME("EditorIcons"));
2697}
2698#endif
2699
2700bool Control::has_theme_icon(const StringName &p_name, const StringName &p_theme_type) const {
2701 ERR_READ_THREAD_GUARD_V(false);
2702 if (!data.initialized) {
2703 WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED");
2704 }
2705
2706 if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
2707 if (has_theme_icon_override(p_name)) {
2708 return true;
2709 }
2710 }
2711
2712 List<StringName> theme_types;
2713 data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2714 return data.theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_ICON, p_name, theme_types);
2715}
2716
2717bool Control::has_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const {
2718 ERR_READ_THREAD_GUARD_V(false);
2719 if (!data.initialized) {
2720 WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED");
2721 }
2722
2723 if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
2724 if (has_theme_stylebox_override(p_name)) {
2725 return true;
2726 }
2727 }
2728
2729 List<StringName> theme_types;
2730 data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2731 return data.theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_STYLEBOX, p_name, theme_types);
2732}
2733
2734bool Control::has_theme_font(const StringName &p_name, const StringName &p_theme_type) const {
2735 ERR_READ_THREAD_GUARD_V(false);
2736 if (!data.initialized) {
2737 WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED");
2738 }
2739
2740 if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
2741 if (has_theme_font_override(p_name)) {
2742 return true;
2743 }
2744 }
2745
2746 List<StringName> theme_types;
2747 data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2748 return data.theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_FONT, p_name, theme_types);
2749}
2750
2751bool Control::has_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const {
2752 ERR_READ_THREAD_GUARD_V(false);
2753 if (!data.initialized) {
2754 WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED");
2755 }
2756
2757 if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
2758 if (has_theme_font_size_override(p_name)) {
2759 return true;
2760 }
2761 }
2762
2763 List<StringName> theme_types;
2764 data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2765 return data.theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_FONT_SIZE, p_name, theme_types);
2766}
2767
2768bool Control::has_theme_color(const StringName &p_name, const StringName &p_theme_type) const {
2769 ERR_READ_THREAD_GUARD_V(false);
2770 if (!data.initialized) {
2771 WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED");
2772 }
2773
2774 if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
2775 if (has_theme_color_override(p_name)) {
2776 return true;
2777 }
2778 }
2779
2780 List<StringName> theme_types;
2781 data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2782 return data.theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_COLOR, p_name, theme_types);
2783}
2784
2785bool Control::has_theme_constant(const StringName &p_name, const StringName &p_theme_type) const {
2786 ERR_READ_THREAD_GUARD_V(false);
2787 if (!data.initialized) {
2788 WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED");
2789 }
2790
2791 if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) {
2792 if (has_theme_constant_override(p_name)) {
2793 return true;
2794 }
2795 }
2796
2797 List<StringName> theme_types;
2798 data.theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
2799 return data.theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_CONSTANT, p_name, theme_types);
2800}
2801
2802/// Local property overrides.
2803
2804void Control::add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon) {
2805 ERR_MAIN_THREAD_GUARD;
2806 ERR_FAIL_COND(!p_icon.is_valid());
2807
2808 if (data.theme_icon_override.has(p_name)) {
2809 data.theme_icon_override[p_name]->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed));
2810 }
2811
2812 data.theme_icon_override[p_name] = p_icon;
2813 data.theme_icon_override[p_name]->connect_changed(callable_mp(this, &Control::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED);
2814 _notify_theme_override_changed();
2815}
2816
2817void Control::add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) {
2818 ERR_MAIN_THREAD_GUARD;
2819 ERR_FAIL_COND(!p_style.is_valid());
2820
2821 if (data.theme_style_override.has(p_name)) {
2822 data.theme_style_override[p_name]->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed));
2823 }
2824
2825 data.theme_style_override[p_name] = p_style;
2826 data.theme_style_override[p_name]->connect_changed(callable_mp(this, &Control::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED);
2827 _notify_theme_override_changed();
2828}
2829
2830void Control::add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font) {
2831 ERR_MAIN_THREAD_GUARD;
2832 ERR_FAIL_COND(!p_font.is_valid());
2833
2834 if (data.theme_font_override.has(p_name)) {
2835 data.theme_font_override[p_name]->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed));
2836 }
2837
2838 data.theme_font_override[p_name] = p_font;
2839 data.theme_font_override[p_name]->connect_changed(callable_mp(this, &Control::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED);
2840 _notify_theme_override_changed();
2841}
2842
2843void Control::add_theme_font_size_override(const StringName &p_name, int p_font_size) {
2844 ERR_MAIN_THREAD_GUARD;
2845 data.theme_font_size_override[p_name] = p_font_size;
2846 _notify_theme_override_changed();
2847}
2848
2849void Control::add_theme_color_override(const StringName &p_name, const Color &p_color) {
2850 ERR_MAIN_THREAD_GUARD;
2851 data.theme_color_override[p_name] = p_color;
2852 _notify_theme_override_changed();
2853}
2854
2855void Control::add_theme_constant_override(const StringName &p_name, int p_constant) {
2856 ERR_MAIN_THREAD_GUARD;
2857 data.theme_constant_override[p_name] = p_constant;
2858 _notify_theme_override_changed();
2859}
2860
2861void Control::remove_theme_icon_override(const StringName &p_name) {
2862 ERR_MAIN_THREAD_GUARD;
2863 if (data.theme_icon_override.has(p_name)) {
2864 data.theme_icon_override[p_name]->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed));
2865 }
2866
2867 data.theme_icon_override.erase(p_name);
2868 _notify_theme_override_changed();
2869}
2870
2871void Control::remove_theme_style_override(const StringName &p_name) {
2872 ERR_MAIN_THREAD_GUARD;
2873 if (data.theme_style_override.has(p_name)) {
2874 data.theme_style_override[p_name]->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed));
2875 }
2876
2877 data.theme_style_override.erase(p_name);
2878 _notify_theme_override_changed();
2879}
2880
2881void Control::remove_theme_font_override(const StringName &p_name) {
2882 ERR_MAIN_THREAD_GUARD;
2883 if (data.theme_font_override.has(p_name)) {
2884 data.theme_font_override[p_name]->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed));
2885 }
2886
2887 data.theme_font_override.erase(p_name);
2888 _notify_theme_override_changed();
2889}
2890
2891void Control::remove_theme_font_size_override(const StringName &p_name) {
2892 ERR_MAIN_THREAD_GUARD;
2893 data.theme_font_size_override.erase(p_name);
2894 _notify_theme_override_changed();
2895}
2896
2897void Control::remove_theme_color_override(const StringName &p_name) {
2898 ERR_MAIN_THREAD_GUARD;
2899 data.theme_color_override.erase(p_name);
2900 _notify_theme_override_changed();
2901}
2902
2903void Control::remove_theme_constant_override(const StringName &p_name) {
2904 ERR_MAIN_THREAD_GUARD;
2905 data.theme_constant_override.erase(p_name);
2906 _notify_theme_override_changed();
2907}
2908
2909bool Control::has_theme_icon_override(const StringName &p_name) const {
2910 ERR_READ_THREAD_GUARD_V(false);
2911 const Ref<Texture2D> *tex = data.theme_icon_override.getptr(p_name);
2912 return tex != nullptr;
2913}
2914
2915bool Control::has_theme_stylebox_override(const StringName &p_name) const {
2916 ERR_READ_THREAD_GUARD_V(false);
2917 const Ref<StyleBox> *style = data.theme_style_override.getptr(p_name);
2918 return style != nullptr;
2919}
2920
2921bool Control::has_theme_font_override(const StringName &p_name) const {
2922 ERR_READ_THREAD_GUARD_V(false);
2923 const Ref<Font> *font = data.theme_font_override.getptr(p_name);
2924 return font != nullptr;
2925}
2926
2927bool Control::has_theme_font_size_override(const StringName &p_name) const {
2928 ERR_READ_THREAD_GUARD_V(false);
2929 const int *font_size = data.theme_font_size_override.getptr(p_name);
2930 return font_size != nullptr;
2931}
2932
2933bool Control::has_theme_color_override(const StringName &p_name) const {
2934 ERR_READ_THREAD_GUARD_V(false);
2935 const Color *color = data.theme_color_override.getptr(p_name);
2936 return color != nullptr;
2937}
2938
2939bool Control::has_theme_constant_override(const StringName &p_name) const {
2940 ERR_READ_THREAD_GUARD_V(false);
2941 const int *constant = data.theme_constant_override.getptr(p_name);
2942 return constant != nullptr;
2943}
2944
2945/// Default theme properties.
2946
2947float Control::get_theme_default_base_scale() const {
2948 ERR_READ_THREAD_GUARD_V(0);
2949 return data.theme_owner->get_theme_default_base_scale();
2950}
2951
2952Ref<Font> Control::get_theme_default_font() const {
2953 ERR_READ_THREAD_GUARD_V(Ref<Font>());
2954 return data.theme_owner->get_theme_default_font();
2955}
2956
2957int Control::get_theme_default_font_size() const {
2958 ERR_READ_THREAD_GUARD_V(0);
2959 return data.theme_owner->get_theme_default_font_size();
2960}
2961
2962/// Bulk actions.
2963
2964void Control::begin_bulk_theme_override() {
2965 ERR_MAIN_THREAD_GUARD;
2966 data.bulk_theme_override = true;
2967}
2968
2969void Control::end_bulk_theme_override() {
2970 ERR_MAIN_THREAD_GUARD;
2971 ERR_FAIL_COND(!data.bulk_theme_override);
2972
2973 data.bulk_theme_override = false;
2974 _notify_theme_override_changed();
2975}
2976
2977// Internationalization.
2978
2979TypedArray<Vector3i> Control::structured_text_parser(TextServer::StructuredTextParser p_parser_type, const Array &p_args, const String &p_text) const {
2980 ERR_READ_THREAD_GUARD_V(TypedArray<Vector3i>());
2981 if (p_parser_type == TextServer::STRUCTURED_TEXT_CUSTOM) {
2982 TypedArray<Vector3i> ret;
2983 GDVIRTUAL_CALL(_structured_text_parser, p_args, p_text, ret);
2984 return ret;
2985 } else {
2986 return TS->parse_structured_text(p_parser_type, p_args, p_text);
2987 }
2988}
2989
2990void Control::set_layout_direction(Control::LayoutDirection p_direction) {
2991 ERR_MAIN_THREAD_GUARD;
2992 if (data.layout_dir == p_direction) {
2993 return;
2994 }
2995 ERR_FAIL_INDEX((int)p_direction, 4);
2996
2997 data.layout_dir = p_direction;
2998 data.is_rtl_dirty = true;
2999
3000 propagate_notification(NOTIFICATION_LAYOUT_DIRECTION_CHANGED);
3001}
3002
3003Control::LayoutDirection Control::get_layout_direction() const {
3004 ERR_READ_THREAD_GUARD_V(LAYOUT_DIRECTION_INHERITED);
3005 return data.layout_dir;
3006}
3007
3008bool Control::is_layout_rtl() const {
3009 ERR_READ_THREAD_GUARD_V(false);
3010 if (data.is_rtl_dirty) {
3011 const_cast<Control *>(this)->data.is_rtl_dirty = false;
3012 if (data.layout_dir == LAYOUT_DIRECTION_INHERITED) {
3013 if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) {
3014 const_cast<Control *>(this)->data.is_rtl = true;
3015 return data.is_rtl;
3016 }
3017 Node *parent_node = get_parent();
3018 while (parent_node) {
3019 Control *parent_control = Object::cast_to<Control>(parent_node);
3020 if (parent_control) {
3021 const_cast<Control *>(this)->data.is_rtl = parent_control->is_layout_rtl();
3022 return data.is_rtl;
3023 }
3024
3025 Window *parent_window = Object::cast_to<Window>(parent_node);
3026 if (parent_window) {
3027 const_cast<Control *>(this)->data.is_rtl = parent_window->is_layout_rtl();
3028 return data.is_rtl;
3029 }
3030 parent_node = parent_node->get_parent();
3031 }
3032
3033 int root_dir = GLOBAL_GET(SNAME("internationalization/rendering/root_node_layout_direction"));
3034 if (root_dir == 1) {
3035 const_cast<Control *>(this)->data.is_rtl = false;
3036 } else if (root_dir == 2) {
3037 const_cast<Control *>(this)->data.is_rtl = true;
3038 } else {
3039 String locale = TranslationServer::get_singleton()->get_tool_locale();
3040 const_cast<Control *>(this)->data.is_rtl = TS->is_locale_right_to_left(locale);
3041 }
3042 } else if (data.layout_dir == LAYOUT_DIRECTION_LOCALE) {
3043 if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) {
3044 const_cast<Control *>(this)->data.is_rtl = true;
3045 } else {
3046 String locale = TranslationServer::get_singleton()->get_tool_locale();
3047 const_cast<Control *>(this)->data.is_rtl = TS->is_locale_right_to_left(locale);
3048 }
3049 } else {
3050 const_cast<Control *>(this)->data.is_rtl = (data.layout_dir == LAYOUT_DIRECTION_RTL);
3051 }
3052 }
3053 return data.is_rtl;
3054}
3055
3056void Control::set_localize_numeral_system(bool p_enable) {
3057 ERR_MAIN_THREAD_GUARD;
3058 if (p_enable == data.localize_numeral_system) {
3059 return;
3060 }
3061
3062 data.localize_numeral_system = p_enable;
3063
3064 notification(MainLoop::NOTIFICATION_TRANSLATION_CHANGED);
3065}
3066
3067bool Control::is_localizing_numeral_system() const {
3068 ERR_READ_THREAD_GUARD_V(false);
3069 return data.localize_numeral_system;
3070}
3071
3072void Control::set_auto_translate(bool p_enable) {
3073 ERR_MAIN_THREAD_GUARD;
3074 if (p_enable == data.auto_translate) {
3075 return;
3076 }
3077
3078 data.auto_translate = p_enable;
3079
3080 notification(MainLoop::NOTIFICATION_TRANSLATION_CHANGED);
3081}
3082
3083bool Control::is_auto_translating() const {
3084 ERR_READ_THREAD_GUARD_V(false);
3085 return data.auto_translate;
3086}
3087
3088// Extra properties.
3089
3090void Control::set_tooltip_text(const String &p_hint) {
3091 ERR_MAIN_THREAD_GUARD;
3092 data.tooltip = p_hint;
3093 update_configuration_warnings();
3094}
3095
3096String Control::get_tooltip_text() const {
3097 ERR_READ_THREAD_GUARD_V(String());
3098 return data.tooltip;
3099}
3100
3101String Control::get_tooltip(const Point2 &p_pos) const {
3102 ERR_READ_THREAD_GUARD_V(String());
3103 String ret;
3104 if (GDVIRTUAL_CALL(_get_tooltip, p_pos, ret)) {
3105 return ret;
3106 }
3107 return data.tooltip;
3108}
3109
3110Control *Control::make_custom_tooltip(const String &p_text) const {
3111 ERR_READ_THREAD_GUARD_V(nullptr);
3112 Object *ret = nullptr;
3113 GDVIRTUAL_CALL(_make_custom_tooltip, p_text, ret);
3114 return Object::cast_to<Control>(ret);
3115}
3116
3117// Base object overrides.
3118
3119void Control::_notification(int p_notification) {
3120 ERR_MAIN_THREAD_GUARD;
3121 switch (p_notification) {
3122 case NOTIFICATION_POSTINITIALIZE: {
3123 data.initialized = true;
3124
3125 _invalidate_theme_cache();
3126 _update_theme_item_cache();
3127 } break;
3128
3129 case NOTIFICATION_PARENTED: {
3130 Node *parent_node = get_parent();
3131 data.parent_control = Object::cast_to<Control>(parent_node);
3132 data.parent_window = Object::cast_to<Window>(parent_node);
3133
3134 data.theme_owner->assign_theme_on_parented(this);
3135
3136 _update_layout_mode();
3137 } break;
3138
3139 case NOTIFICATION_UNPARENTED: {
3140 data.parent_control = nullptr;
3141 data.parent_window = nullptr;
3142
3143 data.theme_owner->clear_theme_on_unparented(this);
3144 } break;
3145
3146 case NOTIFICATION_ENTER_TREE: {
3147#ifdef TOOLS_ENABLED
3148 if (is_part_of_edited_scene()) {
3149 // Don't translate Controls on scene when inside editor.
3150 set_message_translation(false);
3151 notification(NOTIFICATION_TRANSLATION_CHANGED);
3152 }
3153#endif
3154
3155 // Emits NOTIFICATION_THEME_CHANGED internally.
3156 set_theme_context(ThemeDB::get_singleton()->get_nearest_theme_context(this));
3157 } break;
3158
3159 case NOTIFICATION_POST_ENTER_TREE: {
3160 data.is_rtl_dirty = true;
3161 update_minimum_size();
3162 _size_changed();
3163 } break;
3164
3165 case NOTIFICATION_EXIT_TREE: {
3166 set_theme_context(nullptr, false);
3167 release_focus();
3168 get_viewport()->_gui_remove_control(this);
3169 } break;
3170
3171 case NOTIFICATION_READY: {
3172#ifdef DEBUG_ENABLED
3173 connect("ready", callable_mp(this, &Control::_clear_size_warning), CONNECT_DEFERRED | CONNECT_ONE_SHOT);
3174#endif
3175 } break;
3176
3177 case NOTIFICATION_ENTER_CANVAS: {
3178 data.is_rtl_dirty = true;
3179
3180 CanvasItem *node = this;
3181 bool has_parent_control = false;
3182
3183 while (!node->is_set_as_top_level()) {
3184 CanvasItem *parent = Object::cast_to<CanvasItem>(node->get_parent());
3185 if (!parent) {
3186 break;
3187 }
3188
3189 Control *parent_control = Object::cast_to<Control>(parent);
3190 if (parent_control) {
3191 has_parent_control = true;
3192 break;
3193 }
3194
3195 node = parent;
3196 }
3197
3198 if (has_parent_control) {
3199 // Do nothing, has a parent control.
3200 } else {
3201 // Is a regular root control or top_level.
3202 Viewport *viewport = get_viewport();
3203 ERR_FAIL_NULL(viewport);
3204 data.RI = viewport->_gui_add_root_control(this);
3205
3206 get_parent()->connect(SNAME("child_order_changed"), callable_mp(get_viewport(), &Viewport::gui_set_root_order_dirty), CONNECT_REFERENCE_COUNTED);
3207 }
3208
3209 data.parent_canvas_item = get_parent_item();
3210
3211 if (data.parent_canvas_item) {
3212 data.parent_canvas_item->connect("item_rect_changed", callable_mp(this, &Control::_size_changed));
3213 } else {
3214 // Connect viewport.
3215 Viewport *viewport = get_viewport();
3216 ERR_FAIL_NULL(viewport);
3217 viewport->connect("size_changed", callable_mp(this, &Control::_size_changed));
3218 }
3219 } break;
3220
3221 case NOTIFICATION_EXIT_CANVAS: {
3222 if (data.parent_canvas_item) {
3223 data.parent_canvas_item->disconnect("item_rect_changed", callable_mp(this, &Control::_size_changed));
3224 data.parent_canvas_item = nullptr;
3225 } else {
3226 // Disconnect viewport.
3227 Viewport *viewport = get_viewport();
3228 ERR_FAIL_NULL(viewport);
3229 viewport->disconnect("size_changed", callable_mp(this, &Control::_size_changed));
3230 }
3231
3232 if (data.RI) {
3233 get_viewport()->_gui_remove_root_control(data.RI);
3234 data.RI = nullptr;
3235 get_parent()->disconnect(SNAME("child_order_changed"), callable_mp(get_viewport(), &Viewport::gui_set_root_order_dirty));
3236 }
3237
3238 data.parent_canvas_item = nullptr;
3239 data.is_rtl_dirty = true;
3240 } break;
3241
3242 case NOTIFICATION_CHILD_ORDER_CHANGED: {
3243 // Some parents need to know the order of the children to draw (like TabContainer),
3244 // so we update them just in case.
3245 queue_redraw();
3246 } break;
3247
3248 case NOTIFICATION_RESIZED: {
3249 emit_signal(SceneStringNames::get_singleton()->resized);
3250 } break;
3251
3252 case NOTIFICATION_DRAW: {
3253 _update_canvas_item_transform();
3254 RenderingServer::get_singleton()->canvas_item_set_custom_rect(get_canvas_item(), !data.disable_visibility_clip, Rect2(Point2(), get_size()));
3255 RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), data.clip_contents);
3256 } break;
3257
3258 case NOTIFICATION_MOUSE_ENTER: {
3259 emit_signal(SceneStringNames::get_singleton()->mouse_entered);
3260 } break;
3261
3262 case NOTIFICATION_MOUSE_EXIT: {
3263 emit_signal(SceneStringNames::get_singleton()->mouse_exited);
3264 } break;
3265
3266 case NOTIFICATION_FOCUS_ENTER: {
3267 emit_signal(SceneStringNames::get_singleton()->focus_entered);
3268 queue_redraw();
3269 } break;
3270
3271 case NOTIFICATION_FOCUS_EXIT: {
3272 emit_signal(SceneStringNames::get_singleton()->focus_exited);
3273 queue_redraw();
3274 } break;
3275
3276 case NOTIFICATION_THEME_CHANGED: {
3277 emit_signal(SceneStringNames::get_singleton()->theme_changed);
3278
3279 _invalidate_theme_cache();
3280 _update_theme_item_cache();
3281 queue_redraw();
3282
3283 update_minimum_size();
3284 _size_changed();
3285 } break;
3286
3287 case NOTIFICATION_VISIBILITY_CHANGED: {
3288 if (!is_visible_in_tree()) {
3289 if (get_viewport() != nullptr) {
3290 get_viewport()->_gui_hide_control(this);
3291 }
3292 } else {
3293 update_minimum_size();
3294 _size_changed();
3295 }
3296 } break;
3297
3298 case NOTIFICATION_TRANSLATION_CHANGED:
3299 case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
3300 if (is_inside_tree()) {
3301 data.is_rtl_dirty = true;
3302
3303 _invalidate_theme_cache();
3304 _update_theme_item_cache();
3305 queue_redraw();
3306
3307 update_minimum_size();
3308 _size_changed();
3309 }
3310 } break;
3311 }
3312}
3313
3314void Control::_bind_methods() {
3315 ClassDB::bind_method(D_METHOD("accept_event"), &Control::accept_event);
3316 ClassDB::bind_method(D_METHOD("get_minimum_size"), &Control::get_minimum_size);
3317 ClassDB::bind_method(D_METHOD("get_combined_minimum_size"), &Control::get_combined_minimum_size);
3318
3319 ClassDB::bind_method(D_METHOD("_set_layout_mode", "mode"), &Control::_set_layout_mode);
3320 ClassDB::bind_method(D_METHOD("_get_layout_mode"), &Control::_get_layout_mode);
3321 ClassDB::bind_method(D_METHOD("_set_anchors_layout_preset", "preset"), &Control::_set_anchors_layout_preset);
3322 ClassDB::bind_method(D_METHOD("_get_anchors_layout_preset"), &Control::_get_anchors_layout_preset);
3323 ClassDB::bind_method(D_METHOD("set_anchors_preset", "preset", "keep_offsets"), &Control::set_anchors_preset, DEFVAL(false));
3324 ClassDB::bind_method(D_METHOD("set_offsets_preset", "preset", "resize_mode", "margin"), &Control::set_offsets_preset, DEFVAL(PRESET_MODE_MINSIZE), DEFVAL(0));
3325 ClassDB::bind_method(D_METHOD("set_anchors_and_offsets_preset", "preset", "resize_mode", "margin"), &Control::set_anchors_and_offsets_preset, DEFVAL(PRESET_MODE_MINSIZE), DEFVAL(0));
3326
3327 ClassDB::bind_method(D_METHOD("_set_anchor", "side", "anchor"), &Control::_set_anchor);
3328 ClassDB::bind_method(D_METHOD("set_anchor", "side", "anchor", "keep_offset", "push_opposite_anchor"), &Control::set_anchor, DEFVAL(false), DEFVAL(true));
3329 ClassDB::bind_method(D_METHOD("get_anchor", "side"), &Control::get_anchor);
3330 ClassDB::bind_method(D_METHOD("set_offset", "side", "offset"), &Control::set_offset);
3331 ClassDB::bind_method(D_METHOD("get_offset", "offset"), &Control::get_offset);
3332 ClassDB::bind_method(D_METHOD("set_anchor_and_offset", "side", "anchor", "offset", "push_opposite_anchor"), &Control::set_anchor_and_offset, DEFVAL(false));
3333
3334 ClassDB::bind_method(D_METHOD("set_begin", "position"), &Control::set_begin);
3335 ClassDB::bind_method(D_METHOD("set_end", "position"), &Control::set_end);
3336 ClassDB::bind_method(D_METHOD("set_position", "position", "keep_offsets"), &Control::set_position, DEFVAL(false));
3337 ClassDB::bind_method(D_METHOD("_set_position", "position"), &Control::_set_position);
3338 ClassDB::bind_method(D_METHOD("set_size", "size", "keep_offsets"), &Control::set_size, DEFVAL(false));
3339 ClassDB::bind_method(D_METHOD("reset_size"), &Control::reset_size);
3340 ClassDB::bind_method(D_METHOD("_set_size", "size"), &Control::_set_size);
3341 ClassDB::bind_method(D_METHOD("set_custom_minimum_size", "size"), &Control::set_custom_minimum_size);
3342 ClassDB::bind_method(D_METHOD("set_global_position", "position", "keep_offsets"), &Control::set_global_position, DEFVAL(false));
3343 ClassDB::bind_method(D_METHOD("_set_global_position", "position"), &Control::_set_global_position);
3344 ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &Control::set_rotation);
3345 ClassDB::bind_method(D_METHOD("set_rotation_degrees", "degrees"), &Control::set_rotation_degrees);
3346 ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Control::set_scale);
3347 ClassDB::bind_method(D_METHOD("set_pivot_offset", "pivot_offset"), &Control::set_pivot_offset);
3348 ClassDB::bind_method(D_METHOD("get_begin"), &Control::get_begin);
3349 ClassDB::bind_method(D_METHOD("get_end"), &Control::get_end);
3350 ClassDB::bind_method(D_METHOD("get_position"), &Control::get_position);
3351 ClassDB::bind_method(D_METHOD("get_size"), &Control::get_size);
3352 ClassDB::bind_method(D_METHOD("get_rotation"), &Control::get_rotation);
3353 ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &Control::get_rotation_degrees);
3354 ClassDB::bind_method(D_METHOD("get_scale"), &Control::get_scale);
3355 ClassDB::bind_method(D_METHOD("get_pivot_offset"), &Control::get_pivot_offset);
3356 ClassDB::bind_method(D_METHOD("get_custom_minimum_size"), &Control::get_custom_minimum_size);
3357 ClassDB::bind_method(D_METHOD("get_parent_area_size"), &Control::get_parent_area_size);
3358 ClassDB::bind_method(D_METHOD("get_global_position"), &Control::get_global_position);
3359 ClassDB::bind_method(D_METHOD("get_screen_position"), &Control::get_screen_position);
3360 ClassDB::bind_method(D_METHOD("get_rect"), &Control::get_rect);
3361 ClassDB::bind_method(D_METHOD("get_global_rect"), &Control::get_global_rect);
3362 ClassDB::bind_method(D_METHOD("set_focus_mode", "mode"), &Control::set_focus_mode);
3363 ClassDB::bind_method(D_METHOD("get_focus_mode"), &Control::get_focus_mode);
3364 ClassDB::bind_method(D_METHOD("has_focus"), &Control::has_focus);
3365 ClassDB::bind_method(D_METHOD("grab_focus"), &Control::grab_focus);
3366 ClassDB::bind_method(D_METHOD("release_focus"), &Control::release_focus);
3367 ClassDB::bind_method(D_METHOD("find_prev_valid_focus"), &Control::find_prev_valid_focus);
3368 ClassDB::bind_method(D_METHOD("find_next_valid_focus"), &Control::find_next_valid_focus);
3369
3370 ClassDB::bind_method(D_METHOD("set_h_size_flags", "flags"), &Control::set_h_size_flags);
3371 ClassDB::bind_method(D_METHOD("get_h_size_flags"), &Control::get_h_size_flags);
3372
3373 ClassDB::bind_method(D_METHOD("set_stretch_ratio", "ratio"), &Control::set_stretch_ratio);
3374 ClassDB::bind_method(D_METHOD("get_stretch_ratio"), &Control::get_stretch_ratio);
3375
3376 ClassDB::bind_method(D_METHOD("set_v_size_flags", "flags"), &Control::set_v_size_flags);
3377 ClassDB::bind_method(D_METHOD("get_v_size_flags"), &Control::get_v_size_flags);
3378
3379 ClassDB::bind_method(D_METHOD("set_theme", "theme"), &Control::set_theme);
3380 ClassDB::bind_method(D_METHOD("get_theme"), &Control::get_theme);
3381
3382 ClassDB::bind_method(D_METHOD("set_theme_type_variation", "theme_type"), &Control::set_theme_type_variation);
3383 ClassDB::bind_method(D_METHOD("get_theme_type_variation"), &Control::get_theme_type_variation);
3384
3385 ClassDB::bind_method(D_METHOD("begin_bulk_theme_override"), &Control::begin_bulk_theme_override);
3386 ClassDB::bind_method(D_METHOD("end_bulk_theme_override"), &Control::end_bulk_theme_override);
3387
3388 ClassDB::bind_method(D_METHOD("add_theme_icon_override", "name", "texture"), &Control::add_theme_icon_override);
3389 ClassDB::bind_method(D_METHOD("add_theme_stylebox_override", "name", "stylebox"), &Control::add_theme_style_override);
3390 ClassDB::bind_method(D_METHOD("add_theme_font_override", "name", "font"), &Control::add_theme_font_override);
3391 ClassDB::bind_method(D_METHOD("add_theme_font_size_override", "name", "font_size"), &Control::add_theme_font_size_override);
3392 ClassDB::bind_method(D_METHOD("add_theme_color_override", "name", "color"), &Control::add_theme_color_override);
3393 ClassDB::bind_method(D_METHOD("add_theme_constant_override", "name", "constant"), &Control::add_theme_constant_override);
3394
3395 ClassDB::bind_method(D_METHOD("remove_theme_icon_override", "name"), &Control::remove_theme_icon_override);
3396 ClassDB::bind_method(D_METHOD("remove_theme_stylebox_override", "name"), &Control::remove_theme_style_override);
3397 ClassDB::bind_method(D_METHOD("remove_theme_font_override", "name"), &Control::remove_theme_font_override);
3398 ClassDB::bind_method(D_METHOD("remove_theme_font_size_override", "name"), &Control::remove_theme_font_size_override);
3399 ClassDB::bind_method(D_METHOD("remove_theme_color_override", "name"), &Control::remove_theme_color_override);
3400 ClassDB::bind_method(D_METHOD("remove_theme_constant_override", "name"), &Control::remove_theme_constant_override);
3401
3402 ClassDB::bind_method(D_METHOD("get_theme_icon", "name", "theme_type"), &Control::get_theme_icon, DEFVAL(""));
3403 ClassDB::bind_method(D_METHOD("get_theme_stylebox", "name", "theme_type"), &Control::get_theme_stylebox, DEFVAL(""));
3404 ClassDB::bind_method(D_METHOD("get_theme_font", "name", "theme_type"), &Control::get_theme_font, DEFVAL(""));
3405 ClassDB::bind_method(D_METHOD("get_theme_font_size", "name", "theme_type"), &Control::get_theme_font_size, DEFVAL(""));
3406 ClassDB::bind_method(D_METHOD("get_theme_color", "name", "theme_type"), &Control::get_theme_color, DEFVAL(""));
3407 ClassDB::bind_method(D_METHOD("get_theme_constant", "name", "theme_type"), &Control::get_theme_constant, DEFVAL(""));
3408
3409 ClassDB::bind_method(D_METHOD("has_theme_icon_override", "name"), &Control::has_theme_icon_override);
3410 ClassDB::bind_method(D_METHOD("has_theme_stylebox_override", "name"), &Control::has_theme_stylebox_override);
3411 ClassDB::bind_method(D_METHOD("has_theme_font_override", "name"), &Control::has_theme_font_override);
3412 ClassDB::bind_method(D_METHOD("has_theme_font_size_override", "name"), &Control::has_theme_font_size_override);
3413 ClassDB::bind_method(D_METHOD("has_theme_color_override", "name"), &Control::has_theme_color_override);
3414 ClassDB::bind_method(D_METHOD("has_theme_constant_override", "name"), &Control::has_theme_constant_override);
3415
3416 ClassDB::bind_method(D_METHOD("has_theme_icon", "name", "theme_type"), &Control::has_theme_icon, DEFVAL(""));
3417 ClassDB::bind_method(D_METHOD("has_theme_stylebox", "name", "theme_type"), &Control::has_theme_stylebox, DEFVAL(""));
3418 ClassDB::bind_method(D_METHOD("has_theme_font", "name", "theme_type"), &Control::has_theme_font, DEFVAL(""));
3419 ClassDB::bind_method(D_METHOD("has_theme_font_size", "name", "theme_type"), &Control::has_theme_font_size, DEFVAL(""));
3420 ClassDB::bind_method(D_METHOD("has_theme_color", "name", "theme_type"), &Control::has_theme_color, DEFVAL(""));
3421 ClassDB::bind_method(D_METHOD("has_theme_constant", "name", "theme_type"), &Control::has_theme_constant, DEFVAL(""));
3422
3423 ClassDB::bind_method(D_METHOD("get_theme_default_base_scale"), &Control::get_theme_default_base_scale);
3424 ClassDB::bind_method(D_METHOD("get_theme_default_font"), &Control::get_theme_default_font);
3425 ClassDB::bind_method(D_METHOD("get_theme_default_font_size"), &Control::get_theme_default_font_size);
3426
3427 ClassDB::bind_method(D_METHOD("get_parent_control"), &Control::get_parent_control);
3428
3429 ClassDB::bind_method(D_METHOD("set_h_grow_direction", "direction"), &Control::set_h_grow_direction);
3430 ClassDB::bind_method(D_METHOD("get_h_grow_direction"), &Control::get_h_grow_direction);
3431
3432 ClassDB::bind_method(D_METHOD("set_v_grow_direction", "direction"), &Control::set_v_grow_direction);
3433 ClassDB::bind_method(D_METHOD("get_v_grow_direction"), &Control::get_v_grow_direction);
3434
3435 ClassDB::bind_method(D_METHOD("set_tooltip_text", "hint"), &Control::set_tooltip_text);
3436 ClassDB::bind_method(D_METHOD("get_tooltip_text"), &Control::get_tooltip_text);
3437 ClassDB::bind_method(D_METHOD("get_tooltip", "at_position"), &Control::get_tooltip, DEFVAL(Point2()));
3438
3439 ClassDB::bind_method(D_METHOD("set_default_cursor_shape", "shape"), &Control::set_default_cursor_shape);
3440 ClassDB::bind_method(D_METHOD("get_default_cursor_shape"), &Control::get_default_cursor_shape);
3441 ClassDB::bind_method(D_METHOD("get_cursor_shape", "position"), &Control::get_cursor_shape, DEFVAL(Point2()));
3442
3443 ClassDB::bind_method(D_METHOD("set_focus_neighbor", "side", "neighbor"), &Control::set_focus_neighbor);
3444 ClassDB::bind_method(D_METHOD("get_focus_neighbor", "side"), &Control::get_focus_neighbor);
3445
3446 ClassDB::bind_method(D_METHOD("set_focus_next", "next"), &Control::set_focus_next);
3447 ClassDB::bind_method(D_METHOD("get_focus_next"), &Control::get_focus_next);
3448
3449 ClassDB::bind_method(D_METHOD("set_focus_previous", "previous"), &Control::set_focus_previous);
3450 ClassDB::bind_method(D_METHOD("get_focus_previous"), &Control::get_focus_previous);
3451
3452 ClassDB::bind_method(D_METHOD("force_drag", "data", "preview"), &Control::force_drag);
3453
3454 ClassDB::bind_method(D_METHOD("set_mouse_filter", "filter"), &Control::set_mouse_filter);
3455 ClassDB::bind_method(D_METHOD("get_mouse_filter"), &Control::get_mouse_filter);
3456
3457 ClassDB::bind_method(D_METHOD("set_force_pass_scroll_events", "force_pass_scroll_events"), &Control::set_force_pass_scroll_events);
3458 ClassDB::bind_method(D_METHOD("is_force_pass_scroll_events"), &Control::is_force_pass_scroll_events);
3459
3460 ClassDB::bind_method(D_METHOD("set_clip_contents", "enable"), &Control::set_clip_contents);
3461 ClassDB::bind_method(D_METHOD("is_clipping_contents"), &Control::is_clipping_contents);
3462
3463 ClassDB::bind_method(D_METHOD("grab_click_focus"), &Control::grab_click_focus);
3464
3465 ClassDB::bind_method(D_METHOD("set_drag_forwarding", "drag_func", "can_drop_func", "drop_func"), &Control::set_drag_forwarding);
3466 ClassDB::bind_method(D_METHOD("set_drag_preview", "control"), &Control::set_drag_preview);
3467 ClassDB::bind_method(D_METHOD("is_drag_successful"), &Control::is_drag_successful);
3468
3469 ClassDB::bind_method(D_METHOD("warp_mouse", "position"), &Control::warp_mouse);
3470
3471 ClassDB::bind_method(D_METHOD("set_shortcut_context", "node"), &Control::set_shortcut_context);
3472 ClassDB::bind_method(D_METHOD("get_shortcut_context"), &Control::get_shortcut_context);
3473
3474 ClassDB::bind_method(D_METHOD("update_minimum_size"), &Control::update_minimum_size);
3475
3476 ClassDB::bind_method(D_METHOD("set_layout_direction", "direction"), &Control::set_layout_direction);
3477 ClassDB::bind_method(D_METHOD("get_layout_direction"), &Control::get_layout_direction);
3478 ClassDB::bind_method(D_METHOD("is_layout_rtl"), &Control::is_layout_rtl);
3479
3480 ClassDB::bind_method(D_METHOD("set_auto_translate", "enable"), &Control::set_auto_translate);
3481 ClassDB::bind_method(D_METHOD("is_auto_translating"), &Control::is_auto_translating);
3482
3483 ClassDB::bind_method(D_METHOD("set_localize_numeral_system", "enable"), &Control::set_localize_numeral_system);
3484 ClassDB::bind_method(D_METHOD("is_localizing_numeral_system"), &Control::is_localizing_numeral_system);
3485
3486 ADD_GROUP("Layout", "");
3487 ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_contents"), "set_clip_contents", "is_clipping_contents");
3488 ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "custom_minimum_size", PROPERTY_HINT_NONE, "suffix:px"), "set_custom_minimum_size", "get_custom_minimum_size");
3489 ADD_PROPERTY(PropertyInfo(Variant::INT, "layout_direction", PROPERTY_HINT_ENUM, "Inherited,Based on Locale,Left-to-Right,Right-to-Left"), "set_layout_direction", "get_layout_direction");
3490 ADD_PROPERTY(PropertyInfo(Variant::INT, "layout_mode", PROPERTY_HINT_ENUM, "Position,Anchors,Container,Uncontrolled", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "_set_layout_mode", "_get_layout_mode");
3491 ADD_PROPERTY_DEFAULT("layout_mode", LayoutMode::LAYOUT_MODE_POSITION);
3492
3493 const String anchors_presets_options = "Custom:-1,PresetFullRect:15,"
3494 "PresetTopLeft:0,PresetTopRight:1,PresetBottomRight:3,PresetBottomLeft:2,"
3495 "PresetCenterLeft:4,PresetCenterTop:5,PresetCenterRight:6,PresetCenterBottom:7,PresetCenter:8,"
3496 "PresetLeftWide:9,PresetTopWide:10,PresetRightWide:11,PresetBottomWide:12,PresetVCenterWide:13,PresetHCenterWide:14";
3497
3498 ADD_PROPERTY(PropertyInfo(Variant::INT, "anchors_preset", PROPERTY_HINT_ENUM, anchors_presets_options, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "_set_anchors_layout_preset", "_get_anchors_layout_preset");
3499 ADD_PROPERTY_DEFAULT("anchors_preset", -1);
3500
3501 ADD_SUBGROUP_INDENT("Anchor Points", "anchor_", 1);
3502 ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_left", PROPERTY_HINT_RANGE, "0,1,0.001,or_less,or_greater"), "_set_anchor", "get_anchor", SIDE_LEFT);
3503 ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_top", PROPERTY_HINT_RANGE, "0,1,0.001,or_less,or_greater"), "_set_anchor", "get_anchor", SIDE_TOP);
3504 ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_right", PROPERTY_HINT_RANGE, "0,1,0.001,or_less,or_greater"), "_set_anchor", "get_anchor", SIDE_RIGHT);
3505 ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_bottom", PROPERTY_HINT_RANGE, "0,1,0.001,or_less,or_greater"), "_set_anchor", "get_anchor", SIDE_BOTTOM);
3506
3507 ADD_SUBGROUP_INDENT("Anchor Offsets", "offset_", 1);
3508 ADD_PROPERTYI(PropertyInfo(Variant::INT, "offset_left", PROPERTY_HINT_RANGE, "-4096,4096,suffix:px"), "set_offset", "get_offset", SIDE_LEFT);
3509 ADD_PROPERTYI(PropertyInfo(Variant::INT, "offset_top", PROPERTY_HINT_RANGE, "-4096,4096,suffix:px"), "set_offset", "get_offset", SIDE_TOP);
3510 ADD_PROPERTYI(PropertyInfo(Variant::INT, "offset_right", PROPERTY_HINT_RANGE, "-4096,4096,suffix:px"), "set_offset", "get_offset", SIDE_RIGHT);
3511 ADD_PROPERTYI(PropertyInfo(Variant::INT, "offset_bottom", PROPERTY_HINT_RANGE, "-4096,4096,suffix:px"), "set_offset", "get_offset", SIDE_BOTTOM);
3512
3513 ADD_SUBGROUP_INDENT("Grow Direction", "grow_", 1);
3514 ADD_PROPERTY(PropertyInfo(Variant::INT, "grow_horizontal", PROPERTY_HINT_ENUM, "Left,Right,Both"), "set_h_grow_direction", "get_h_grow_direction");
3515 ADD_PROPERTY(PropertyInfo(Variant::INT, "grow_vertical", PROPERTY_HINT_ENUM, "Top,Bottom,Both"), "set_v_grow_direction", "get_v_grow_direction");
3516
3517 ADD_SUBGROUP("Transform", "");
3518 ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size", PROPERTY_HINT_NONE, "suffix:px", PROPERTY_USAGE_EDITOR), "_set_size", "get_size");
3519 ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position", PROPERTY_HINT_NONE, "suffix:px", PROPERTY_USAGE_EDITOR), "_set_position", "get_position");
3520 ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_position", PROPERTY_HINT_NONE, "suffix:px", PROPERTY_USAGE_NONE), "_set_global_position", "get_global_position");
3521 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rotation", PROPERTY_HINT_RANGE, "-360,360,0.1,or_less,or_greater,radians"), "set_rotation", "get_rotation");
3522 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_rotation_degrees", "get_rotation_degrees");
3523 ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale");
3524 ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "pivot_offset", PROPERTY_HINT_NONE, "suffix:px"), "set_pivot_offset", "get_pivot_offset");
3525
3526 ADD_SUBGROUP("Container Sizing", "size_flags_");
3527 ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill:1,Expand:2,Shrink Center:4,Shrink End:8"), "set_h_size_flags", "get_h_size_flags");
3528 ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill:1,Expand:2,Shrink Center:4,Shrink End:8"), "set_v_size_flags", "get_v_size_flags");
3529 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,20,0.01,or_greater"), "set_stretch_ratio", "get_stretch_ratio");
3530
3531 ADD_GROUP("Localization", "");
3532 ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate"), "set_auto_translate", "is_auto_translating");
3533 ADD_PROPERTY(PropertyInfo(Variant::BOOL, "localize_numeral_system"), "set_localize_numeral_system", "is_localizing_numeral_system");
3534
3535 ADD_GROUP("Tooltip", "tooltip_");
3536 ADD_PROPERTY(PropertyInfo(Variant::STRING, "tooltip_text", PROPERTY_HINT_MULTILINE_TEXT), "set_tooltip_text", "get_tooltip_text");
3537
3538 ADD_GROUP("Focus", "focus_");
3539 ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "focus_neighbor_left", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_neighbor", "get_focus_neighbor", SIDE_LEFT);
3540 ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "focus_neighbor_top", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_neighbor", "get_focus_neighbor", SIDE_TOP);
3541 ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "focus_neighbor_right", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_neighbor", "get_focus_neighbor", SIDE_RIGHT);
3542 ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "focus_neighbor_bottom", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_neighbor", "get_focus_neighbor", SIDE_BOTTOM);
3543 ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "focus_next", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_next", "get_focus_next");
3544 ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "focus_previous", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_previous", "get_focus_previous");
3545 ADD_PROPERTY(PropertyInfo(Variant::INT, "focus_mode", PROPERTY_HINT_ENUM, "None,Click,All"), "set_focus_mode", "get_focus_mode");
3546
3547 ADD_GROUP("Mouse", "mouse_");
3548 ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_filter", PROPERTY_HINT_ENUM, "Stop,Pass,Ignore"), "set_mouse_filter", "get_mouse_filter");
3549 ADD_PROPERTY(PropertyInfo(Variant::BOOL, "mouse_force_pass_scroll_events"), "set_force_pass_scroll_events", "is_force_pass_scroll_events");
3550 ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_default_cursor_shape", PROPERTY_HINT_ENUM, "Arrow,I-Beam,Pointing Hand,Cross,Wait,Busy,Drag,Can Drop,Forbidden,Vertical Resize,Horizontal Resize,Secondary Diagonal Resize,Main Diagonal Resize,Move,Vertical Split,Horizontal Split,Help"), "set_default_cursor_shape", "get_default_cursor_shape");
3551
3552 ADD_GROUP("Input", "");
3553 ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shortcut_context", PROPERTY_HINT_NODE_TYPE, "Node"), "set_shortcut_context", "get_shortcut_context");
3554
3555 ADD_GROUP("Theme", "theme_");
3556 ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme");
3557 ADD_PROPERTY(PropertyInfo(Variant::STRING, "theme_type_variation", PROPERTY_HINT_ENUM_SUGGESTION), "set_theme_type_variation", "get_theme_type_variation");
3558
3559 BIND_ENUM_CONSTANT(FOCUS_NONE);
3560 BIND_ENUM_CONSTANT(FOCUS_CLICK);
3561 BIND_ENUM_CONSTANT(FOCUS_ALL);
3562
3563 BIND_CONSTANT(NOTIFICATION_RESIZED);
3564 BIND_CONSTANT(NOTIFICATION_MOUSE_ENTER);
3565 BIND_CONSTANT(NOTIFICATION_MOUSE_EXIT);
3566 BIND_CONSTANT(NOTIFICATION_FOCUS_ENTER);
3567 BIND_CONSTANT(NOTIFICATION_FOCUS_EXIT);
3568 BIND_CONSTANT(NOTIFICATION_THEME_CHANGED);
3569 BIND_CONSTANT(NOTIFICATION_SCROLL_BEGIN);
3570 BIND_CONSTANT(NOTIFICATION_SCROLL_END);
3571 BIND_CONSTANT(NOTIFICATION_LAYOUT_DIRECTION_CHANGED);
3572
3573 BIND_ENUM_CONSTANT(CURSOR_ARROW);
3574 BIND_ENUM_CONSTANT(CURSOR_IBEAM);
3575 BIND_ENUM_CONSTANT(CURSOR_POINTING_HAND);
3576 BIND_ENUM_CONSTANT(CURSOR_CROSS);
3577 BIND_ENUM_CONSTANT(CURSOR_WAIT);
3578 BIND_ENUM_CONSTANT(CURSOR_BUSY);
3579 BIND_ENUM_CONSTANT(CURSOR_DRAG);
3580 BIND_ENUM_CONSTANT(CURSOR_CAN_DROP);
3581 BIND_ENUM_CONSTANT(CURSOR_FORBIDDEN);
3582 BIND_ENUM_CONSTANT(CURSOR_VSIZE);
3583 BIND_ENUM_CONSTANT(CURSOR_HSIZE);
3584 BIND_ENUM_CONSTANT(CURSOR_BDIAGSIZE);
3585 BIND_ENUM_CONSTANT(CURSOR_FDIAGSIZE);
3586 BIND_ENUM_CONSTANT(CURSOR_MOVE);
3587 BIND_ENUM_CONSTANT(CURSOR_VSPLIT);
3588 BIND_ENUM_CONSTANT(CURSOR_HSPLIT);
3589 BIND_ENUM_CONSTANT(CURSOR_HELP);
3590
3591 BIND_ENUM_CONSTANT(PRESET_TOP_LEFT);
3592 BIND_ENUM_CONSTANT(PRESET_TOP_RIGHT);
3593 BIND_ENUM_CONSTANT(PRESET_BOTTOM_LEFT);
3594 BIND_ENUM_CONSTANT(PRESET_BOTTOM_RIGHT);
3595 BIND_ENUM_CONSTANT(PRESET_CENTER_LEFT);
3596 BIND_ENUM_CONSTANT(PRESET_CENTER_TOP);
3597 BIND_ENUM_CONSTANT(PRESET_CENTER_RIGHT);
3598 BIND_ENUM_CONSTANT(PRESET_CENTER_BOTTOM);
3599 BIND_ENUM_CONSTANT(PRESET_CENTER);
3600 BIND_ENUM_CONSTANT(PRESET_LEFT_WIDE);
3601 BIND_ENUM_CONSTANT(PRESET_TOP_WIDE);
3602 BIND_ENUM_CONSTANT(PRESET_RIGHT_WIDE);
3603 BIND_ENUM_CONSTANT(PRESET_BOTTOM_WIDE);
3604 BIND_ENUM_CONSTANT(PRESET_VCENTER_WIDE);
3605 BIND_ENUM_CONSTANT(PRESET_HCENTER_WIDE);
3606 BIND_ENUM_CONSTANT(PRESET_FULL_RECT);
3607
3608 BIND_ENUM_CONSTANT(PRESET_MODE_MINSIZE);
3609 BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_WIDTH);
3610 BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_HEIGHT);
3611 BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_SIZE);
3612
3613 BIND_BITFIELD_FLAG(SIZE_SHRINK_BEGIN);
3614 BIND_BITFIELD_FLAG(SIZE_FILL);
3615 BIND_BITFIELD_FLAG(SIZE_EXPAND);
3616 BIND_BITFIELD_FLAG(SIZE_EXPAND_FILL);
3617 BIND_BITFIELD_FLAG(SIZE_SHRINK_CENTER);
3618 BIND_BITFIELD_FLAG(SIZE_SHRINK_END);
3619
3620 BIND_ENUM_CONSTANT(MOUSE_FILTER_STOP);
3621 BIND_ENUM_CONSTANT(MOUSE_FILTER_PASS);
3622 BIND_ENUM_CONSTANT(MOUSE_FILTER_IGNORE);
3623
3624 BIND_ENUM_CONSTANT(GROW_DIRECTION_BEGIN);
3625 BIND_ENUM_CONSTANT(GROW_DIRECTION_END);
3626 BIND_ENUM_CONSTANT(GROW_DIRECTION_BOTH);
3627
3628 BIND_ENUM_CONSTANT(ANCHOR_BEGIN);
3629 BIND_ENUM_CONSTANT(ANCHOR_END);
3630
3631 BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_INHERITED);
3632 BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_LOCALE);
3633 BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_LTR);
3634 BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_RTL);
3635
3636 BIND_ENUM_CONSTANT(TEXT_DIRECTION_INHERITED);
3637 BIND_ENUM_CONSTANT(TEXT_DIRECTION_AUTO);
3638 BIND_ENUM_CONSTANT(TEXT_DIRECTION_LTR);
3639 BIND_ENUM_CONSTANT(TEXT_DIRECTION_RTL);
3640
3641 ADD_SIGNAL(MethodInfo("resized"));
3642 ADD_SIGNAL(MethodInfo("gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
3643 ADD_SIGNAL(MethodInfo("mouse_entered"));
3644 ADD_SIGNAL(MethodInfo("mouse_exited"));
3645 ADD_SIGNAL(MethodInfo("focus_entered"));
3646 ADD_SIGNAL(MethodInfo("focus_exited"));
3647 ADD_SIGNAL(MethodInfo("size_flags_changed"));
3648 ADD_SIGNAL(MethodInfo("minimum_size_changed"));
3649 ADD_SIGNAL(MethodInfo("theme_changed"));
3650
3651 GDVIRTUAL_BIND(_has_point, "point");
3652 GDVIRTUAL_BIND(_structured_text_parser, "args", "text");
3653 GDVIRTUAL_BIND(_get_minimum_size);
3654 GDVIRTUAL_BIND(_get_tooltip, "at_position");
3655
3656 GDVIRTUAL_BIND(_get_drag_data, "at_position");
3657 GDVIRTUAL_BIND(_can_drop_data, "at_position", "data");
3658 GDVIRTUAL_BIND(_drop_data, "at_position", "data");
3659 GDVIRTUAL_BIND(_make_custom_tooltip, "for_text");
3660
3661 GDVIRTUAL_BIND(_gui_input, "event");
3662}
3663
3664Control::Control() {
3665 data.theme_owner = memnew(ThemeOwner(this));
3666}
3667
3668Control::~Control() {
3669 memdelete(data.theme_owner);
3670
3671 // Resources need to be disconnected.
3672 for (KeyValue<StringName, Ref<Texture2D>> &E : data.theme_icon_override) {
3673 E.value->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed));
3674 }
3675 for (KeyValue<StringName, Ref<StyleBox>> &E : data.theme_style_override) {
3676 E.value->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed));
3677 }
3678 for (KeyValue<StringName, Ref<Font>> &E : data.theme_font_override) {
3679 E.value->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed));
3680 }
3681
3682 // Then override maps can be simply cleared.
3683 data.theme_icon_override.clear();
3684 data.theme_style_override.clear();
3685 data.theme_font_override.clear();
3686 data.theme_font_size_override.clear();
3687 data.theme_color_override.clear();
3688 data.theme_constant_override.clear();
3689}
3690