mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 09:25:38 +00:00
io/pointer,io/router: replace AreaOp with clip.Op
Pointer hit areas and paint clip areas are separate concepts, but similar enough to warrant merging. This change replaces pointer hit areas with clip areas, so Gio is left with just one area concept (in package op/clip). The reason for separating the concepts in the original Gio release was because of my being unsure general path/stroke hit areas would ever be implemented, let alone efficient. This change represents a change of mind, in the sense that it's better to have an incomplete API than two separate area concepts. Leave the deprecated pointer.Rect, pointer.Ellipse for temporary backwards compatibility. This is an API change. Most existing programs should continue to build with this change, but may have to adjust to having all clip.Ops participate in InputOp hit areas. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"gioui.org/io/key"
|
||||
"gioui.org/io/pointer"
|
||||
"gioui.org/op"
|
||||
"gioui.org/op/clip"
|
||||
)
|
||||
|
||||
func TestPointerWakeup(t *testing.T) {
|
||||
@@ -733,6 +734,33 @@ func TestAreaPassthrough(t *testing.T) {
|
||||
assertEventSequence(t, r.Events(h), pointer.Cancel, pointer.Press)
|
||||
}
|
||||
|
||||
func TestEllipse(t *testing.T) {
|
||||
var ops op.Ops
|
||||
|
||||
h := new(int)
|
||||
cl := clip.Ellipse(f32.Rect(0, 0, 100, 100)).Push(&ops)
|
||||
pointer.InputOp{Tag: h, Types: pointer.Press}.Add(&ops)
|
||||
cl.Pop()
|
||||
var r Router
|
||||
r.Frame(&ops)
|
||||
r.Queue(
|
||||
// Outside ellipse.
|
||||
pointer.Event{
|
||||
Position: f32.Pt(10, 10),
|
||||
Type: pointer.Press,
|
||||
},
|
||||
pointer.Event{
|
||||
Type: pointer.Release,
|
||||
},
|
||||
// Inside ellipse.
|
||||
pointer.Event{
|
||||
Position: f32.Pt(50, 50),
|
||||
Type: pointer.Press,
|
||||
},
|
||||
)
|
||||
assertEventSequence(t, r.Events(h), pointer.Cancel, pointer.Press)
|
||||
}
|
||||
|
||||
// addPointerHandler adds a pointer.InputOp for the tag in a
|
||||
// rectangular area.
|
||||
func addPointerHandler(ops *op.Ops, tag event.Tag, area image.Rectangle) {
|
||||
|
||||
Reference in New Issue
Block a user