Ver código fonte

ScrollBar: Simplify ScrollBar::scroll_to_position()

Nico Weber 5 anos atrás
pai
commit
326261094d
1 arquivos alterados com 4 adições e 12 exclusões
  1. 4 12
      Libraries/LibGUI/ScrollBar.cpp

+ 4 - 12
Libraries/LibGUI/ScrollBar.cpp

@@ -330,22 +330,14 @@ void ScrollBar::set_automatic_scrolling_active(bool active)
     }
 }
 
-void ScrollBar::scroll_to_position(const Gfx::IntPoint& position)
+void ScrollBar::scroll_to_position(const Gfx::IntPoint& click_position)
 {
     float range_size = m_max - m_min;
     float available = scrubbable_range_in_pixels();
 
-    float x = ::max(0, position.x() - button_width() - button_width() / 2);
-    float y = ::max(0, position.y() - button_height() - button_height() / 2);
-
-    float rel_x = x / available;
-    float rel_y = y / available;
-
-    if (orientation() == Orientation::Vertical)
-        set_value(m_min + rel_y * range_size);
-    else
-        set_value(m_min + rel_x * range_size);
-
+    float x_or_y = ::max(0, click_position.primary_offset_for_orientation(orientation()) - button_width() - button_width() / 2);
+    float rel_x_or_y = x_or_y / available;
+    set_value(m_min + rel_x_or_y * range_size);
 }
 
 void ScrollBar::mousemove_event(MouseEvent& event)