Skip to content

Commit 8aac4a1

Browse files
committed
Merge pull request #106742 from bruvzg/about_to_popup
Call `PopupMenu` min. size calculations after `about_to_popup` signal processing.
2 parents 9282ed3 + 12d957e commit 8aac4a1

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

scene/gui/popup_menu.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3211,21 +3211,24 @@ void PopupMenu::popup(const Rect2i &p_bounds) {
32113211
moved = Vector2();
32123212
popup_time_msec = OS::get_singleton()->get_ticks_msec();
32133213

3214-
Size2 scale = get_parent_viewport()->get_popup_base_transform().get_scale();
3215-
CanvasItem *c = Object::cast_to<CanvasItem>(get_parent());
3216-
if (c) {
3217-
scale *= c->get_global_transform_with_canvas().get_scale();
3218-
}
3219-
real_t popup_scale = MIN(scale.x, scale.y);
3220-
set_content_scale_factor(popup_scale);
3221-
Size2 minsize = get_contents_minimum_size() * popup_scale;
3222-
minsize.height = Math::ceil(minsize.height); // Ensures enough height at fractional content scales to prevent the v_scroll_bar from showing.
3223-
set_min_size(minsize); // `height` is truncated here by the cast to Size2i for Window.min_size.
3224-
set_size(Vector2(0, 0)); // Shrinkwraps to min size.
32253214
Popup::popup(p_bounds);
32263215
}
32273216
}
32283217

3218+
void PopupMenu::_pre_popup() {
3219+
Size2 scale = get_parent_viewport()->get_popup_base_transform().get_scale();
3220+
CanvasItem *c = Object::cast_to<CanvasItem>(get_parent());
3221+
if (c) {
3222+
scale *= c->get_global_transform_with_canvas().get_scale();
3223+
}
3224+
real_t popup_scale = MIN(scale.x, scale.y);
3225+
set_content_scale_factor(popup_scale);
3226+
Size2 minsize = get_contents_minimum_size() * popup_scale;
3227+
minsize.height = Math::ceil(minsize.height); // Ensures enough height at fractional content scales to prevent the v_scroll_bar from showing.
3228+
set_min_size(minsize); // `height` is truncated here by the cast to Size2i for Window.min_size.
3229+
reset_size(); // Shrinkwraps to min size.
3230+
}
3231+
32293232
void PopupMenu::set_visible(bool p_visible) {
32303233
bool native = global_menu.is_valid();
32313234
#ifdef TOOLS_ENABLED

scene/gui/popup_menu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ class PopupMenu : public Popup {
226226
String _atr(int p_idx, const String &p_text) const;
227227

228228
protected:
229+
virtual void _pre_popup() override;
229230
virtual Rect2i _popup_adjust_rect() const override;
230231

231232
virtual void add_child_notify(Node *p_child) override;

scene/main/window.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,8 @@ void Window::popup(const Rect2i &p_screen_rect) {
19941994
ERR_MAIN_THREAD_GUARD;
19951995
emit_signal(SNAME("about_to_popup"));
19961996

1997+
_pre_popup();
1998+
19971999
if (!get_embedder() && get_flag(FLAG_POPUP)) {
19982000
// Send a focus-out notification when opening a Window Manager Popup.
19992001
SceneTree *scene_tree = get_tree();

scene/main/window.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ class Window : public Viewport {
257257
static int root_layout_direction;
258258

259259
protected:
260+
virtual void _pre_popup() {} // Called after "about_to_popup", but before window is shown.
260261
virtual Rect2i _popup_adjust_rect() const { return Rect2i(); }
261262
virtual void _post_popup() {}
262263

0 commit comments

Comments
 (0)