Skip to content

Commit 74e869c

Browse files
committed
Merge pull request #109981 from bruvzg/clamp_menui_h
Clamp menus at the bottom of the screen.
2 parents e15210b + 90370a0 commit 74e869c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

scene/gui/menu_button.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ void MenuButton::show_popup() {
8585
Transform2D xform = get_viewport()->get_popup_base_transform_native();
8686
rect = xform.xform(rect);
8787
}
88+
Rect2i scr_usable = DisplayServer::get_singleton()->screen_get_usable_rect(get_window()->get_current_screen());
89+
Size2i max_size;
90+
if (scr_usable.has_area()) {
91+
real_t max_h = scr_usable.get_end().y - rect.position.y;
92+
real_t max_w = scr_usable.get_end().x - rect.position.x;
93+
if (max_h >= 4 * rect.size.height && max_w >= rect.size.width) {
94+
max_size = Size2i(max_w, max_h);
95+
}
96+
}
97+
popup->set_max_size(max_size);
8898
rect.size.height = 0;
8999
popup->set_size(rect.size);
90100
if (is_layout_rtl()) {

scene/gui/popup_menu.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3230,6 +3230,10 @@ void PopupMenu::_pre_popup() {
32303230
set_content_scale_factor(popup_scale);
32313231
Size2 minsize = get_contents_minimum_size() * popup_scale;
32323232
minsize.height = Math::ceil(minsize.height); // Ensures enough height at fractional content scales to prevent the v_scroll_bar from showing.
3233+
real_t max_h = get_max_size().height;
3234+
if (max_h > 0) {
3235+
minsize.height = MIN(minsize.height, max_h);
3236+
}
32333237
set_min_size(minsize); // `height` is truncated here by the cast to Size2i for Window.min_size.
32343238
reset_size(); // Shrinkwraps to min size.
32353239
}

0 commit comments

Comments
 (0)