forked from joejulian/gio
all: [API] change op.Offset to take integer coordinates
op.Offset is a convenience function most often used by layouts. Layouts usually operate in integer coordinates, and the float32 version of op.Offset needlessly force conversions from int to float32. This change makes op.Offset take integer coordinates, to better match its intended use. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -67,6 +67,7 @@ package op
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"image"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
@@ -195,9 +196,10 @@ func (r InvalidateOp) Add(o *Ops) {
|
||||
}
|
||||
}
|
||||
|
||||
// Offset creates a TransformOp with the offset o.
|
||||
func Offset(o f32.Point) TransformOp {
|
||||
return TransformOp{t: f32.Affine2D{}.Offset(o)}
|
||||
// Offset converts an offset to a TransformOp.
|
||||
func Offset(off image.Point) TransformOp {
|
||||
offf := f32.Pt(float32(off.X), float32(off.Y))
|
||||
return Affine(f32.Affine2D{}.Offset(offf))
|
||||
}
|
||||
|
||||
// Affine creates a TransformOp representing the transformation a.
|
||||
|
||||
+2
-3
@@ -3,9 +3,8 @@
|
||||
package op
|
||||
|
||||
import (
|
||||
"image"
|
||||
"testing"
|
||||
|
||||
"gioui.org/f32"
|
||||
)
|
||||
|
||||
func TestTransformChecks(t *testing.T) {
|
||||
@@ -15,7 +14,7 @@ func TestTransformChecks(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
var ops Ops
|
||||
trans := Offset(f32.Point{}).Push(&ops)
|
||||
trans := Offset(image.Point{}).Push(&ops)
|
||||
Record(&ops)
|
||||
trans.Pop()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user