diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/gui/popup_menu.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 08faaf7d45..cffea527a5 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -191,16 +191,20 @@ void PopupMenu::_submenu_timeout() { void PopupMenu::_scroll(float p_factor, const Point2 &p_over) { - const float global_y = get_global_position().y; - int vseparation = get_constant("vseparation"); Ref<Font> font = get_font("font"); float dy = (vseparation + font->get_height()) * 3 * p_factor * get_global_transform().get_scale().y; - if (dy > 0 && global_y < 0) - dy = MIN(dy, -global_y - 1); - else if (dy < 0 && global_y + get_size().y * get_global_transform().get_scale().y > get_viewport_rect().size.y) - dy = -MIN(-dy, global_y + get_size().y * get_global_transform().get_scale().y - get_viewport_rect().size.y - 1); + if (dy > 0) { + const float global_top = get_global_position().y; + const float limit = global_top < 0 ? -global_top : 0; + dy = MIN(dy, limit); + } else if (dy < 0) { + const float global_bottom = get_global_position().y + get_size().y * get_global_transform().get_scale().y; + const float viewport_height = get_viewport_rect().size.y; + const float limit = global_bottom > viewport_height ? global_bottom - viewport_height: 0; + dy = -MIN(-dy, limit); + } set_position(get_position() + Vector2(0, dy)); Ref<InputEventMouseMotion> ie; |