Merge pull request #111801 from scgm0/PopupMenu-no-longer-ignores-max_size

Make `PopupMenu` respect `max_size`
This commit is contained in:
Thaddeus Crews
2025-10-27 10:01:43 -05:00

View File

@ -3230,15 +3230,20 @@ void PopupMenu::_pre_popup() {
} }
real_t popup_scale = MIN(scale.x, scale.y); real_t popup_scale = MIN(scale.x, scale.y);
set_content_scale_factor(popup_scale); set_content_scale_factor(popup_scale);
if (is_wrapping_controls()) {
Size2 minsize = get_contents_minimum_size() * 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. Size2 maxsize = get_max_size();
real_t max_h = get_max_size().height; if (maxsize.height > 0) {
if (max_h > 0) { minsize.height = MIN(minsize.height, maxsize.height);
minsize.height = MIN(minsize.height, max_h);
} }
if (maxsize.width > 0) {
minsize.width = MIN(minsize.width, maxsize.width);
}
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_min_size(minsize); // `height` is truncated here by the cast to Size2i for Window.min_size.
reset_size(); // Shrinkwraps to min size. reset_size(); // Shrinkwraps to min size.
} }
}
void PopupMenu::set_visible(bool p_visible) { void PopupMenu::set_visible(bool p_visible) {
bool native = global_menu.is_valid(); bool native = global_menu.is_valid();