diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 3cd9092e915..52295343938 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -3211,21 +3211,24 @@ void PopupMenu::popup(const Rect2i &p_bounds) { moved = Vector2(); popup_time_msec = OS::get_singleton()->get_ticks_msec(); - Size2 scale = get_parent_viewport()->get_popup_base_transform().get_scale(); - CanvasItem *c = Object::cast_to(get_parent()); - if (c) { - scale *= c->get_global_transform_with_canvas().get_scale(); - } - real_t popup_scale = MIN(scale.x, scale.y); - set_content_scale_factor(popup_scale); - Size2 minsize = get_contents_minimum_size() * popup_scale; - minsize.height = Math::ceil(minsize.height); // Ensures enough height at fractional content scales to prevent the v_scroll_bar from showing. - set_min_size(minsize); // `height` is truncated here by the cast to Size2i for Window.min_size. - set_size(Vector2(0, 0)); // Shrinkwraps to min size. Popup::popup(p_bounds); } } +void PopupMenu::_pre_popup() { + Size2 scale = get_parent_viewport()->get_popup_base_transform().get_scale(); + CanvasItem *c = Object::cast_to(get_parent()); + if (c) { + scale *= c->get_global_transform_with_canvas().get_scale(); + } + real_t popup_scale = MIN(scale.x, scale.y); + set_content_scale_factor(popup_scale); + Size2 minsize = get_contents_minimum_size() * popup_scale; + minsize.height = Math::ceil(minsize.height); // Ensures enough height at fractional content scales to prevent the v_scroll_bar from showing. + set_min_size(minsize); // `height` is truncated here by the cast to Size2i for Window.min_size. + reset_size(); // Shrinkwraps to min size. +} + void PopupMenu::set_visible(bool p_visible) { bool native = global_menu.is_valid(); #ifdef TOOLS_ENABLED diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h index 30cff62a93b..f4f534b097e 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -226,6 +226,7 @@ class PopupMenu : public Popup { String _atr(int p_idx, const String &p_text) const; protected: + virtual void _pre_popup() override; virtual Rect2i _popup_adjust_rect() const override; virtual void add_child_notify(Node *p_child) override; diff --git a/scene/main/window.cpp b/scene/main/window.cpp index 4ff3b1d0b01..819606d9565 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -1994,6 +1994,8 @@ void Window::popup(const Rect2i &p_screen_rect) { ERR_MAIN_THREAD_GUARD; emit_signal(SNAME("about_to_popup")); + _pre_popup(); + if (!get_embedder() && get_flag(FLAG_POPUP)) { // Send a focus-out notification when opening a Window Manager Popup. SceneTree *scene_tree = get_tree(); diff --git a/scene/main/window.h b/scene/main/window.h index 7f29bbd24ba..b53a3808558 100644 --- a/scene/main/window.h +++ b/scene/main/window.h @@ -257,6 +257,7 @@ private: static int root_layout_direction; protected: + 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() {}