a6483a421ff651b1362cfa53d6300ac01a316a4c — Elias Naur 30 days ago 9520a92
ui/gesture: replace Click.Events with Click.Next

Everything else was converted to use the Next
style event API, but Click was forgotten.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2 files changed, 6 insertions(+), 7 deletions(-)

M ui/gesture/gesture.go
M ui/text/editor.go
M ui/gesture/gesture.go => ui/gesture/gesture.go +5 -6
@@ 124,9 124,8 @@ return c.state
  }
  
- // Events reports all click events for the available events.
- func (c *Click) Events(q input.Queue) []ClickEvent {
- 	var events []ClickEvent
+ // Next returns the next click event, if any.
+ func (c *Click) Next(q input.Queue) (ClickEvent, bool) {
  	for evt, ok := q.Next(c); ok; evt, ok = q.Next(c) {
  		e, ok := evt.(pointer.Event)
  		if !ok {


@@ 137,7 136,7 @@ wasPressed := c.state == StatePressed
  			c.state = StateNormal
  			if wasPressed {
- 				events = append(events, ClickEvent{Type: TypeClick, Position: e.Position, Source: e.Source})
+ 				return ClickEvent{Type: TypeClick, Position: e.Position, Source: e.Source}, true
  			}
  		case pointer.Cancel:
  			c.state = StateNormal


@@ 146,7 145,7 @@ break
  			}
  			c.state = StatePressed
- 			events = append(events, ClickEvent{Type: TypePress, Position: e.Position, Source: e.Source})
+ 			return ClickEvent{Type: TypePress, Position: e.Position, Source: e.Source}, true
  		case pointer.Move:
  			if c.state == StatePressed && !e.Hit {
  				c.state = StateNormal


@@ 155,7 154,7 @@ }
  		}
  	}
- 	return events
+ 	return ClickEvent{}, false
  }
  
  // Add the handler to the operation list to receive scroll events.

M ui/text/editor.go => ui/text/editor.go +1 -1
@@ 107,7 107,7 @@ e.scrollOff.Y += sdist
  		soff = e.scrollOff.Y
  	}
- 	for _, evt := range e.clicker.Events(queue) {
+ 	for evt, ok := e.clicker.Next(queue); ok; evt, ok = e.clicker.Next(queue) {
  		switch {
  		case evt.Type == gesture.TypePress && evt.Source == pointer.Mouse,
  			evt.Type == gesture.TypeClick && evt.Source == pointer.Touch: