~eliasnaur/gio-patches

gio: io/router: use f32.Rectangle in areaOp v1 PROPOSED

~pierrec
~pierrec: 1
 io/router: use f32.Rectangle in areaOp

 1 files changed, 16 insertions(+), 16 deletions(-)
#436675 apple.yml success
#436676 freebsd.yml failed
#436677 linux.yml failed
#436678 openbsd.yml failed
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~eliasnaur/gio-patches/patches/20484/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH gio] io/router: use f32.Rectangle in areaOp Export this patch

~pierrec
From: pierre <pierre.curto@gmail.com>

Also introduce a function to decode an int from ops.

Signed-off-by: pierre <pierre.curto@gmail.com>
---
 io/router/pointer.go | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/io/router/pointer.go b/io/router/pointer.go
index ab9348b..4ca3514 100644
--- a/io/router/pointer.go
+++ b/io/router/pointer.go
@@ -11,6 +11,7 @@ import (
	"gioui.org/internal/ops"
	"gioui.org/io/event"
	"gioui.org/io/pointer"
	"gioui.org/layout"
	"gioui.org/op"
)

@@ -64,7 +65,7 @@ type pointerHandler struct {

type areaOp struct {
	kind areaKind
	rect image.Rectangle
	rect f32.Rectangle
}

type areaNode struct {
@@ -409,41 +410,40 @@ func searchTag(tags []event.Tag, tag event.Tag) (int, bool) {
	return 0, false
}

func opDecodeInt(d []byte) int {
	return int(binary.LittleEndian.Uint32(d))
}

func (op *areaOp) Decode(d []byte) {
	if opconst.OpType(d[0]) != opconst.TypeArea {
		panic("invalid op")
	}
	bo := binary.LittleEndian
	rect := image.Rectangle{
		Min: image.Point{
			X: int(int32(bo.Uint32(d[2:]))),
			Y: int(int32(bo.Uint32(d[6:]))),
			X: opDecodeInt(d[2:]),
			Y: opDecodeInt(d[6:]),
		},
		Max: image.Point{
			X: int(int32(bo.Uint32(d[10:]))),
			Y: int(int32(bo.Uint32(d[14:]))),
			X: opDecodeInt(d[10:]),
			Y: opDecodeInt(d[14:]),
		},
	}
	*op = areaOp{
		kind: areaKind(d[1]),
		rect: rect,
		rect: layout.FRect(rect),
	}
}

func (op *areaOp) Hit(pos f32.Point) bool {
	min := f32.Point{
		X: float32(op.rect.Min.X),
		Y: float32(op.rect.Min.Y),
	}
	pos = pos.Sub(min)
	pos = pos.Sub(op.rect.Min)
	size := op.rect.Size()
	switch op.kind {
	case areaRect:
		return 0 <= pos.X && pos.X < float32(size.X) &&
			0 <= pos.Y && pos.Y < float32(size.Y)
		return 0 <= pos.X && pos.X < size.X &&
			0 <= pos.Y && pos.Y < size.Y
	case areaEllipse:
		rx := float32(size.X) / 2
		ry := float32(size.Y) / 2
		rx := size.X / 2
		ry := size.Y / 2
		xh := pos.X - rx
		yk := pos.Y - ry
		// The ellipse function works in all cases because
-- 
2.30.1
builds.sr.ht
gio/patches: FAILED in 20m36s

[io/router: use f32.Rectangle in areaOp][0] from [~pierrec][1]

[0]: https://lists.sr.ht/~eliasnaur/gio-patches/patches/20484
[1]: mailto:pierre.curto@gmail.com

✗ #436677 FAILED  gio/patches/linux.yml   https://builds.sr.ht/~eliasnaur/job/436677
✗ #436676 FAILED  gio/patches/freebsd.yml https://builds.sr.ht/~eliasnaur/job/436676
✗ #436678 FAILED  gio/patches/openbsd.yml https://builds.sr.ht/~eliasnaur/job/436678
✓ #436675 SUCCESS gio/patches/apple.yml   https://builds.sr.ht/~eliasnaur/job/436675