Fix shadow offset larger than shadow size in PopupMenu and PopupPanel.

Panel shadow offsets larger than shadow size should no longer place the
panel edges outside its window.
This commit is contained in:
Ibrahn Sahir 2025-04-10 12:31:06 +01:00
parent c374ce211c
commit 147b8415b1
2 changed files with 15 additions and 15 deletions

View file

@ -307,7 +307,7 @@ Rect2i PopupPanel::_popup_adjust_rect() const {
_update_child_rects(); _update_child_rects();
if (is_layout_rtl()) { if (is_layout_rtl()) {
current.position -= Vector2(Math::abs(panel->get_offset(SIDE_RIGHT)), panel->get_offset(SIDE_TOP)) * get_content_scale_factor(); current.position -= Vector2(-panel->get_offset(SIDE_RIGHT), panel->get_offset(SIDE_TOP)) * get_content_scale_factor();
} else { } else {
current.position -= Vector2(panel->get_offset(SIDE_LEFT), panel->get_offset(SIDE_TOP)) * get_content_scale_factor(); current.position -= Vector2(panel->get_offset(SIDE_LEFT), panel->get_offset(SIDE_TOP)) * get_content_scale_factor();
} }
@ -337,14 +337,14 @@ void PopupPanel::_update_shadow_offsets() const {
// Offset the background panel so it leaves space inside the window for the shadows to be drawn. // Offset the background panel so it leaves space inside the window for the shadows to be drawn.
const Point2 shadow_offset = sb->get_shadow_offset(); const Point2 shadow_offset = sb->get_shadow_offset();
if (is_layout_rtl()) { if (is_layout_rtl()) {
panel->set_offset(SIDE_LEFT, shadow_size + shadow_offset.x); panel->set_offset(SIDE_LEFT, MAX(0, shadow_size + shadow_offset.x));
panel->set_offset(SIDE_RIGHT, -shadow_size + shadow_offset.x); panel->set_offset(SIDE_RIGHT, MIN(0, -shadow_size + shadow_offset.x));
} else { } else {
panel->set_offset(SIDE_LEFT, shadow_size - shadow_offset.x); panel->set_offset(SIDE_LEFT, MAX(0, shadow_size - shadow_offset.x));
panel->set_offset(SIDE_RIGHT, -shadow_size - shadow_offset.x); panel->set_offset(SIDE_RIGHT, MIN(0, -shadow_size - shadow_offset.x));
} }
panel->set_offset(SIDE_TOP, shadow_size - shadow_offset.y); panel->set_offset(SIDE_TOP, MAX(0, shadow_size - shadow_offset.y));
panel->set_offset(SIDE_BOTTOM, -shadow_size - shadow_offset.y); panel->set_offset(SIDE_BOTTOM, MIN(0, -shadow_size - shadow_offset.y));
} }
void PopupPanel::_update_child_rects() const { void PopupPanel::_update_child_rects() const {

View file

@ -352,7 +352,7 @@ void PopupMenu::_activate_submenu(int p_over, bool p_by_keyboard) {
const float win_scale = get_content_scale_factor(); const float win_scale = get_content_scale_factor();
const Point2 panel_ofs_start = Point2(panel->get_offset(SIDE_LEFT), panel->get_offset(SIDE_TOP)) * win_scale; const Point2 panel_ofs_start = Point2(panel->get_offset(SIDE_LEFT), panel->get_offset(SIDE_TOP)) * win_scale;
const Point2 panel_ofs_end = Point2(panel->get_offset(SIDE_RIGHT), panel->get_offset(SIDE_BOTTOM)).abs() * win_scale; const Point2 panel_ofs_end = Point2(-panel->get_offset(SIDE_RIGHT), -panel->get_offset(SIDE_BOTTOM)) * win_scale;
const Point2 this_pos = get_position() + Point2(0, panel_ofs_start.y + theme_cache.panel_style->get_margin(SIDE_TOP) * win_scale); const Point2 this_pos = get_position() + Point2(0, panel_ofs_start.y + theme_cache.panel_style->get_margin(SIDE_TOP) * win_scale);
Rect2 this_rect(this_pos, get_size()); Rect2 this_rect(this_pos, get_size());
@ -1045,14 +1045,14 @@ void PopupMenu::_update_shadow_offsets() const {
// Offset the background panel so it leaves space inside the window for the shadows to be drawn. // Offset the background panel so it leaves space inside the window for the shadows to be drawn.
const Point2 shadow_offset = sb->get_shadow_offset(); const Point2 shadow_offset = sb->get_shadow_offset();
if (is_layout_rtl()) { if (is_layout_rtl()) {
panel->set_offset(SIDE_LEFT, shadow_size + shadow_offset.x); panel->set_offset(SIDE_LEFT, MAX(0, shadow_size + shadow_offset.x));
panel->set_offset(SIDE_RIGHT, -shadow_size + shadow_offset.x); panel->set_offset(SIDE_RIGHT, MIN(0, -shadow_size + shadow_offset.x));
} else { } else {
panel->set_offset(SIDE_LEFT, shadow_size - shadow_offset.x); panel->set_offset(SIDE_LEFT, MAX(0, shadow_size - shadow_offset.x));
panel->set_offset(SIDE_RIGHT, -shadow_size - shadow_offset.x); panel->set_offset(SIDE_RIGHT, MIN(0, -shadow_size - shadow_offset.x));
} }
panel->set_offset(SIDE_TOP, shadow_size - shadow_offset.y); panel->set_offset(SIDE_TOP, MAX(0, shadow_size - shadow_offset.y));
panel->set_offset(SIDE_BOTTOM, -shadow_size - shadow_offset.y); panel->set_offset(SIDE_BOTTOM, MIN(0, -shadow_size - shadow_offset.y));
} }
Rect2i PopupMenu::_popup_adjust_rect() const { Rect2i PopupMenu::_popup_adjust_rect() const {
@ -1066,7 +1066,7 @@ Rect2i PopupMenu::_popup_adjust_rect() const {
_update_shadow_offsets(); _update_shadow_offsets();
if (is_layout_rtl()) { if (is_layout_rtl()) {
current.position -= Vector2(Math::abs(panel->get_offset(SIDE_RIGHT)), panel->get_offset(SIDE_TOP)) * get_content_scale_factor(); current.position -= Vector2(-panel->get_offset(SIDE_RIGHT), panel->get_offset(SIDE_TOP)) * get_content_scale_factor();
} else { } else {
current.position -= Vector2(panel->get_offset(SIDE_LEFT), panel->get_offset(SIDE_TOP)) * get_content_scale_factor(); current.position -= Vector2(panel->get_offset(SIDE_LEFT), panel->get_offset(SIDE_TOP)) * get_content_scale_factor();
} }