mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
GUI: Extract a ScrollBar::scroll_to_position method
This commit is contained in:
parent
d1571ce00a
commit
eab7712ab0
Notes:
sideshowbarker
2024-07-19 03:52:38 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/eab7712ab0c Pull-request: https://github.com/SerenityOS/serenity/pull/3102
2 changed files with 21 additions and 13 deletions
|
@ -294,19 +294,7 @@ void ScrollBar::mousedown_event(MouseEvent& event)
|
|||
return;
|
||||
}
|
||||
|
||||
float range_size = m_max - m_min;
|
||||
float available = scrubbable_range_in_pixels();
|
||||
|
||||
float x = ::max(0, event.position().x() - button_width() - button_width() / 2);
|
||||
float y = ::max(0, event.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);
|
||||
scroll_to_position(event.position());
|
||||
|
||||
m_scrubbing = true;
|
||||
m_scrub_start_value = value();
|
||||
|
@ -342,6 +330,24 @@ void ScrollBar::set_automatic_scrolling_active(bool active)
|
|||
}
|
||||
}
|
||||
|
||||
void ScrollBar::scroll_to_position(const Gfx::IntPoint& 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);
|
||||
|
||||
}
|
||||
|
||||
void ScrollBar::mousemove_event(MouseEvent& event)
|
||||
{
|
||||
auto old_hovered_component = m_hovered_component;
|
||||
|
|
|
@ -92,6 +92,8 @@ private:
|
|||
void on_automatic_scrolling_timer_fired();
|
||||
void set_automatic_scrolling_active(bool);
|
||||
|
||||
void scroll_to_position(const Gfx::IntPoint&);
|
||||
|
||||
int m_min { 0 };
|
||||
int m_max { 0 };
|
||||
int m_page { 0 };
|
||||
|
|
Loading…
Reference in a new issue