-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix popup_centered not centered when size changed #24907
Conversation
When `popup_centered` was called while the size of the popup has changed (e.g. Label text got changed), it was calculating the position based on the old size. This commit forces the size to be recalculated.
Sorry for the late review. It makes sense to force calculating the size IMO, but the reason I haven't merged this yet is that I'm not sure
|
Thx for reviewing. The reason I used Do you know where the actual function is located? I'd be happy to contribute a better fix for this |
I've taken another look into the codebase. The I don't think it's a good idea to attempt a fix in I think doing a size recalculation before the calculations in Another idea I just had is to do the popup first and then adjust the position of the popup. |
After experimenting a bit, I realized that the size of a Label is only updated when it becomes visible. Therefore calculating the new position after doing the popup doesn't work. |
#19334 was supposed to have fixed this issue and similar ones, but this PR (and #29760) are evidence that it's still not working everywhere. CC @guilhermefelipecgs |
I didn't understood how to reproduce this. I created a popup with a label and before calling @Dragoncraft89 Could you attach a demo project showing this behavior please? |
@Dragoncraft89 Never mind. I discovery how to reproduce this behavior. |
This problems happens because Here is how I would fix diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index e3e9368a1..584de3cb1 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -541,6 +541,8 @@ void Label::set_text(const String &p_string) {
word_cache_dirty = true;
if (percent_visible < 1)
visible_chars = get_total_character_count() * percent_visible;
+
+ minimum_size_changed();
update();
}
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index fdb1b65f7..6ceaeb905 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -138,7 +138,7 @@ void Popup::popup_centered(const Size2 &p_size) {
Rect2 rect;
Size2 window_size = get_viewport_rect().size;
- rect.size = p_size == Size2() ? get_size() : p_size;
+ rect.size = p_size == Size2() ? get_combined_minimum_size() : p_size;
rect.position = ((window_size - rect.size) / 2.0).floor();
popup(rect); That's how I'm testing func _on_Button_pressed():
$ConfirmationDialog/Label2.text = "12345678901234567890123456789012345678901234567890"
$ConfirmationDialog.popup_centered() The way this PR was made (using |
Superseded by #30053. Thanks for the contribution nevertheless, as it helped find out the better fix! |
When
popup_centered
was called while the size of the popup has changed (e.g. Label text got changed), it was calculating the position based on the old size.This commit forces the size to be recalculated.