summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorHaoyu Qiu <timothyqiu32@gmail.com>2019-12-10 09:49:02 +0800
committerHaoyu Qiu <timothyqiu32@gmail.com>2019-12-10 09:49:02 +0800
commit5bf8e1e426126a71e3a50389fc11734d0456b81f (patch)
tree0e93fafdbbaa25712995b1b74ed5b7ebe4ee855f /scene
parent269145a346bddae5cbbf00fd17b6c8eac4cd4665 (diff)
Fixes long popup menu scroll behavior
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.)
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/popup_menu.cpp16
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;