mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
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:
+5
-1
@@ -116,7 +116,11 @@ func (b *Clickable) Update(gtx layout.Context) (Click, bool) {
|
||||
NumClicks: c,
|
||||
}, true
|
||||
}
|
||||
for _, e := range b.click.Update(gtx.Source) {
|
||||
for {
|
||||
e, ok := b.click.Update(gtx.Source)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
switch e.Kind {
|
||||
case gesture.KindClick:
|
||||
if l := len(b.history); l > 0 {
|
||||
|
||||
+5
-1
@@ -53,7 +53,11 @@ func (d *Draggable) Dragging() bool {
|
||||
// requested to offer data, if any
|
||||
func (d *Draggable) Update(gtx layout.Context) (mime string, requested bool) {
|
||||
pos := d.pos
|
||||
for _, ev := range d.drag.Update(gtx.Metric, gtx.Source, gesture.Both) {
|
||||
for {
|
||||
ev, ok := d.drag.Update(gtx.Metric, gtx.Source, gesture.Both)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
switch ev.Kind {
|
||||
case pointer.Press:
|
||||
d.click = ev.Position
|
||||
|
||||
+10
-2
@@ -316,10 +316,18 @@ func (e *Editor) processPointer(gtx layout.Context) {
|
||||
|
||||
func (e *Editor) clickDragEvents(gtx layout.Context) []event.Event {
|
||||
var combinedEvents []event.Event
|
||||
for _, evt := range e.clicker.Update(gtx.Source) {
|
||||
for {
|
||||
evt, ok := e.clicker.Update(gtx.Source)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
combinedEvents = append(combinedEvents, evt)
|
||||
}
|
||||
for _, evt := range e.dragger.Update(gtx.Metric, gtx.Source, gesture.Both) {
|
||||
for {
|
||||
evt, ok := e.dragger.Update(gtx.Metric, gtx.Source, gesture.Both)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
combinedEvents = append(combinedEvents, evt)
|
||||
}
|
||||
return combinedEvents
|
||||
|
||||
+5
-1
@@ -47,7 +47,11 @@ func (e *Enum) Update(gtx layout.Context) bool {
|
||||
e.hovering = false
|
||||
changed := false
|
||||
for _, state := range e.keys {
|
||||
for _, ev := range state.click.Update(gtx.Source) {
|
||||
for {
|
||||
ev, ok := state.click.Update(gtx.Source)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
switch ev.Kind {
|
||||
case gesture.KindPress:
|
||||
if ev.Source == pointer.Mouse {
|
||||
|
||||
+5
-1
@@ -48,7 +48,11 @@ func (f *Float) Layout(gtx layout.Context, axis layout.Axis, pointerMargin unit.
|
||||
// The range of f is set by the minimum constraints main axis value.
|
||||
func (f *Float) Update(gtx layout.Context) bool {
|
||||
changed := false
|
||||
for _, e := range f.drag.Update(gtx.Metric, gtx.Source, gesture.Axis(f.axis)) {
|
||||
for {
|
||||
e, ok := f.drag.Update(gtx.Metric, gtx.Source, gesture.Axis(f.axis))
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
if f.length > 0 && (e.Kind == pointer.Press || e.Kind == pointer.Drag) {
|
||||
pos := e.Position.X
|
||||
if f.axis == layout.Vertical {
|
||||
|
||||
+15
-3
@@ -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
|
||||
|
||||
+10
-2
@@ -283,10 +283,18 @@ func (e *Selectable) processPointer(gtx layout.Context) {
|
||||
|
||||
func (e *Selectable) clickDragEvents(gtx layout.Context) []event.Event {
|
||||
var combinedEvents []event.Event
|
||||
for _, evt := range e.clicker.Update(gtx.Source) {
|
||||
for {
|
||||
evt, ok := e.clicker.Update(gtx.Source)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
combinedEvents = append(combinedEvents, evt)
|
||||
}
|
||||
for _, evt := range e.dragger.Update(gtx.Metric, gtx.Source, gesture.Both) {
|
||||
for {
|
||||
evt, ok := e.dragger.Update(gtx.Metric, gtx.Source, gesture.Both)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
combinedEvents = append(combinedEvents, evt)
|
||||
}
|
||||
return combinedEvents
|
||||
|
||||
Reference in New Issue
Block a user