mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 20:45:14 +00:00
ScrollBar: Simplify ScrollBar::scroll_to_position()
This commit is contained in:
parent
8eee5312c5
commit
326261094d
Notes:
sideshowbarker
2024-07-19 03:52:26 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/326261094d8 Pull-request: https://github.com/SerenityOS/serenity/pull/3102
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
Reference in a new issue