diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-06-25 17:46:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-25 17:46:57 +0200 |
commit | 18b62d50194576f555c53ed5409b5a71fbfe5630 (patch) | |
tree | c4680b72d90e4079646e1d91827e19e6c66bf621 | |
parent | ca084db4aa6d5da8f34fc889d70f1b8e46990b82 (diff) | |
parent | 54653565a45e90a6640491fa7211c4659eac303f (diff) |
Merge pull request #30053 from guilhermefelipecgs/fix_popup_centered
Fix Popup::popup_centered not centralizing at the first call
-rw-r--r-- | scene/gui/popup.cpp | 17 | ||||
-rw-r--r-- | scene/gui/popup.h | 3 |
2 files changed, 17 insertions, 3 deletions
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index fdb1b65f77..492e379440 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -141,7 +141,7 @@ void Popup::popup_centered(const Size2 &p_size) { rect.size = p_size == Size2() ? get_size() : p_size; rect.position = ((window_size - rect.size) / 2.0).floor(); - popup(rect); + _popup(rect, true); } void Popup::popup_centered_ratio(float p_screen_ratio) { @@ -151,18 +151,29 @@ void Popup::popup_centered_ratio(float p_screen_ratio) { rect.size = (window_size * p_screen_ratio).floor(); rect.position = ((window_size - rect.size) / 2.0).floor(); - popup(rect); + _popup(rect, true); } void Popup::popup(const Rect2 &p_bounds) { + _popup(p_bounds); +} + +void Popup::_popup(const Rect2 &p_bounds, const bool p_centered) { + emit_signal("about_to_show"); show_modal(exclusive); // Fit the popup into the optionally provided bounds. if (!p_bounds.has_no_area()) { - set_position(p_bounds.position); set_size(p_bounds.size); + + // check if p_bounds.size was using an outdated cached values + if (p_centered && p_bounds.size != get_size()) { + set_position(p_bounds.position - ((get_size() - p_bounds.size) / 2.0).floor()); + } else { + set_position(p_bounds.position); + } } _fix_size(); diff --git a/scene/gui/popup.h b/scene/gui/popup.h index 6615c51ec5..d6d96dfe64 100644 --- a/scene/gui/popup.h +++ b/scene/gui/popup.h @@ -43,6 +43,9 @@ class Popup : public Control { bool exclusive; bool popped_up; +private: + void _popup(const Rect2 &p_bounds = Rect2(), const bool p_centered = false); + protected: virtual void _post_popup() {} |