gesture: report one event at a time

Events are now delivered one at a time, and this change makes the
corresponding change to gestures.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-11-25 16:38:48 -06:00
parent ab9f42c820
commit 8e209fd2eb
9 changed files with 82 additions and 36 deletions
+15 -3
View File
@@ -61,7 +61,11 @@ func (s *Scrollbar) Update(gtx layout.Context, axis layout.Axis, viewportStart,
}
// Jump to a click in the track.
for _, event := range s.track.Update(gtx.Source) {
for {
event, ok := s.track.Update(gtx.Source)
if !ok {
break
}
if event.Kind != gesture.KindClick ||
event.Modifiers != key.Modifiers(0) ||
event.NumClicks > 1 {
@@ -80,7 +84,11 @@ func (s *Scrollbar) Update(gtx layout.Context, axis layout.Axis, viewportStart,
}
// Offset to account for any drags.
for _, event := range s.drag.Update(gtx.Metric, gtx.Source, gesture.Axis(axis)) {
for {
event, ok := s.drag.Update(gtx.Metric, gtx.Source, gesture.Axis(axis))
if !ok {
break
}
switch event.Kind {
case pointer.Drag:
case pointer.Release, pointer.Cancel:
@@ -136,7 +144,11 @@ func (s *Scrollbar) Update(gtx layout.Context, axis layout.Axis, viewportStart,
// Process events from the indicator so that hover is
// detected properly.
_ = s.indicator.Update(gtx.Source)
for {
if _, ok := s.indicator.Update(gtx.Source); !ok {
break
}
}
}
// AddTrack configures the track click listener for the scrollbar to use