Skip to content

Commit

Permalink
Warn when setting Control size inside ready()
Browse files Browse the repository at this point in the history
(cherry picked from commit 84da090)
  • Loading branch information
KoBeWi authored and akien-mga committed Feb 22, 2021
1 parent cefaa6f commit a8105d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 14 additions & 1 deletion scene/gui/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ void Control::_resize(const Size2 &p_size) {
_size_changed();
}

void Control::_clear_size_warning() {
data.size_warning = false;
}

//moved theme configuration here, so controls can set up even if still not inside active scene

void Control::add_child_notify(Node *p_child) {
Expand Down Expand Up @@ -484,7 +488,9 @@ void Control::_notification(int p_notification) {
case NOTIFICATION_EXIT_TREE: {

get_viewport()->_gui_remove_control(this);

} break;
case NOTIFICATION_READY: {
connect("ready", this, "_clear_size_warning", varray(), CONNECT_DEFERRED | CONNECT_ONESHOT);
} break;

case NOTIFICATION_ENTER_CANVAS: {
Expand Down Expand Up @@ -1829,6 +1835,11 @@ void Control::set_position(const Size2 &p_point, bool p_keep_margins) {
}

void Control::_set_size(const Size2 &p_size) {
#ifdef DEBUG_ENABLED
if (data.size_warning) {
WARN_PRINT("Adjusting the size of Control nodes before they are fully initialized is unreliable. Consider deferring it with set_deferred().");
}
#endif
set_size(p_size);
}

Expand Down Expand Up @@ -2953,6 +2964,8 @@ void Control::_bind_methods() {

ClassDB::bind_method(D_METHOD("_override_changed"), &Control::_override_changed);

ClassDB::bind_method(D_METHOD("_clear_size_warning"), &Control::_clear_size_warning);

BIND_VMETHOD(MethodInfo("_gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
BIND_VMETHOD(MethodInfo(Variant::VECTOR2, "_get_minimum_size"));

Expand Down
2 changes: 2 additions & 0 deletions scene/gui/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class Control : public CanvasItem {
float rotation;
Vector2 scale;
Vector2 pivot_offset;
bool size_warning = true;

bool pending_resize;

Expand Down Expand Up @@ -224,6 +225,7 @@ class Control : public CanvasItem {
void _change_notify_margins();
void _update_minimum_size();

void _clear_size_warning();
void _update_scroll();
void _resize(const Size2 &p_size);

Expand Down

0 comments on commit a8105d7

Please sign in to comment.