You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2026-01-05 19:31:35 +00:00
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.)
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user