From 020eb27ff534161b1081171efba9f55b3dd7b90a Mon Sep 17 00:00:00 2001 From: Chris Waldon Date: Tue, 23 Aug 2022 09:47:54 -0400 Subject: [PATCH] widget: add useful state accessors to scrollbar This commit adds methods to widget.Scrollbar that enable consuming code to check if the scroll indicator is processing a drag gesture or if the scroll track is currently being hovered. These accessors enable scrollbar style types to have enough information to hide the scroll indicator when it isn't needed, whereas currently they cannot differentiate between a scrollbar indicator that is being dragged but hasn't moved since the last frame and a scrollbar indicator that is not being dragged. Signed-off-by: Chris Waldon --- widget/list.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/widget/list.go b/widget/list.go index 9c1b9562..8e351f8f 100644 --- a/widget/list.go +++ b/widget/list.go @@ -159,18 +159,32 @@ func (s *Scrollbar) AddDrag(ops *op.Ops) { s.drag.Add(ops) } -// IndicatorHovered returns whether the scroll indicator is currently being +// IndicatorHovered reports whether the scroll indicator is currently being // hovered by the pointer. func (s *Scrollbar) IndicatorHovered() bool { return s.indicator.Hovered() } +// TrackHovered reports whether the scroll track is being hovered by the +// pointer. +func (s *Scrollbar) TrackHovered() bool { + return s.track.Hovered() +} + // ScrollDistance returns the normalized distance that the scrollbar // moved during the last call to Layout as a value in the range [-1,1]. func (s *Scrollbar) ScrollDistance() float32 { return s.delta } +// Dragging reports whether the user is currently performing a drag gesture +// on the indicator. Note that this can return false while ScrollDistance is nonzero +// if the user scrolls using a different control than the scrollbar (like a mouse +// wheel). +func (s *Scrollbar) Dragging() bool { + return s.dragging +} + // List holds the persistent state for a layout.List that has a // scrollbar attached. type List struct {