From df26066ce9c59b59756653fd761bd38012b00878 Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Tue, 6 Jun 2023 20:55:03 +0200 Subject: [PATCH 1/2] Revert "Make sure that `data.last_minimum_size` is consistent with `get_combined_minimum_size()` at the same time" This reverts commit 594852caf1353ba48ba40c19bc05977635b5b9e8. --- scene/gui/control.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index c28cfeea1d33..3beaf83f6f37 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1582,6 +1582,22 @@ void Control::_update_minimum_size() { return; } + Size2 minsize = get_combined_minimum_size(); + data.updating_last_minimum_size = false; + + if (minsize != data.last_minimum_size) { + data.last_minimum_size = minsize; + _size_changed(); + emit_signal(SceneStringNames::get_singleton()->minimum_size_changed); + } +} + +void Control::update_minimum_size() { + ERR_MAIN_THREAD_GUARD; + if (!is_inside_tree() || data.block_minimum_size_adjust) { + return; + } + Control *invalidate = this; // Invalidate cache upwards. @@ -1604,21 +1620,6 @@ void Control::_update_minimum_size() { return; } - Size2 minsize = get_combined_minimum_size(); - data.updating_last_minimum_size = false; - if (minsize != data.last_minimum_size) { - data.last_minimum_size = minsize; - _size_changed(); - emit_signal(SceneStringNames::get_singleton()->minimum_size_changed); - } -} - -void Control::update_minimum_size() { - ERR_MAIN_THREAD_GUARD; - if (!is_inside_tree() || data.block_minimum_size_adjust) { - return; - } - if (data.updating_last_minimum_size) { return; } @@ -3139,6 +3140,7 @@ void Control::_notification(int p_notification) { } break; case NOTIFICATION_POST_ENTER_TREE: { + data.minimum_size_valid = false; data.is_rtl_dirty = true; _size_changed(); } break; @@ -3267,7 +3269,9 @@ void Control::_notification(int p_notification) { get_viewport()->_gui_hide_control(this); } } else { + data.minimum_size_valid = false; _update_minimum_size(); + _size_changed(); } } break; From ccaab0e590ee5ebb343841a5acfb14f59a7d84c5 Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Tue, 6 Jun 2023 22:05:53 +0200 Subject: [PATCH 2/2] Ensure that controls update all their sizing information when required --- scene/gui/container.cpp | 2 -- scene/gui/control.cpp | 32 +++++++++++++------------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp index 145074a626fc..1e642d4bacc1 100644 --- a/scene/gui/container.cpp +++ b/scene/gui/container.cpp @@ -34,8 +34,6 @@ #include "scene/scene_string_names.h" void Container::_child_minsize_changed() { - //Size2 ms = get_combined_minimum_size(); - //if (ms.width > get_size().width || ms.height > get_size().height) { update_minimum_size(); queue_sort(); } diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 3beaf83f6f37..eff10c56331f 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1579,6 +1579,7 @@ Vector2 Control::get_pivot_offset() const { void Control::_update_minimum_size() { if (!is_inside_tree()) { + data.updating_last_minimum_size = false; return; } @@ -1598,9 +1599,8 @@ void Control::update_minimum_size() { return; } - Control *invalidate = this; - // Invalidate cache upwards. + Control *invalidate = this; while (invalidate && invalidate->data.minimum_size_valid) { invalidate->data.minimum_size_valid = false; if (invalidate->is_set_as_top_level()) { @@ -1623,10 +1623,9 @@ void Control::update_minimum_size() { if (data.updating_last_minimum_size) { return; } - data.updating_last_minimum_size = true; - MessageQueue::get_singleton()->push_call(this, "_update_minimum_size"); + MessageQueue::get_singleton()->push_callable(callable_mp(this, &Control::_update_minimum_size)); } void Control::set_block_minimum_size_adjust(bool p_block) { @@ -1666,17 +1665,8 @@ void Control::_update_minimum_size_cache() { minsize.x = MAX(minsize.x, data.custom_minimum_size.x); minsize.y = MAX(minsize.y, data.custom_minimum_size.y); - bool size_changed = false; - if (data.minimum_size_cache != minsize) { - size_changed = true; - } - data.minimum_size_cache = minsize; data.minimum_size_valid = true; - - if (size_changed) { - update_minimum_size(); - } } Size2 Control::get_combined_minimum_size() const { @@ -3140,8 +3130,8 @@ void Control::_notification(int p_notification) { } break; case NOTIFICATION_POST_ENTER_TREE: { - data.minimum_size_valid = false; data.is_rtl_dirty = true; + update_minimum_size(); _size_changed(); } break; @@ -3257,10 +3247,13 @@ void Control::_notification(int p_notification) { case NOTIFICATION_THEME_CHANGED: { emit_signal(SceneStringNames::get_singleton()->theme_changed); + _invalidate_theme_cache(); _update_theme_item_cache(); - update_minimum_size(); queue_redraw(); + + update_minimum_size(); + _size_changed(); } break; case NOTIFICATION_VISIBILITY_CHANGED: { @@ -3269,8 +3262,7 @@ void Control::_notification(int p_notification) { get_viewport()->_gui_hide_control(this); } } else { - data.minimum_size_valid = false; - _update_minimum_size(); + update_minimum_size(); _size_changed(); } } break; @@ -3279,8 +3271,12 @@ void Control::_notification(int p_notification) { case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: { if (is_inside_tree()) { data.is_rtl_dirty = true; + _invalidate_theme_cache(); _update_theme_item_cache(); + queue_redraw(); + + update_minimum_size(); _size_changed(); } } break; @@ -3288,8 +3284,6 @@ void Control::_notification(int p_notification) { } void Control::_bind_methods() { - ClassDB::bind_method(D_METHOD("_update_minimum_size"), &Control::_update_minimum_size); - ClassDB::bind_method(D_METHOD("accept_event"), &Control::accept_event); ClassDB::bind_method(D_METHOD("get_minimum_size"), &Control::get_minimum_size); ClassDB::bind_method(D_METHOD("get_combined_minimum_size"), &Control::get_combined_minimum_size);