mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
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:
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user