~eliasnaur/gio

4f45d9a56753fd5c3f6cf773779a266af584a752 — Elias Naur 3 months ago 24f69bf
io/router: rename Router.Add to the more specific Queue

Signed-off-by: Elias Naur <mail@eliasnaur.com>
M app/window.go => app/window.go +2 -2
@@ 180,7 180,7 @@ func (w *Window) processFrame(frameStart time.Time, size image.Point, frame *op.
		frameDur = frameDur.Truncate(100 * time.Microsecond)
		q := 100 * time.Microsecond
		timings := fmt.Sprintf("tot:%7s %s", frameDur.Round(q), w.loop.Summary())
		w.queue.q.Add(profile.Event{Timings: timings})
		w.queue.q.Queue(profile.Event{Timings: timings})
	}
	if t, ok := w.queue.q.WakeupTime(); ok {
		w.setNextFrame(t)


@@ 420,7 420,7 @@ func (w *Window) run(opts *window.Options) {
				w.ack <- struct{}{}
				return
			case event.Event:
				if w.queue.q.Add(e2) {
				if w.queue.q.Queue(e2) {
					w.setNextFrame(time.Time{})
					w.updateAnimation()
				}

M gesture/gesture_test.go => gesture/gesture_test.go +1 -1
@@ 43,7 43,7 @@ func TestMouseClicks(t *testing.T) {

			var r router.Router
			r.Frame(&ops)
			r.Add(tc.events...)
			r.Queue(tc.events...)

			events := click.Events(&r)
			clicks := filterMouseClicks(events)

M io/router/clipboard_test.go => io/router/clipboard_test.go +2 -2
@@ 17,7 17,7 @@ func TestClipboardDuplicateEvent(t *testing.T) {

	router.Frame(ops)
	event := clipboard.Event{Text: "Test"}
	router.Add(event)
	router.Queue(event)
	assertClipboardReadOp(t, router, 0)
	assertClipboardEvent(t, router.Events(&handler[0]), true)
	assertClipboardEvent(t, router.Events(&handler[1]), true)


@@ 64,7 64,7 @@ func TestQueueProcessReadClipboard(t *testing.T) {
	router.Frame(ops)
	// Send the clipboard event
	event := clipboard.Event{Text: "Text 2"}
	router.Add(event)
	router.Queue(event)
	assertClipboardReadOp(t, router, 0)
	assertClipboardEvent(t, router.Events(&handler[0]), true)
	ops.Reset()

M io/router/key_test.go => io/router/key_test.go +1 -1
@@ 122,7 122,7 @@ func TestKeyRemoveFocus(t *testing.T) {

	// Add some key events:
	event := event.Event(key.Event{Name: key.NameTab, Modifiers: key.ModShortcut, State: key.Press})
	r.Add(event)
	r.Queue(event)

	assertKeyEvent(t, r.Events(&handlers[0]), true, event)
	assertKeyEvent(t, r.Events(&handlers[1]), false)

M io/router/pointer_test.go => io/router/pointer_test.go +25 -25
@@ 42,7 42,7 @@ func TestPointerDrag(t *testing.T) {

	var r Router
	r.Frame(&ops)
	r.Add(
	r.Queue(
		// Press.
		pointer.Event{
			Type:     pointer.Press,


@@ 73,7 73,7 @@ func TestPointerMove(t *testing.T) {

	var r Router
	r.Frame(&ops)
	r.Add(
	r.Queue(
		// Hit both handlers.
		pointer.Event{
			Type:     pointer.Move,


@@ 105,7 105,7 @@ func TestPointerTypes(t *testing.T) {

	var r Router
	r.Frame(&ops)
	r.Add(
	r.Queue(
		pointer.Event{
			Type:     pointer.Press,
			Position: f32.Pt(50, 50),


@@ 135,7 135,7 @@ func TestPointerPriority(t *testing.T) {

	var r Router
	r.Frame(&ops)
	r.Add(
	r.Queue(
		// Hit both handlers.
		pointer.Event{
			Type:     pointer.Scroll,


@@ 174,7 174,7 @@ func TestPointerEnterLeave(t *testing.T) {
	var r Router
	r.Frame(&ops)
	// Hit both handlers.
	r.Add(
	r.Queue(
		pointer.Event{
			Type:     pointer.Move,
			Position: f32.Pt(50, 50),


@@ 187,7 187,7 @@ func TestPointerEnterLeave(t *testing.T) {
	assertEventSequence(t, r.Events(handler2), pointer.Cancel, pointer.Enter, pointer.Move)

	// Leave the second area by moving into the first.
	r.Add(
	r.Queue(
		pointer.Event{
			Type:     pointer.Move,
			Position: f32.Pt(45, 45),


@@ 198,7 198,7 @@ func TestPointerEnterLeave(t *testing.T) {
	assertEventSequence(t, r.Events(handler2), pointer.Leave)

	// Move, but stay within the same hit area.
	r.Add(
	r.Queue(
		pointer.Event{
			Type:     pointer.Move,
			Position: f32.Pt(40, 40),


@@ 208,7 208,7 @@ func TestPointerEnterLeave(t *testing.T) {
	assertEventSequence(t, r.Events(handler2))

	// Move outside of both inputs.
	r.Add(
	r.Queue(
		pointer.Event{
			Type:     pointer.Move,
			Position: f32.Pt(300, 300),


@@ 218,7 218,7 @@ func TestPointerEnterLeave(t *testing.T) {
	assertEventSequence(t, r.Events(handler2))

	// Check that a Press event generates Enter Events.
	r.Add(
	r.Queue(
		pointer.Event{
			Type:     pointer.Press,
			Position: f32.Pt(125, 125),


@@ 228,7 228,7 @@ func TestPointerEnterLeave(t *testing.T) {
	assertEventSequence(t, r.Events(handler2), pointer.Enter, pointer.Press)

	// Check that a drag only affects the participating handlers.
	r.Add(
	r.Queue(
		// Leave
		pointer.Event{
			Type:     pointer.Move,


@@ 244,7 244,7 @@ func TestPointerEnterLeave(t *testing.T) {
	assertEventSequence(t, r.Events(handler2), pointer.Leave, pointer.Drag, pointer.Enter, pointer.Drag)

	// Check that a Release event generates Enter/Leave Events.
	r.Add(
	r.Queue(
		pointer.Event{
			Type: pointer.Release,
			Position: f32.Pt(25,


@@ 273,7 273,7 @@ func TestMultipleAreas(t *testing.T) {
	var r Router
	r.Frame(&ops)
	// Hit first area, then second area, then both.
	r.Add(
	r.Queue(
		pointer.Event{
			Type:     pointer.Move,
			Position: f32.Pt(25, 25),


@@ 308,7 308,7 @@ func TestPointerEnterLeaveNested(t *testing.T) {
	var r Router
	r.Frame(&ops)
	// Hit both handlers.
	r.Add(
	r.Queue(
		pointer.Event{
			Type:     pointer.Move,
			Position: f32.Pt(50, 50),


@@ 320,7 320,7 @@ func TestPointerEnterLeaveNested(t *testing.T) {
	assertEventSequence(t, r.Events(handler2), pointer.Cancel, pointer.Enter, pointer.Move)

	// Leave the second area by moving into the first.
	r.Add(
	r.Queue(
		pointer.Event{
			Type:     pointer.Move,
			Position: f32.Pt(20, 20),


@@ 330,7 330,7 @@ func TestPointerEnterLeaveNested(t *testing.T) {
	assertEventSequence(t, r.Events(handler2), pointer.Leave)

	// Move, but stay within the same hit area.
	r.Add(
	r.Queue(
		pointer.Event{
			Type:     pointer.Move,
			Position: f32.Pt(10, 10),


@@ 340,7 340,7 @@ func TestPointerEnterLeaveNested(t *testing.T) {
	assertEventSequence(t, r.Events(handler2))

	// Move outside of both inputs.
	r.Add(
	r.Queue(
		pointer.Event{
			Type:     pointer.Move,
			Position: f32.Pt(200, 200),


@@ 350,7 350,7 @@ func TestPointerEnterLeaveNested(t *testing.T) {
	assertEventSequence(t, r.Events(handler2))

	// Check that a Press event generates Enter Events.
	r.Add(
	r.Queue(
		pointer.Event{
			Type:     pointer.Press,
			Position: f32.Pt(50, 50),


@@ 360,7 360,7 @@ func TestPointerEnterLeaveNested(t *testing.T) {
	assertEventSequence(t, r.Events(handler2), pointer.Enter, pointer.Press)

	// Check that a Release event generates Enter/Leave Events.
	r.Add(
	r.Queue(
		pointer.Event{
			Type:     pointer.Release,
			Position: f32.Pt(20, 20),


@@ 379,7 379,7 @@ func TestPointerActiveInputDisappears(t *testing.T) {
	ops.Reset()
	addPointerHandler(&ops, handler1, image.Rect(0, 0, 100, 100))
	r.Frame(&ops)
	r.Add(
	r.Queue(
		pointer.Event{
			Type:     pointer.Move,
			Position: f32.Pt(25, 25),


@@ 390,7 390,7 @@ func TestPointerActiveInputDisappears(t *testing.T) {
	// Re-render with handler missing.
	ops.Reset()
	r.Frame(&ops)
	r.Add(
	r.Queue(
		pointer.Event{
			Type:     pointer.Move,
			Position: f32.Pt(25, 25),


@@ 412,21 412,21 @@ func TestMultitouch(t *testing.T) {

	var r Router
	r.Frame(&ops)
	r.Add(
	r.Queue(
		pointer.Event{
			Type:      pointer.Press,
			Position:  h1pt,
			PointerID: p1,
		},
	)
	r.Add(
	r.Queue(
		pointer.Event{
			Type:      pointer.Press,
			Position:  h2pt,
			PointerID: p2,
		},
	)
	r.Add(
	r.Queue(
		pointer.Event{
			Type:      pointer.Release,
			Position:  h2pt,


@@ 468,7 468,7 @@ func TestCursorNameOp(t *testing.T) {
			}
			// Add a mouse move event.
			r.Frame(ops)
			r.Add(
			r.Queue(
				pointer.Event{
					Source:   pointer.Mouse,
					Type:     pointer.Move,


@@ 568,7 568,7 @@ func BenchmarkRouterAdd(b *testing.B) {
			b.ReportAllocs()
			b.ResetTimer()
			for i := 0; i < b.N; i++ {
				r.Add(
				r.Queue(
					pointer.Event{
						Type:     pointer.Move,
						Position: f32.Pt(50, 50),

M io/router/router.go => io/router/router.go +2 -2
@@ 79,8 79,8 @@ func (q *Router) Frame(ops *op.Ops) {
	}
}

// Add an event and report whether at least one handler had an event queued.
func (q *Router) Add(events ...event.Event) bool {
// Queue an event and report whether at least one handler had an event queued.
func (q *Router) Queue(events ...event.Event) bool {
	for _, e := range events {
		switch e := e.(type) {
		case profile.Event:

M layout/list_test.go => layout/list_test.go +1 -1
@@ 108,7 108,7 @@ func TestListPosition(t *testing.T) {
			list.Layout(gtx, tc.num, el)
			// Generate the scroll events.
			r.Frame(gtx.Ops)
			r.Add(tc.scroll...)
			r.Queue(tc.scroll...)
			// Let the list process the events.
			list.Layout(gtx, tc.num, el)


M widget/example_test.go => widget/example_test.go +1 -1
@@ 41,7 41,7 @@ func ExampleClickable_passthrough() {
	widget()
	r.Frame(gtx.Ops)
	// Simulate one click on the buttons by sending a Press and Release event.
	r.Add(
	r.Queue(
		pointer.Event{
			Source:   pointer.Mouse,
			Buttons:  pointer.ButtonLeft,