mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:38:11 +00:00
ScrollBar: Simplify ScrollBar::scroll_to_position()
This commit is contained in:
parent
8eee5312c5
commit
326261094d
1 changed files with 4 additions and 12 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue