1
0
mirror of https://github.com/godotengine/godot.git synced 2026-01-04 19:21:46 +00:00

Clamp menus at the bottom of the screen.

This commit is contained in:
Pāvels Nadtočajevs
2025-08-26 11:23:18 +03:00
parent f20ef37ccb
commit 90370a08ec
2 changed files with 14 additions and 0 deletions

View File

@@ -85,6 +85,16 @@ void MenuButton::show_popup() {
Transform2D xform = get_viewport()->get_popup_base_transform_native();
rect = xform.xform(rect);
}
Rect2i scr_usable = DisplayServer::get_singleton()->screen_get_usable_rect(get_window()->get_current_screen());
Size2i max_size;
if (scr_usable.has_area()) {
real_t max_h = scr_usable.get_end().y - rect.position.y;
real_t max_w = scr_usable.get_end().x - rect.position.x;
if (max_h >= 4 * rect.size.height && max_w >= rect.size.width) {
max_size = Size2i(max_w, max_h);
}
}
popup->set_max_size(max_size);
rect.size.height = 0;
popup->set_size(rect.size);
if (is_layout_rtl()) {

View File

@@ -3230,6 +3230,10 @@ void PopupMenu::_pre_popup() {
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.
real_t max_h = get_max_size().height;
if (max_h > 0) {
minsize.height = MIN(minsize.height, max_h);
}
set_min_size(minsize); // `height` is truncated here by the cast to Size2i for Window.min_size.
reset_size(); // Shrinkwraps to min size.
}