1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-31 18:41:20 +00:00

Merge pull request #112604 from bruvzg/pop_center_rec

Update rect after `_pre_popup` in `popup_centered_*`.
This commit is contained in:
Thaddeus Crews
2025-11-25 09:52:38 -06:00
10 changed files with 60 additions and 18 deletions

View File

@@ -1941,7 +1941,17 @@ void Window::popup_centered_clamped(const Size2i &p_size, float p_fallback_ratio
popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2;
}
popup(popup_rect);
emit_signal(SNAME("about_to_popup"));
if (popup_rect != Rect2()) {
set_size(popup_rect.size);
}
_pre_popup();
if (popup_rect != Rect2i()) {
popup_rect.size = get_size();
popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2;
}
_popup_base(popup_rect);
}
void Window::popup_centered(const Size2i &p_minsize) {
@@ -1970,7 +1980,17 @@ void Window::popup_centered(const Size2i &p_minsize) {
popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2;
}
popup(popup_rect);
emit_signal(SNAME("about_to_popup"));
if (popup_rect != Rect2()) {
set_size(popup_rect.size);
}
_pre_popup();
if (popup_rect != Rect2i()) {
popup_rect.size = get_size();
popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2;
}
_popup_base(popup_rect);
}
void Window::popup_centered_ratio(float p_ratio) {
@@ -1997,14 +2017,36 @@ void Window::popup_centered_ratio(float p_ratio) {
popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2;
}
popup(popup_rect);
emit_signal(SNAME("about_to_popup"));
if (popup_rect != Rect2()) {
set_size(popup_rect.size);
}
_pre_popup();
if (popup_rect != Rect2i()) {
popup_rect.size = get_size();
popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2;
}
_popup_base(popup_rect);
}
void Window::popup(const Rect2i &p_screen_rect) {
ERR_MAIN_THREAD_GUARD;
emit_signal(SNAME("about_to_popup"));
Rect2i screen_rect = p_screen_rect;
if (screen_rect != Rect2i()) {
set_size(screen_rect.size);
}
_pre_popup();
if (screen_rect != Rect2i()) {
screen_rect.size = get_size();
}
_popup_base(screen_rect);
}
void Window::_popup_base(const Rect2i &p_screen_rect) {
ERR_MAIN_THREAD_GUARD;
if (!get_embedder() && get_flag(FLAG_POPUP)) {
// Send a focus-out notification when opening a Window Manager Popup.

View File

@@ -259,6 +259,7 @@ private:
static int root_layout_direction;
protected:
virtual void _popup_base(const Rect2i &p_screen_rect = Rect2i());
virtual void _pre_popup() {} // Called after "about_to_popup", but before window is shown.
virtual Rect2i _popup_adjust_rect() const { return Rect2i(); }
virtual void _post_popup() {}
@@ -407,7 +408,7 @@ public:
Window *get_non_popup_window() const;
Viewport *get_parent_viewport() const;
virtual void popup(const Rect2i &p_screen_rect = Rect2i());
void popup(const Rect2i &p_screen_rect = Rect2i());
void popup_on_parent(const Rect2i &p_parent_rect);
void popup_centered(const Size2i &p_minsize = Size2i());
void popup_centered_ratio(float p_ratio = 0.8);