Commit Graph

16 Commits

Author SHA1 Message Date
Nico Weber
23e2944aa4 LibGUI: Make ScrollBar track the currently pressed component
And remove the now-redundant members m_scrubbing, m_scrubber_in_use,
and m_automatic_scrolling_kind.

This also made it clear that we weren't canceling the autoscroll
timer if the scrollbar got disabled while it was scrolling, so
this fixes that too.
2020-08-25 20:20:45 +02:00
Nico Weber
98dd034c29 LibGUI: Make scrollbars keep scrolling by page while clicking the gutter
Note that m_hovered_component is only updated on mouse move, not while
just keeping left down. It's arguably wrong to update it on mouse move
while the mouse is down, I'll probably change things so that it doesn't
update there either.

The behavior on click-in-gutter-keep-left-down-then-move-mouse varies
a surprising amount between platforms. This implements the macOS
behavior where the scrubber follows the mouse direction while scrolling
by pages. (To be precise, it's the macOS behavior of Finder and Preview,
Safari has Windows's scrollbar behavior).

On Windows, the first click locks in the scroll direction and then
dragging the mouse off the scrubber in that direction makes the
scroll continue, but dragging it off the other direction has no effect.
I see no reason for that behavior.
2020-08-25 18:09:56 +02:00
Nico Weber
0a462dac14 LibGUI: Keep scrollbar timer active while mouse is down
Rather than disable and re-enable the timer, always keep it active
and make it do collision checks to decide if it should have an effect.

This is because set_automatic_scrolling_active(true) calls the
timeout callback immediately before starting the timer, and
when clicking the gutter this callback could disable the timer
again (if the first page scroll put the scrubber under the cursor).

Intead of making set_automatic_scrolling_active() work when it's
called reentrantly (which is easy: just swap the order of
on_automatic_scrolling_timer_fired() and timer->start() so that
on_automatic_scrolling_timer_fired() can immediately stop the
timer again, but it's confusing), make the timer check if it
should do anything.

This is keyed off m_last_mouse_position instead of
m_hovered_component because m_hovered_component is a visual state
and we arguably shouldn't modify it while the left mouse button
is down (as it indicated what part is activated on click).
2020-08-25 18:09:56 +02:00
Nico Weber
b96759930d LibGUI: Extract ScrollBar::update_hovered_component() method 2020-08-25 18:09:56 +02:00
Nico Weber
bf0b5c3c5a LibGUI: Extract ScrollBar::component_at_position() method
...and use it in mousedown_event(), which allows putting in
stricter asserts.
2020-08-25 18:09:56 +02:00
Nico Weber
ecf6cbbd02 LibGUI: Make AutomaticScrollingKind a paramter on set_automatic_scrolling_active
Most callers of set_automatic_scrolling_active() also change
m_automatic_scrolling_kind, and it makes it possible to make timer
behavior dependent on the autoscroll kind later.
2020-08-25 16:21:26 +02:00
Nico Weber
129816e056 LibGUI: In ScrollBar, rename AutomaticScrollingDirection to AutomaticScrollingKind
Also rename Decrement to DecrementButton and Increment to
IncrementButton.
2020-08-25 16:21:26 +02:00
Nico Weber
cdf1282419 ScrollBar: Let clicking the gutter scroll by one page
Shift-clicking has the old behavior of jumping to the click position.

This matches scrollbar behavior in macOS and Windows, and in many Linux apps.
2020-08-12 11:02:30 +02:00
Nico Weber
8eee5312c5 GUI: Rename ScrollBar::scrubber_size() to ScrollBar::visibile_scrubber_size() 2020-08-12 11:02:30 +02:00
Nico Weber
eab7712ab0 GUI: Extract a ScrollBar::scroll_to_position method 2020-08-12 11:02:30 +02:00
Tom
fc568ea13a LibGUI: Make scrollbar thumb size relative to content size
In order to calculate a thumb size that is a representation
of the visible portion (page) of the content, that information
needs to be taken into account.
2020-07-09 21:56:45 +02:00
Andreas Kling
116cf92156 LibGfx: Rename Rect,Point,Size => IntRect,IntPoint,IntSize
This fits nicer with FloatRect,FloatPoint,FloatSize and gives a much
better visual clue about what type of metric is being used.
2020-06-10 10:59:04 +02:00
Andreas Kling
c5d913970a LibGUI: Remove parent parameter to GUI::Widget constructor 2020-02-23 12:27:53 +01:00
Andreas Kling
428582e805 LibGUI: Don't require passing a parent to widget constructors
This is a step towards using Core::Object::add<T> more, which takes
care of parenting the newly created child automatically.
2020-02-23 11:10:52 +01:00
Andreas Kling
2143da6434 LibGUI: Add forwarding header
This patch adds <LibGUI/Forward.h> and uses it a bunch.
It also dragged various header dependency reduction changes into it.
2020-02-16 09:41:56 +01:00
Andreas Kling
6a9cc66b97 LibGUI: Remove leading G from filenames 2020-02-06 20:33:02 +01:00