đź“ťGio event handling

Gio uses the Ops to subscribe to events as well.

var tag = new(bool)
var pressed = false

func doButton(ops *op.Ops, q event.Queue) {
	stack := op.Push(ops)
	defer stack.Pop()

	// this will iterate over all events that occurred since the previous frame
	for _, ev = range q.Events(tag) {
		if x, ok := ev.(pointer.Event); ok {
			switch x.Type {
			case pointer.Press:
				pressed = true
			case pointer.Release:
				pressed = false
			}
		}
	}

	// Limit the area of interest to 100x100 rectangle
	pointer.Rect(image.Rect(0, 0, 100, 100)).Add(ops)
	// Subscribe for Press|Release events using tag
	pointer.InputOp{
		Tag: tag,
		Types: pointer.Press | pointer.Release,
	}.Add(ops)
}

q.Events will return all the events that occurred since the previous frame. The zone of interest is limited by pointer.Rect.

That’s nice because it solves a couple of problems:

Cons:

Backlinks