~eliasnaur/gio

020eb27ff534161b1081171efba9f55b3dd7b90a — Chris Waldon 9 months ago 911b526
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 <christopher.waldon.dev@gmail.com>
1 files changed, 15 insertions(+), 1 deletions(-)

M widget/list.go
M widget/list.go => widget/list.go +15 -1
@@ 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 {