Răsfoiți Sursa

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.)
Haoyu Qiu 5 ani în urmă
părinte
comite
5bf8e1e426
1 a modificat fișierele cu 10 adăugiri și 6 ștergeri
  1. 10 6
      scene/gui/popup_menu.cpp

+ 10 - 6
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;