mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 17:35:36 +00:00
io/router: fix system action routing logic
When running ActionAt, the router used to only consider the topmost clip area, even if that clip area had no input handlers attached whatsoever. This change updates the logic for that test to use the same traversal as normal event handling, ensuring that action inputs behave intuitively like any other pointer input area. Included is a test catching the problematic behavior that prompted this change. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/io/key"
|
||||
"gioui.org/io/pointer"
|
||||
"gioui.org/io/system"
|
||||
"gioui.org/io/transfer"
|
||||
"gioui.org/op"
|
||||
"gioui.org/op/clip"
|
||||
@@ -221,6 +222,30 @@ func TestPointerTypes(t *testing.T) {
|
||||
assertEventPointerTypeSequence(t, r.Events(handler), pointer.Cancel, pointer.Press, pointer.Release)
|
||||
}
|
||||
|
||||
func TestPointerSystemAction(t *testing.T) {
|
||||
t.Run("simple", func(t *testing.T) {
|
||||
var ops op.Ops
|
||||
r1 := clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops)
|
||||
system.ActionInputOp(system.ActionMove).Add(&ops)
|
||||
r1.Pop()
|
||||
|
||||
var r Router
|
||||
r.Frame(&ops)
|
||||
assertActionAt(t, r, f32.Pt(50, 50), system.ActionMove)
|
||||
})
|
||||
t.Run("covered by another clip", func(t *testing.T) {
|
||||
var ops op.Ops
|
||||
r1 := clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops)
|
||||
system.ActionInputOp(system.ActionMove).Add(&ops)
|
||||
clip.Rect(image.Rect(0, 0, 100, 100)).Push(&ops).Pop()
|
||||
r1.Pop()
|
||||
|
||||
var r Router
|
||||
r.Frame(&ops)
|
||||
assertActionAt(t, r, f32.Pt(50, 50), system.ActionMove)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPointerPriority(t *testing.T) {
|
||||
handler1 := new(int)
|
||||
handler2 := new(int)
|
||||
@@ -1231,6 +1256,17 @@ func assertScrollEvent(t *testing.T, ev event.Event, scroll f32.Point) {
|
||||
}
|
||||
}
|
||||
|
||||
// assertActionAt checks that the router has a system action of the expected type at point.
|
||||
func assertActionAt(t *testing.T, q Router, point f32.Point, expected system.Action) {
|
||||
t.Helper()
|
||||
action, ok := q.ActionAt(point)
|
||||
if !ok {
|
||||
t.Errorf("expected action %v at %v, got no action", expected, point)
|
||||
} else if action != expected {
|
||||
t.Errorf("expected action %v at %v, got %v", expected, point, action)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkRouterAdd(b *testing.B) {
|
||||
// Set this to the number of overlapping handlers that you want to
|
||||
// evaluate performance for. Typical values for the example applications
|
||||
|
||||
Reference in New Issue
Block a user