~eliasnaur/gio

73b1e642098cc91ee9c8028365c1990982b6fe78 — Elias Naur 10 months ago b15a320
ui/input: change Queue to return Events one at a time

By returning all events, widgets that might return early from its
event loop might throw away subsequent events. Instead of requiring
those widgets to store the event list, convert input.Queue to step
through the available events one at a time.

Functional revert of 1735d5ced8937ff6f853aa8b01fed3140738c744.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
M ui/app/internal/input/router.go => ui/app/internal/input/router.go +9 -5
@@ 36,8 36,8 @@ type handlerEvents struct {
	updated  bool
}

func (q *Router) Events(k input.Key) []input.Event {
	return q.handlers.For(k)
func (q *Router) Next(k input.Key) (input.Event, bool) {
	return q.handlers.Next(k)
}

func (q *Router) Frame(ops *ui.Ops) {


@@ 125,10 125,14 @@ func (h *handlerEvents) Updated() bool {
	return u
}

func (h *handlerEvents) For(k input.Key) []input.Event {
func (h *handlerEvents) Next(k input.Key) (input.Event, bool) {
	events := h.handlers[k]
	delete(h.handlers, k)
	return events
	if len(events) == 0 {
		return nil, false
	}
	e := events[0]
	h.handlers[k] = events[1:]
	return e, true
}

func (h *handlerEvents) Clear() {

M ui/app/window.go => ui/app/window.go +2 -2
@@ 307,8 307,8 @@ func (w *Window) run(opts *WindowOptions) {
	}
}

func (q *Queue) Events(k input.Key) []input.Event {
	return q.q.Events(k)
func (q *Queue) Next(k input.Key) (input.Event, bool) {
	return q.q.Next(k)
}

func (_ driverEvent) ImplementsEvent() {}

M ui/gesture/gestures.go => ui/gesture/gestures.go +2 -2
@@ 83,7 83,7 @@ func (c *Click) Add(ops *ui.Ops) {

func (c *Click) Events(q input.Queue) []ClickEvent {
	var events []ClickEvent
	for _, evt := range q.Events(c) {
	for evt, ok := q.Next(c); ok; evt, ok = q.Next(c) {
		e, ok := evt.(pointer.Event)
		if !ok {
			continue


@@ 136,7 136,7 @@ func (s *Scroll) Scroll(cfg ui.Config, q input.Queue, axis Axis) int {
		return 0
	}
	total := 0
	for _, evt := range q.Events(s) {
	for evt, ok := q.Next(s); ok; evt, ok = q.Next(s) {
		e, ok := evt.(pointer.Event)
		if !ok {
			continue

M ui/input/input.go => ui/input/input.go +1 -1
@@ 7,7 7,7 @@ package input
// Queue maps an event handler key to the events
// available to the handler.
type Queue interface {
	Events(k Key) []Event
	Next(k Key) (Event, bool)
}

// Key is the stable identifier for an event handler.

M ui/text/editor.go => ui/text/editor.go +1 -1
@@ 113,7 113,7 @@ func (e *Editor) Next(cfg ui.Config, queue input.Queue) (EditorEvent, bool) {
	if (sdist > 0 && soff >= smax) || (sdist < 0 && soff <= smin) {
		e.scroller.Stop()
	}
	for _, ke := range queue.Events(e) {
	for ke, ok := queue.Next(e); ok; ke, ok = queue.Next(e) {
		e.blinkStart = cfg.Now()
		switch ke := ke.(type) {
		case key.FocusEvent: