Skip to content

Commit

Permalink
Fixes long popup menu scroll behavior
Browse files Browse the repository at this point in the history
Popup menus longer than the viewport have stange behaviors before this
fix:

* They always have one pixel outside the viewport.
* You can scroll down the long menu even if bottom outside screen and
top inside the screen. (Only menus one pixel above the screen is limited
to scroll down.)
  • Loading branch information
timothyqiu committed Dec 10, 2019
1 parent 269145a commit 5bf8e1e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions scene/gui/popup_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5bf8e1e

Please sign in to comment.