ScrollBar: Simplify ScrollBar::scroll_to_position()

This commit is contained in:
Nico Weber 2020-08-11 21:33:03 -04:00 committed by Andreas Kling
parent 8eee5312c5
commit 326261094d
Notes: sideshowbarker 2024-07-19 03:52:26 +09:00

View file

@ -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)