From dbc10056f9f90850efe51cb21800fa5347720c7d Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Tue, 28 Nov 2023 15:01:02 -0600 Subject: [PATCH] io/event: [API] rename InputOp to Op Signed-off-by: Elias Naur --- gesture/gesture.go | 10 +++---- io/event/event.go | 4 +-- io/input/key_test.go | 12 ++++---- io/input/pointer_test.go | 60 +++++++++++++++++++-------------------- io/input/semantic_test.go | 2 +- widget/button.go | 2 +- widget/dnd.go | 2 +- widget/dnd_test.go | 2 +- widget/editor.go | 2 +- widget/enum.go | 2 +- widget/example_test.go | 2 +- widget/selectable.go | 2 +- 12 files changed, 51 insertions(+), 51 deletions(-) diff --git a/gesture/gesture.go b/gesture/gesture.go index b32c2a47..70e87707 100644 --- a/gesture/gesture.go +++ b/gesture/gesture.go @@ -38,7 +38,7 @@ type Hover struct { // Add the gesture to detect hovering over the current pointer area. func (h *Hover) Add(ops *op.Ops) { - event.InputOp(ops, h) + event.Op(ops, h) } // Update state and report whether a pointer is inside the area. @@ -163,7 +163,7 @@ const touchSlop = unit.Dp(3) // Add the handler to the operation list to receive click events. func (c *Click) Add(ops *op.Ops) { - event.InputOp(ops, c) + event.Op(ops, c) } // Hovered returns whether a pointer is inside the area. @@ -260,9 +260,9 @@ func (ClickEvent) ImplementsEvent() {} // Add the handler to the operation list to receive scroll events. // The bounds variable refers to the scrolling boundaries -// as defined in io/pointer.InputOp. +// as defined in [pointer.Filter]. func (s *Scroll) Add(ops *op.Ops) { - event.InputOp(ops, s) + event.Op(ops, s) } // Stop any remaining fling movement. @@ -373,7 +373,7 @@ func (s *Scroll) State() ScrollState { // Add the handler to the operation list to receive drag events. func (d *Drag) Add(ops *op.Ops) { - event.InputOp(ops, d) + event.Op(ops, d) } // Update state and return the next drag event, if any. diff --git a/io/event/event.go b/io/event/event.go index 2f13b855..a92342f7 100644 --- a/io/event/event.go +++ b/io/event/event.go @@ -22,9 +22,9 @@ type Filter interface { ImplementsFilter() } -// InputOp declares a tag for input routing at the current transformation +// Op declares a tag for input routing at the current transformation // and clip area hierarchy. It panics if tag is nil. -func InputOp(o *op.Ops, tag Tag) { +func Op(o *op.Ops, tag Tag) { if tag == nil { panic("Tag must be non-nil") } diff --git a/io/input/key_test.go b/io/input/key_test.go index 71034c90..bc6c13e9 100644 --- a/io/input/key_test.go +++ b/io/input/key_test.go @@ -73,7 +73,7 @@ func TestInputWakeup(t *testing.T) { handler := new(int) var ops op.Ops // InputOps shouldn't trigger redraws. - event.InputOp(&ops, handler) + event.Op(&ops, handler) var r Router // Reset events shouldn't either. @@ -192,7 +192,7 @@ func TestKeyFocusedInvisible(t *testing.T) { // Respawn the first element: // It must receive one `Event{Focus: false}`. - event.InputOp(ops, &handlers[0]) + event.Op(ops, &handlers[0]) assertEventSequence(t, events(r, -1, key.FocusFilter{Target: &handlers[0]}), key.FocusEvent{Focus: false}) } @@ -214,7 +214,7 @@ func TestDirectionalFocus(t *testing.T) { for i, bounds := range handlers { cl := clip.Rect(bounds).Push(ops) - event.InputOp(ops, &handlers[i]) + event.Op(ops, &handlers[i]) cl.Pop() events(r, -1, key.FocusFilter{Target: &handlers[i]}) } @@ -259,9 +259,9 @@ func TestFocusScroll(t *testing.T) { events(r, -1, filters...) parent := clip.Rect(image.Rect(1, 1, 14, 39)).Push(ops) cl := clip.Rect(image.Rect(10, -20, 20, 30)).Push(ops) - event.InputOp(ops, h) + event.Op(ops, h) // Test that h is scrolled even if behind another handler. - event.InputOp(ops, new(int)) + event.Op(ops, new(int)) cl.Pop() parent.Pop() r.Frame(ops) @@ -286,7 +286,7 @@ func TestFocusClick(t *testing.T) { } assertEventPointerTypeSequence(t, events(r, -1, filters...), pointer.Cancel) cl := clip.Rect(image.Rect(0, 0, 10, 10)).Push(ops) - event.InputOp(ops, h) + event.Op(ops, h) cl.Pop() r.Frame(ops) diff --git a/io/input/pointer_test.go b/io/input/pointer_test.go index e5f1ed4c..16ac9628 100644 --- a/io/input/pointer_test.go +++ b/io/input/pointer_test.go @@ -107,9 +107,9 @@ func TestPointerGrab(t *testing.T) { return pointer.Filter{Target: t, Kinds: pointer.Press | pointer.Release | pointer.Cancel} } - event.InputOp(&ops, handler1) - event.InputOp(&ops, handler2) - event.InputOp(&ops, handler3) + event.Op(&ops, handler1) + event.Op(&ops, handler2) + event.Op(&ops, handler3) var r Router assertEventPointerTypeSequence(t, events(&r, -1, filter(handler1)), pointer.Cancel) @@ -146,9 +146,9 @@ func TestPointerGrabSameHandlerTwice(t *testing.T) { return pointer.Filter{Target: t, Kinds: pointer.Press | pointer.Release | pointer.Cancel} } - event.InputOp(&ops, handler1) - event.InputOp(&ops, handler1) - event.InputOp(&ops, handler2) + event.Op(&ops, handler1) + event.Op(&ops, handler1) + event.Op(&ops, handler2) var r Router assertEventPointerTypeSequence(t, events(&r, -1, filter(handler1)), pointer.Cancel) @@ -187,10 +187,10 @@ func TestPointerMove(t *testing.T) { // Handler 1 area: (0, 0) - (100, 100) r1 := clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops) - event.InputOp(&ops, handler1) + event.Op(&ops, handler1) // Handler 2 area: (50, 50) - (100, 100) (areas intersect). r2 := clip.Rect(image.Rect(50, 50, 200, 200)).Push(&ops) - event.InputOp(&ops, handler2) + event.Op(&ops, handler2) r2.Pop() r1.Pop() @@ -230,7 +230,7 @@ func TestPointerTypes(t *testing.T) { Target: handler, Kinds: pointer.Press | pointer.Release | pointer.Cancel, } - event.InputOp(&ops, handler) + event.Op(&ops, handler) r1.Pop() var r Router @@ -306,7 +306,7 @@ func TestPointerPriority(t *testing.T) { } } events(&r, -1, f1(handler1)) - event.InputOp(&ops, handler1) + event.Op(&ops, handler1) r2 := clip.Rect(image.Rect(0, 0, 100, 50)).Push(&ops) f2 := func(t event.Tag) event.Filter { @@ -317,7 +317,7 @@ func TestPointerPriority(t *testing.T) { } } events(&r, -1, f2(handler2)) - event.InputOp(&ops, handler2) + event.Op(&ops, handler2) r2.Pop() r1.Pop() @@ -330,7 +330,7 @@ func TestPointerPriority(t *testing.T) { } } events(&r, -1, f3(handler3)) - event.InputOp(&ops, handler3) + event.Op(&ops, handler3) r3.Pop() r.Frame(&ops) @@ -480,7 +480,7 @@ func TestMultipleAreas(t *testing.T) { f := addPointerHandler(&r, &ops, handler, image.Rect(0, 0, 100, 100)) r1 := clip.Rect(image.Rect(50, 50, 200, 200)).Push(&ops) // Test that declaring a handler twice doesn't affect event handling. - event.InputOp(&ops, handler) + event.Op(&ops, handler) r1.Pop() assertEventPointerTypeSequence(t, events(&r, -1, f)) @@ -517,11 +517,11 @@ func TestPointerEnterLeaveNested(t *testing.T) { // Handler 1 area: (0, 0) - (100, 100) r1 := clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops) - event.InputOp(&ops, handler1) + event.Op(&ops, handler1) // Handler 2 area: (25, 25) - (75, 75) (nested within first). r2 := clip.Rect(image.Rect(25, 25, 75, 75)).Push(&ops) - event.InputOp(&ops, handler2) + event.Op(&ops, handler2) r2.Pop() r1.Pop() @@ -758,15 +758,15 @@ func TestPassOp(t *testing.T) { h1, h2, h3, h4 := new(int), new(int), new(int), new(int) area := clip.Rect(image.Rect(0, 0, 100, 100)) root := area.Push(&ops) - event.InputOp(&ops, &h1) - event.InputOp(&ops, h1) + event.Op(&ops, &h1) + event.Op(&ops, h1) child1 := area.Push(&ops) - event.InputOp(&ops, h2) + event.Op(&ops, h2) child1.Pop() child2 := area.Push(&ops) pass := pointer.PassOp{}.Push(&ops) - event.InputOp(&ops, h3) - event.InputOp(&ops, h4) + event.Op(&ops, h3) + event.Op(&ops, h4) pass.Pop() child2.Pop() root.Pop() @@ -795,7 +795,7 @@ func TestAreaPassthrough(t *testing.T) { var ops op.Ops h := new(int) - event.InputOp(&ops, h) + event.Op(&ops, h) clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops).Pop() var r Router f := pointer.Filter{ @@ -817,7 +817,7 @@ func TestEllipse(t *testing.T) { h := new(int) cl := clip.Ellipse(image.Rect(0, 0, 100, 100)).Push(&ops) - event.InputOp(&ops, h) + event.Op(&ops, h) cl.Pop() var r Router f := pointer.Filter{ @@ -853,11 +853,11 @@ func TestTransfer(t *testing.T) { events(r, -1, transfer.TargetFilter{Target: tgt, Type: tgtType}) srcStack := clip.Rect(srcArea).Push(ops) - event.InputOp(ops, src) + event.Op(ops, src) srcStack.Pop() tgt1Stack := clip.Rect(tgtArea).Push(ops) - event.InputOp(ops, tgt) + event.Op(ops, tgt) tgt1Stack.Pop() return src, tgt @@ -904,7 +904,7 @@ func TestTransfer(t *testing.T) { tgt2 := new(int) events(&r, -1, transfer.TargetFilter{Target: tgt2, Type: "nofile"}) stack := clip.Rect(tgtArea).Push(ops) - event.InputOp(ops, tgt2) + event.Op(ops, tgt2) stack.Pop() r.Frame(ops) // Initiate a drag. @@ -1050,7 +1050,7 @@ func TestDeferredInputOp(t *testing.T) { var r Router m := op.Record(&ops) - event.InputOp(&ops, new(int)) + event.Op(&ops, new(int)) call := m.Stop() op.Defer(&ops, call) @@ -1063,13 +1063,13 @@ func TestPassCursor(t *testing.T) { rect := clip.Rect(image.Rect(0, 0, 100, 100)) background := rect.Push(&ops) - event.InputOp(&ops, 1) + event.Op(&ops, 1) pointer.CursorDefault.Add(&ops) background.Pop() overlayPass := pointer.PassOp{}.Push(&ops) overlay := rect.Push(&ops) - event.InputOp(&ops, 2) + event.Op(&ops, 2) want := pointer.CursorPointer want.Add(&ops) overlay.Pop() @@ -1106,7 +1106,7 @@ func addPointerHandler(r *Router, ops *op.Ops, tag event.Tag, area image.Rectang } events(r, -1, f) defer clip.Rect(area).Push(ops).Pop() - event.InputOp(ops, tag) + event.Op(ops, tag) return f } @@ -1245,7 +1245,7 @@ func BenchmarkRouterAdd(b *testing.B) { }). Push(&ops) events(&r, -1, pointer.Filter{Target: handlers[i], Kinds: pointer.Move}) - event.InputOp(&ops, handlers[i]) + event.Op(&ops, handlers[i]) } r.Frame(&ops) b.ReportAllocs() diff --git a/io/input/semantic_test.go b/io/input/semantic_test.go index 98af5285..21263293 100644 --- a/io/input/semantic_test.go +++ b/io/input/semantic_test.go @@ -77,7 +77,7 @@ func TestSemanticDescription(t *testing.T) { var ops op.Ops h := new(int) - event.InputOp(&ops, h) + event.Op(&ops, h) semantic.DescriptionOp("description").Add(&ops) semantic.LabelOp("label").Add(&ops) semantic.Button.Add(&ops) diff --git a/widget/button.go b/widget/button.go index 4f3cb840..c5686a03 100644 --- a/widget/button.go +++ b/widget/button.go @@ -93,7 +93,7 @@ func (b *Clickable) layout(t event.Tag, gtx layout.Context, w layout.Widget) lay defer clip.Rect(image.Rectangle{Max: dims.Size}).Push(gtx.Ops).Pop() semantic.EnabledOp(gtx.Enabled()).Add(gtx.Ops) b.click.Add(gtx.Ops) - event.InputOp(gtx.Ops, t) + event.Op(gtx.Ops, t) c.Add(gtx.Ops) return dims } diff --git a/widget/dnd.go b/widget/dnd.go index 0932e9b2..5c90a4d7 100644 --- a/widget/dnd.go +++ b/widget/dnd.go @@ -31,7 +31,7 @@ func (d *Draggable) Layout(gtx layout.Context, w, drag layout.Widget) layout.Dim stack := clip.Rect{Max: dims.Size}.Push(gtx.Ops) d.drag.Add(gtx.Ops) - event.InputOp(gtx.Ops, d) + event.Op(gtx.Ops, d) stack.Pop() if drag != nil && d.drag.Pressed() { diff --git a/widget/dnd_test.go b/widget/dnd_test.go index 750a0308..9c65de1c 100644 --- a/widget/dnd_test.go +++ b/widget/dnd_test.go @@ -31,7 +31,7 @@ func TestDraggable(t *testing.T) { return layout.Dimensions{Size: gtx.Constraints.Min} }, nil) stack := clip.Rect{Max: dims.Size}.Push(gtx.Ops) - event.InputOp(gtx.Ops, tgt) + event.Op(gtx.Ops, tgt) stack.Pop() drag.Update(gtx) diff --git a/widget/editor.go b/widget/editor.go index 2d89d77d..455e95e0 100644 --- a/widget/editor.go +++ b/widget/editor.go @@ -662,7 +662,7 @@ func (e *Editor) layout(gtx layout.Context, textMaterial, selectMaterial op.Call defer clip.Rect(image.Rectangle{Max: visibleDims.Size}).Push(gtx.Ops).Pop() pointer.CursorText.Add(gtx.Ops) - event.InputOp(gtx.Ops, e) + event.Op(gtx.Ops, e) key.InputHintOp{Tag: e, Hint: e.InputHint}.Add(gtx.Ops) e.scroller.Add(gtx.Ops) diff --git a/widget/enum.go b/widget/enum.go index ae19e46b..dce0c68c 100644 --- a/widget/enum.go +++ b/widget/enum.go @@ -130,7 +130,7 @@ func (e *Enum) Layout(gtx layout.Context, k string, content layout.Widget) layou } clk := &state.click clk.Add(gtx.Ops) - event.InputOp(gtx.Ops, &state.tag) + event.Op(gtx.Ops, &state.tag) semantic.SelectedOp(k == e.Value).Add(gtx.Ops) semantic.EnabledOp(gtx.Enabled()).Add(gtx.Ops) c.Add(gtx.Ops) diff --git a/widget/example_test.go b/widget/example_test.go index c2910fff..428ed09d 100644 --- a/widget/example_test.go +++ b/widget/example_test.go @@ -105,7 +105,7 @@ func ExampleDraggable_Layout() { Min: image.Pt(20, 20), Max: image.Pt(40, 40), }.Push(gtx.Ops) - event.InputOp(gtx.Ops, &drop) + event.Op(gtx.Ops, &drop) ds.Pop() // Check for the received data. diff --git a/widget/selectable.go b/widget/selectable.go index 39380852..7292cd52 100644 --- a/widget/selectable.go +++ b/widget/selectable.go @@ -196,7 +196,7 @@ func (l *Selectable) Layout(gtx layout.Context, lt *text.Shaper, font font.Font, dims := l.text.Dimensions() defer clip.Rect(image.Rectangle{Max: dims.Size}).Push(gtx.Ops).Pop() pointer.CursorText.Add(gtx.Ops) - event.InputOp(gtx.Ops, l) + event.Op(gtx.Ops, l) l.clicker.Add(gtx.Ops) l.dragger.Add(gtx.Ops)