From 108b663618e893c804c150205a21f2e8d95088c2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 25 Mar 2019 05:03:40 +0100 Subject: GScrollBar: Clicking in the gutter should jump directly to that position. I think I like how this feels but I'm not 100% sure yet, so I'm leaving the old feel in behind an #ifdef. --- LibGUI/GScrollBar.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'LibGUI') diff --git a/LibGUI/GScrollBar.cpp b/LibGUI/GScrollBar.cpp index 6b942f21c5..e0ae0eaf86 100644 --- a/LibGUI/GScrollBar.cpp +++ b/LibGUI/GScrollBar.cpp @@ -4,6 +4,8 @@ #include #include +//#define GUTTER_DOES_PAGEUP_PAGEDOWN + static const char* s_up_arrow_bitmap_data = { " " " # " @@ -210,6 +212,7 @@ void GScrollBar::mousedown_event(GMouseEvent& event) set_value(value() + m_step); return; } +#ifdef GUTTER_DOES_PAGEUP_PAGEDOWN if (has_scrubber() && upper_gutter_rect().contains(event.position())) { set_value(value() - m_big_step); return; @@ -218,6 +221,7 @@ void GScrollBar::mousedown_event(GMouseEvent& event) set_value(value() + m_big_step); return; } +#endif if (has_scrubber() && scrubber_rect().contains(event.position())) { m_scrubbing = true; m_scrub_start_value = value(); @@ -225,6 +229,27 @@ void GScrollBar::mousedown_event(GMouseEvent& event) update(); return; } +#ifndef GUTTER_DOES_PAGEUP_PAGEDOWN + if (has_scrubber()) { + float range_size = m_max - m_min; + float available = scrubbable_range_in_pixels(); + + float x = ::max(0, event.position().x() - button_size() - button_size() / 2); + float y = ::max(0, event.position().y() - button_size() - button_size() / 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); + + m_scrubbing = true; + m_scrub_start_value = value(); + m_scrub_origin = event.position(); + } +#endif } void GScrollBar::mouseup_event(GMouseEvent& event) -- cgit v1.2.3