1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:48:10 +00:00

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
This commit is contained in:
Tom 2021-02-20 16:19:52 -07:00 committed by Andreas Kling
parent cb2db3710b
commit a0cbb9068b
3 changed files with 37 additions and 9 deletions

View file

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