Merge pull request #42427 from KoBeWi/achtung_size
Warn when setting Control size inside ready()
This commit is contained in:
commit
7447af265b
|
@ -456,6 +456,10 @@ bool Control::is_layout_rtl() const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
//moved theme configuration here, so controls can set up even if still not inside active scene
|
||||||
|
|
||||||
void Control::add_child_notify(Node *p_child) {
|
void Control::add_child_notify(Node *p_child) {
|
||||||
|
@ -503,7 +507,9 @@ void Control::_notification(int p_notification) {
|
||||||
} break;
|
} break;
|
||||||
case NOTIFICATION_EXIT_TREE: {
|
case NOTIFICATION_EXIT_TREE: {
|
||||||
get_viewport()->_gui_remove_control(this);
|
get_viewport()->_gui_remove_control(this);
|
||||||
|
} break;
|
||||||
|
case NOTIFICATION_READY: {
|
||||||
|
connect("ready", callable_mp(this, &Control::_clear_size_warning), varray(), CONNECT_DEFERRED | CONNECT_ONESHOT);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case NOTIFICATION_ENTER_CANVAS: {
|
case NOTIFICATION_ENTER_CANVAS: {
|
||||||
|
@ -1702,6 +1708,11 @@ void Control::set_rect(const Rect2 &p_rect) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Control::_set_size(const Size2 &p_size) {
|
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);
|
set_size(p_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -182,6 +182,7 @@ private:
|
||||||
float rotation = 0.0;
|
float rotation = 0.0;
|
||||||
Vector2 scale = Vector2(1, 1);
|
Vector2 scale = Vector2(1, 1);
|
||||||
Vector2 pivot_offset;
|
Vector2 pivot_offset;
|
||||||
|
bool size_warning = true;
|
||||||
|
|
||||||
int h_size_flags = SIZE_FILL;
|
int h_size_flags = SIZE_FILL;
|
||||||
int v_size_flags = SIZE_FILL;
|
int v_size_flags = SIZE_FILL;
|
||||||
|
@ -235,6 +236,7 @@ private:
|
||||||
|
|
||||||
void _update_minimum_size();
|
void _update_minimum_size();
|
||||||
|
|
||||||
|
void _clear_size_warning();
|
||||||
void _update_scroll();
|
void _update_scroll();
|
||||||
|
|
||||||
void _compute_offsets(Rect2 p_rect, const float p_anchors[4], float (&r_offsets)[4]);
|
void _compute_offsets(Rect2 p_rect, const float p_anchors[4], float (&r_offsets)[4]);
|
||||||
|
|
Loading…
Reference in a new issue