From a9136d0f47d570ac9b7802999ba561377723177a Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 25 Aug 2020 13:29:52 -0400 Subject: [PATCH] LibGUI: Only paint ScrollBar hover states if a component is pressed While left-mouse is pressed on any component (arrows, gutter, scrubber), don't draw hover states for components other than the pressed component. For example, while clicking the arrow-down button and then dragging around, the arrow-up button and the scrubber now aren't highlighted. This also means that during a gutter drag session, the scrubber isn't highlighted while it's under the mouse cursor. That makes sense, since we get the gutter drag behavior, not the scrubber drag behavior, in this case. The highlight is supposed to indicate "clickability", but if the mouse is already down, they can't be clicked. Now that I check for it, this seems to match the scrollbar behavior on Windows. --- Libraries/LibGUI/ScrollBar.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Libraries/LibGUI/ScrollBar.cpp b/Libraries/LibGUI/ScrollBar.cpp index c727d9cfc9..c558c52db1 100644 --- a/Libraries/LibGUI/ScrollBar.cpp +++ b/Libraries/LibGUI/ScrollBar.cpp @@ -235,13 +235,17 @@ void ScrollBar::paint_event(PaintEvent& event) Painter painter(*this); painter.add_clip_rect(event.rect()); + Component hovered_component_for_painting = m_hovered_component; + if (m_pressed_component != Component::None && m_hovered_component != m_pressed_component) + hovered_component_for_painting = Component::None; + painter.fill_rect_with_dither_pattern(rect(), palette().button().lightened(1.3f), palette().button()); bool decrement_pressed = m_pressed_component == Component::DecrementButton; bool increment_pressed = m_pressed_component == Component::IncrementButton; - Gfx::StylePainter::paint_button(painter, decrement_button_rect(), palette(), Gfx::ButtonStyle::Normal, decrement_pressed, m_hovered_component == Component::DecrementButton); - Gfx::StylePainter::paint_button(painter, increment_button_rect(), palette(), Gfx::ButtonStyle::Normal, increment_pressed, m_hovered_component == Component::IncrementButton); + Gfx::StylePainter::paint_button(painter, decrement_button_rect(), palette(), Gfx::ButtonStyle::Normal, decrement_pressed, hovered_component_for_painting == Component::DecrementButton); + Gfx::StylePainter::paint_button(painter, increment_button_rect(), palette(), Gfx::ButtonStyle::Normal, increment_pressed, hovered_component_for_painting == Component::IncrementButton); if (length(orientation()) > default_button_size()) { auto decrement_location = decrement_button_rect().location().translated(3, 3); @@ -256,7 +260,7 @@ void ScrollBar::paint_event(PaintEvent& event) } if (has_scrubber()) - Gfx::StylePainter::paint_button(painter, scrubber_rect(), palette(), Gfx::ButtonStyle::Normal, false, m_hovered_component == Component::Scrubber || m_pressed_component == Component::Scrubber); + Gfx::StylePainter::paint_button(painter, scrubber_rect(), palette(), Gfx::ButtonStyle::Normal, false, hovered_component_for_painting == Component::Scrubber || m_pressed_component == Component::Scrubber); } void ScrollBar::on_automatic_scrolling_timer_fired()