io/router: use areas to determine targets for synthetic clicks

Before this change, semantic clicks would be delivered according to
the center of the targeted widget, which could result in a different
widget receiving the click. Or in worst case, no widget in case the
center is not visible because of clipping.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-03-30 17:28:58 +02:00
parent 4326fee704
commit e8603ba59e
2 changed files with 22 additions and 2 deletions
+19
View File
@@ -290,6 +290,25 @@ func TestFocusScroll(t *testing.T) {
assertScrollEvent(t, evts[len(evts)-1], f32.Pt(5, -10))
}
func TestFocusClick(t *testing.T) {
ops := new(op.Ops)
r := new(Router)
h := new(int)
cl := clip.Rect(image.Rect(0, 0, 10, 10)).Push(ops)
key.InputOp{Tag: h}.Add(ops)
pointer.InputOp{
Tag: h,
Types: pointer.Press | pointer.Release,
}.Add(ops)
cl.Pop()
r.Frame(ops)
r.MoveFocus(FocusLeft)
r.ClickFocus()
assertEventPointerTypeSequence(t, r.Events(h), pointer.Cancel, pointer.Press, pointer.Release)
}
func assertKeyEvent(t *testing.T, events []event.Event, expected bool, expectedInputs ...event.Event) {
t.Helper()
var evtFocus int
+3 -2
View File
@@ -216,10 +216,11 @@ func (q *Router) ClickFocus() {
Position: f32.Pt(float32(center.X), float32(center.Y)),
Source: pointer.Touch,
}
area := q.key.queue.AreaFor(focus)
e.Type = pointer.Press
q.pointer.queue.Push(e, &q.handlers)
q.pointer.queue.Deliver(area, e, &q.handlers)
e.Type = pointer.Release
q.pointer.queue.Push(e, &q.handlers)
q.pointer.queue.Deliver(area, e, &q.handlers)
}
// TextInputState returns the input state from the most recent