diff options
author | Tom <tomut@yahoo.com> | 2021-02-20 16:19:52 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-21 01:06:17 +0100 |
commit | a0cbb9068b96a825db7e91697ab3d1c3ff94e2fd (patch) | |
tree | df6146d0156b3bc2e9abc94b8c42297bae6a047e /Userland/Libraries/LibGUI/ScrollableWidget.cpp | |
parent | cb2db3710b5e1fb64e08e6775cd56163beeec9c2 (diff) | |
download | serenity-a0cbb9068b96a825db7e91697ab3d1c3ff94e2fd.zip |
LibGUI: Let ScrollableWidget handle the wheel events of its ScrollBars
Route the ScrollBar's wheel event to the ScrollableWidget so it can
handle it itself. This allows it to handle it consistently (e.g.
speed) when the cursor is hovering the scroll bars rather than the
widget's contents.
Fixes #5419
Diffstat (limited to 'Userland/Libraries/LibGUI/ScrollableWidget.cpp')
-rw-r--r-- | Userland/Libraries/LibGUI/ScrollableWidget.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Userland/Libraries/LibGUI/ScrollableWidget.cpp b/Userland/Libraries/LibGUI/ScrollableWidget.cpp index f2b4cb571f..4a0be62737 100644 --- a/Userland/Libraries/LibGUI/ScrollableWidget.cpp +++ b/Userland/Libraries/LibGUI/ScrollableWidget.cpp @@ -31,14 +31,14 @@ namespace GUI { ScrollableWidget::ScrollableWidget() { - m_vertical_scrollbar = add<ScrollBar>(Orientation::Vertical); + m_vertical_scrollbar = add<ScrollableWidgetScrollBar>(*this, Orientation::Vertical); m_vertical_scrollbar->set_step(4); m_vertical_scrollbar->on_change = [this](int) { did_scroll(); update(); }; - m_horizontal_scrollbar = add<ScrollBar>(Orientation::Horizontal); + m_horizontal_scrollbar = add<ScrollableWidgetScrollBar>(*this, Orientation::Horizontal); m_horizontal_scrollbar->set_step(4); m_horizontal_scrollbar->set_page_step(30); m_horizontal_scrollbar->on_change = [this](int) { @@ -54,20 +54,25 @@ ScrollableWidget::~ScrollableWidget() { } -void ScrollableWidget::mousewheel_event(MouseEvent& event) +void ScrollableWidget::handle_wheel_event(MouseEvent& event, Widget& event_source) { if (!m_scrollbars_enabled) { event.ignore(); return; } // FIXME: The wheel delta multiplier should probably come from... somewhere? - if (event.shift()) { + if (event.shift() || &event_source == m_horizontal_scrollbar.ptr()) { horizontal_scrollbar().set_value(horizontal_scrollbar().value() + event.wheel_delta() * 60); } else { vertical_scrollbar().set_value(vertical_scrollbar().value() + event.wheel_delta() * 20); } } +void ScrollableWidget::mousewheel_event(MouseEvent& event) +{ + handle_wheel_event(event, *this); +} + void ScrollableWidget::custom_layout() { auto inner_rect = frame_inner_rect_for_size(size()); |