diff --git a/app/os_android.go b/app/os_android.go index 468ca751..97505ce6 100644 --- a/app/os_android.go +++ b/app/os_android.go @@ -605,7 +605,7 @@ func Java_org_gioui_GioView_initializeAccessibilityNodeInfo(env *C.JNIEnv, class semID := w.semIDFor(virtID) sem, found := w.callbacks.LookupSemantic(semID) if found { - off := f32.Pt(float32(screenX), float32(screenY)) + off := image.Pt(int(screenX), int(screenY)) if err := w.initAccessibilityNodeInfo(env, sem, off, info); err != nil { panic(err) } @@ -657,7 +657,7 @@ func Java_org_gioui_GioView_onClearA11yFocus(env *C.JNIEnv, class C.jclass, view } } -func (w *window) initAccessibilityNodeInfo(env *C.JNIEnv, sem router.SemanticNode, off f32.Point, info C.jobject) error { +func (w *window) initAccessibilityNodeInfo(env *C.JNIEnv, sem router.SemanticNode, off image.Point, info C.jobject) error { for _, ch := range sem.Children { err := callVoidMethod(env, info, android.accessibilityNodeInfo.addChild, jvalue(w.view), jvalue(w.virtualIDFor(ch.ID))) if err != nil { diff --git a/io/router/key.go b/io/router/key.go index 8482c5b0..9d71652c 100644 --- a/io/router/key.go +++ b/io/router/key.go @@ -3,7 +3,7 @@ package router import ( - "math" + "image" "sort" "gioui.org/f32" @@ -54,7 +54,7 @@ type keyCollector struct { type dirFocusEntry struct { tag event.Tag row int - bounds f32.Rectangle + bounds image.Rectangle } const ( @@ -150,7 +150,7 @@ func (q *keyQueue) updateFocusLayout() { end := 1 for ; end < len(order); end++ { h := &order[end] - center := (h.bounds.Min.Y + h.bounds.Max.Y) * .5 + center := (h.bounds.Min.Y + h.bounds.Max.Y) / 2 if center > bottom { break } @@ -217,14 +217,14 @@ func (q *keyQueue) MoveFocus(dir FocusDirection, events *handlerEvents) { nextRow = focus.row + delta } var closest event.Tag - dist := float32(math.Inf(+1)) - center := (focus.bounds.Min.X + focus.bounds.Max.X) * .5 + dist := int(1e6) + center := (focus.bounds.Min.X + focus.bounds.Max.X) / 2 loop: for 0 <= order && order < len(q.dirOrder) { next := q.dirOrder[order] switch next.row { case nextRow: - nextCenter := (next.bounds.Min.X + next.bounds.Max.X) * .5 + nextCenter := (next.bounds.Min.X + next.bounds.Max.X) / 2 d := center - nextCenter if d < 0 { d = -d @@ -251,7 +251,7 @@ func (q *keyQueue) Push(e event.Event, events *handlerEvents) { } } -func (q *keyQueue) BoundsFor(t event.Tag) f32.Rectangle { +func (q *keyQueue) BoundsFor(t event.Tag) image.Rectangle { order := q.handlers[t].dirOrder return q.dirOrder[order].bounds } @@ -291,7 +291,7 @@ func (k *keyCollector) softKeyboard(show bool) { } } -func (k *keyCollector) handlerFor(tag event.Tag, bounds f32.Rectangle) *keyHandler { +func (k *keyCollector) handlerFor(tag event.Tag, bounds image.Rectangle) *keyHandler { h, ok := k.q.handlers[tag] if !ok { h = &keyHandler{new: true, order: -1} @@ -305,7 +305,7 @@ func (k *keyCollector) handlerFor(tag event.Tag, bounds f32.Rectangle) *keyHandl return h } -func (k *keyCollector) inputOp(op key.InputOp, bounds f32.Rectangle) { +func (k *keyCollector) inputOp(op key.InputOp, bounds image.Rectangle) { h := k.handlerFor(op.Tag, bounds) h.visible = true h.hint = op.Hint diff --git a/io/router/pointer.go b/io/router/pointer.go index ecfa1048..dd8c7ec6 100644 --- a/io/router/pointer.go +++ b/io/router/pointer.go @@ -74,7 +74,7 @@ type pointerHandler struct { type areaOp struct { kind areaKind - rect f32.Rectangle + rect image.Rectangle } type areaNode struct { @@ -153,10 +153,10 @@ func (c *pointerCollector) clip(op ops.ClipOp) { if op.Shape == ops.Ellipse { kind = areaEllipse } - c.pushArea(kind, frect(op.Bounds)) + c.pushArea(kind, op.Bounds) } -func (c *pointerCollector) pushArea(kind areaKind, bounds f32.Rectangle) { +func (c *pointerCollector) pushArea(kind areaKind, bounds image.Rectangle) { parentID := c.currentArea() areaID := len(c.q.areas) areaOp := areaOp{kind: kind, rect: bounds} @@ -223,7 +223,7 @@ func (c *pointerCollector) currentArea() int { return -1 } -func (c *pointerCollector) currentAreaBounds() f32.Rectangle { +func (c *pointerCollector) currentAreaBounds() image.Rectangle { a := c.currentArea() if a == -1 { panic("no root area") @@ -340,7 +340,7 @@ func (c *pointerCollector) ensureRoot() { if len(c.q.areas) > 0 { return } - c.pushArea(areaRect, f32.Rect(-1e6, -1e6, 1e6, 1e6)) + c.pushArea(areaRect, image.Rect(-1e6, -1e6, 1e6, 1e6)) // Make it semantic to ensure a single semantic root. c.q.areas[0].semantic.valid = true } @@ -854,8 +854,8 @@ func firstMimeMatch(src, tgt *pointerHandler) (first string, matched bool) { } func (op *areaOp) Hit(pos f32.Point) bool { - pos = pos.Sub(op.rect.Min) - size := op.rect.Size() + pos = pos.Sub(fpt(op.rect.Min)) + size := fpt(op.rect.Size()) switch op.kind { case areaRect: return 0 <= pos.X && pos.X < size.X && @@ -873,11 +873,11 @@ func (op *areaOp) Hit(pos f32.Point) bool { } } -func (a *areaNode) bounds() f32.Rectangle { +func (a *areaNode) bounds() image.Rectangle { return f32.Rectangle{ - Min: a.trans.Transform(a.area.rect.Min), - Max: a.trans.Transform(a.area.rect.Max), - } + Min: a.trans.Transform(fpt(a.area.rect.Min)), + Max: a.trans.Transform(fpt(a.area.rect.Max)), + }.Round() } func setScrollEvent(scroll float32, min, max int) (left, scrolled float32) { diff --git a/io/router/router.go b/io/router/router.go index e303d85c..089c6f12 100644 --- a/io/router/router.go +++ b/io/router/router.go @@ -77,7 +77,7 @@ type SemanticDesc struct { Selected bool Disabled bool Gestures SemanticGestures - Bounds f32.Rectangle + Bounds image.Rectangle } // SemanticGestures is a bit-set of supported gestures. @@ -158,9 +158,9 @@ func (q *Router) ClickFocus() { return } bounds := q.key.queue.BoundsFor(focus) - center := bounds.Max.Add(bounds.Min).Mul(.5) + center := bounds.Max.Add(bounds.Min).Div(2) e := pointer.Event{ - Position: center, + Position: f32.Pt(float32(center.X), float32(center.Y)), Source: pointer.Touch, } e.Type = pointer.Press diff --git a/io/router/semantic_test.go b/io/router/semantic_test.go index 71ea8469..edc5dfbc 100644 --- a/io/router/semantic_test.go +++ b/io/router/semantic_test.go @@ -91,7 +91,7 @@ func TestSemanticDescription(t *testing.T) { Selected: true, Disabled: true, Gestures: ClickGesture, - Bounds: f32.Rectangle{Min: f32.Point{X: -1e+06, Y: -1e+06}, Max: f32.Point{X: 1e+06, Y: 1e+06}}, + Bounds: image.Rectangle{Min: image.Point{X: -1e+06, Y: -1e+06}, Max: image.Point{X: 1e+06, Y: 1e+06}}, } if got != exp { t.Errorf("semantic description mismatch:\nGot: %+v\nWant: %+v", got, exp)