mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
all: remove redundant op.TransformOp.Offset
Use op.Offset instead, or create and manipulate a f32.Affine2D.
API change. Update your code with a gofmt rule:
gofmt -r 'op.TransformOp{}.Offset -> op.Offset'
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -87,7 +87,7 @@ func BenchmarkDrawUI(b *testing.B) {
|
|||||||
|
|
||||||
p := op.Push(gtx.Ops)
|
p := op.Push(gtx.Ops)
|
||||||
off := float32(math.Mod(float64(i)/10, 10))
|
off := float32(math.Mod(float64(i)/10, 10))
|
||||||
op.TransformOp{}.Offset(f32.Pt(off, off)).Add(gtx.Ops)
|
op.Offset(f32.Pt(off, off)).Add(gtx.Ops)
|
||||||
|
|
||||||
drawCore(gtx, th)
|
drawCore(gtx, th)
|
||||||
|
|
||||||
@@ -157,14 +157,14 @@ func draw1000Circles(gtx layout.Context) {
|
|||||||
ops := gtx.Ops
|
ops := gtx.Ops
|
||||||
for x := 0; x < 100; x++ {
|
for x := 0; x < 100; x++ {
|
||||||
p := op.Push(ops)
|
p := op.Push(ops)
|
||||||
op.TransformOp{}.Offset(f32.Pt(float32(x*10), 0)).Add(ops)
|
op.Offset(f32.Pt(float32(x*10), 0)).Add(ops)
|
||||||
for y := 0; y < 10; y++ {
|
for y := 0; y < 10; y++ {
|
||||||
pi := op.Push(ops)
|
pi := op.Push(ops)
|
||||||
paint.ColorOp{Color: color.RGBA{R: 100 + uint8(x), G: 100 + uint8(y), B: 100, A: 120}}.Add(ops)
|
paint.ColorOp{Color: color.RGBA{R: 100 + uint8(x), G: 100 + uint8(y), B: 100, A: 120}}.Add(ops)
|
||||||
clip.Rect{Rect: f32.Rect(0, 0, 10, 10), NE: 5, SE: 5, SW: 5, NW: 5}.Add(ops)
|
clip.Rect{Rect: f32.Rect(0, 0, 10, 10), NE: 5, SE: 5, SW: 5, NW: 5}.Add(ops)
|
||||||
paint.PaintOp{Rect: f32.Rect(0, 0, 10, 10)}.Add(ops)
|
paint.PaintOp{Rect: f32.Rect(0, 0, 10, 10)}.Add(ops)
|
||||||
pi.Pop()
|
pi.Pop()
|
||||||
op.TransformOp{}.Offset(f32.Pt(0, float32(100))).Add(ops)
|
op.Offset(f32.Pt(0, float32(100))).Add(ops)
|
||||||
}
|
}
|
||||||
p.Pop()
|
p.Pop()
|
||||||
}
|
}
|
||||||
@@ -180,13 +180,13 @@ func draw1000CirclesInstanced(gtx layout.Context) {
|
|||||||
|
|
||||||
for x := 0; x < 100; x++ {
|
for x := 0; x < 100; x++ {
|
||||||
p := op.Push(ops)
|
p := op.Push(ops)
|
||||||
op.TransformOp{}.Offset(f32.Pt(float32(x*10), 0)).Add(ops)
|
op.Offset(f32.Pt(float32(x*10), 0)).Add(ops)
|
||||||
for y := 0; y < 10; y++ {
|
for y := 0; y < 10; y++ {
|
||||||
pi := op.Push(ops)
|
pi := op.Push(ops)
|
||||||
paint.ColorOp{Color: color.RGBA{R: 100 + uint8(x), G: 100 + uint8(y), B: 100, A: 120}}.Add(ops)
|
paint.ColorOp{Color: color.RGBA{R: 100 + uint8(x), G: 100 + uint8(y), B: 100, A: 120}}.Add(ops)
|
||||||
c.Add(ops)
|
c.Add(ops)
|
||||||
pi.Pop()
|
pi.Pop()
|
||||||
op.TransformOp{}.Offset(f32.Pt(0, float32(100))).Add(ops)
|
op.Offset(f32.Pt(0, float32(100))).Add(ops)
|
||||||
}
|
}
|
||||||
p.Pop()
|
p.Pop()
|
||||||
}
|
}
|
||||||
@@ -209,14 +209,14 @@ func drawIndividualShapes(gtx layout.Context, th *material.Theme) chan op.CallOp
|
|||||||
c := op.Record(ops)
|
c := op.Record(ops)
|
||||||
for x := 0; x < 9; x++ {
|
for x := 0; x < 9; x++ {
|
||||||
p := op.Push(ops)
|
p := op.Push(ops)
|
||||||
op.TransformOp{}.Offset(f32.Pt(float32(x*50), 0)).Add(ops)
|
op.Offset(f32.Pt(float32(x*50), 0)).Add(ops)
|
||||||
for y := 0; y < 9; y++ {
|
for y := 0; y < 9; y++ {
|
||||||
pi := op.Push(ops)
|
pi := op.Push(ops)
|
||||||
paint.ColorOp{Color: color.RGBA{R: 100 + uint8(x), G: 100 + uint8(y), B: 100, A: 120}}.Add(ops)
|
paint.ColorOp{Color: color.RGBA{R: 100 + uint8(x), G: 100 + uint8(y), B: 100, A: 120}}.Add(ops)
|
||||||
clip.Rect{Rect: f32.Rect(0, 0, 25, 25), NE: 10, SE: 10, SW: 10, NW: 10}.Add(ops)
|
clip.Rect{Rect: f32.Rect(0, 0, 25, 25), NE: 10, SE: 10, SW: 10, NW: 10}.Add(ops)
|
||||||
paint.PaintOp{Rect: f32.Rect(0, 0, 25, 25)}.Add(ops)
|
paint.PaintOp{Rect: f32.Rect(0, 0, 25, 25)}.Add(ops)
|
||||||
pi.Pop()
|
pi.Pop()
|
||||||
op.TransformOp{}.Offset(f32.Pt(0, float32(50))).Add(ops)
|
op.Offset(f32.Pt(0, float32(50))).Add(ops)
|
||||||
}
|
}
|
||||||
p.Pop()
|
p.Pop()
|
||||||
}
|
}
|
||||||
@@ -241,7 +241,7 @@ func drawShapeInstances(gtx layout.Context, th *material.Theme) chan op.CallOp {
|
|||||||
for x := 0; x < 20; x++ {
|
for x := 0; x < 20; x++ {
|
||||||
for y := 0; y < 20; y++ {
|
for y := 0; y < 20; y++ {
|
||||||
p := op.Push(ops)
|
p := op.Push(ops)
|
||||||
op.TransformOp{}.Offset(f32.Pt(float32(x*50+25), float32(y*50+25))).Add(ops)
|
op.Offset(f32.Pt(float32(x*50+25), float32(y*50+25))).Add(ops)
|
||||||
c.Add(ops)
|
c.Add(ops)
|
||||||
p.Pop()
|
p.Pop()
|
||||||
rad += math.Pi * 2 / 400
|
rad += math.Pi * 2 / 400
|
||||||
@@ -262,7 +262,7 @@ func drawText(gtx layout.Context, th *material.Theme) chan op.CallOp {
|
|||||||
for x := 0; x < 40; x++ {
|
for x := 0; x < 40; x++ {
|
||||||
txt.Text = textRows[x]
|
txt.Text = textRows[x]
|
||||||
p := op.Push(ops)
|
p := op.Push(ops)
|
||||||
op.TransformOp{}.Offset(f32.Pt(float32(0), float32(24*x))).Add(ops)
|
op.Offset(f32.Pt(float32(0), float32(24*x))).Add(ops)
|
||||||
gtx.Ops = ops
|
gtx.Ops = ops
|
||||||
txt.Layout(gtx)
|
txt.Layout(gtx)
|
||||||
p.Pop()
|
p.Pop()
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func TestTransformMacro(t *testing.T) {
|
|||||||
paint.ColorOp{Color: colornames.Red}.Add(o)
|
paint.ColorOp{Color: colornames.Red}.Add(o)
|
||||||
// Simulate a draw text call
|
// Simulate a draw text call
|
||||||
stack := op.Push(o)
|
stack := op.Push(o)
|
||||||
op.TransformOp{}.Offset(f32.Pt(0, 10)).Add(o)
|
op.Offset(f32.Pt(0, 10)).Add(o)
|
||||||
|
|
||||||
// Actually create the text clip-path
|
// Actually create the text clip-path
|
||||||
c.Add(o)
|
c.Add(o)
|
||||||
@@ -43,11 +43,11 @@ func TestTransformMacro(t *testing.T) {
|
|||||||
|
|
||||||
// Call each of them in a transform
|
// Call each of them in a transform
|
||||||
s1 := op.Push(o)
|
s1 := op.Push(o)
|
||||||
op.TransformOp{}.Offset(f32.Pt(0, 0)).Add(o)
|
op.Offset(f32.Pt(0, 0)).Add(o)
|
||||||
c1.Add(o)
|
c1.Add(o)
|
||||||
s1.Pop()
|
s1.Pop()
|
||||||
s2 := op.Push(o)
|
s2 := op.Push(o)
|
||||||
op.TransformOp{}.Offset(f32.Pt(0, 0)).Add(o)
|
op.Offset(f32.Pt(0, 0)).Add(o)
|
||||||
c2.Add(o)
|
c2.Add(o)
|
||||||
s2.Pop()
|
s2.Pop()
|
||||||
}, func(r result) {
|
}, func(r result) {
|
||||||
@@ -142,7 +142,7 @@ func TestReuseStencil(t *testing.T) {
|
|||||||
stack1.Pop()
|
stack1.Pop()
|
||||||
|
|
||||||
stack2 := op.Push(ops)
|
stack2 := op.Push(ops)
|
||||||
op.TransformOp{}.Offset(f32.Pt(0, 50)).Add(ops)
|
op.Offset(f32.Pt(0, 50)).Add(ops)
|
||||||
c2.Add(ops)
|
c2.Add(ops)
|
||||||
stack2.Pop()
|
stack2.Pop()
|
||||||
}, func(r result) {
|
}, func(r result) {
|
||||||
@@ -159,7 +159,7 @@ func TestBuildOffscreen(t *testing.T) {
|
|||||||
txt := constSqCirc()
|
txt := constSqCirc()
|
||||||
draw := func(off float32, o *op.Ops) {
|
draw := func(off float32, o *op.Ops) {
|
||||||
s := op.Push(o)
|
s := op.Push(o)
|
||||||
op.TransformOp{}.Offset(f32.Pt(0, off)).Add(o)
|
op.Offset(f32.Pt(0, off)).Add(o)
|
||||||
txt.Add(o)
|
txt.Add(o)
|
||||||
paint.PaintOp{Rect: f32.Rect(0, 0, 40, 40)}.Add(o)
|
paint.PaintOp{Rect: f32.Rect(0, 0, 40, 40)}.Add(o)
|
||||||
s.Pop()
|
s.Pop()
|
||||||
|
|||||||
+1
-1
@@ -182,7 +182,7 @@ func (f Flex) Layout(gtx Context, children ...FlexChild) Dimensions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
stack := op.Push(gtx.Ops)
|
stack := op.Push(gtx.Ops)
|
||||||
op.TransformOp{}.Offset(FPt(axisPoint(f.Axis, mainSize, cross))).Add(gtx.Ops)
|
op.Offset(FPt(axisPoint(f.Axis, mainSize, cross))).Add(gtx.Ops)
|
||||||
child.call.Add(gtx.Ops)
|
child.call.Add(gtx.Ops)
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
mainSize += axisMain(f.Axis, dims.Size)
|
mainSize += axisMain(f.Axis, dims.Size)
|
||||||
|
|||||||
+2
-2
@@ -136,7 +136,7 @@ func (in Inset) Layout(gtx Context, w Widget) Dimensions {
|
|||||||
mcs.Min.Y = mcs.Max.Y
|
mcs.Min.Y = mcs.Max.Y
|
||||||
}
|
}
|
||||||
stack := op.Push(gtx.Ops)
|
stack := op.Push(gtx.Ops)
|
||||||
op.TransformOp{}.Offset(FPt(image.Point{X: left, Y: top})).Add(gtx.Ops)
|
op.Offset(FPt(image.Point{X: left, Y: top})).Add(gtx.Ops)
|
||||||
gtx.Constraints = mcs
|
gtx.Constraints = mcs
|
||||||
dims := w(gtx)
|
dims := w(gtx)
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
@@ -180,7 +180,7 @@ func (a Direction) Layout(gtx Context, w Widget) Dimensions {
|
|||||||
p.Y = sz.Y - dims.Size.Y
|
p.Y = sz.Y - dims.Size.Y
|
||||||
}
|
}
|
||||||
stack := op.Push(gtx.Ops)
|
stack := op.Push(gtx.Ops)
|
||||||
op.TransformOp{}.Offset(FPt(p)).Add(gtx.Ops)
|
op.Offset(FPt(p)).Add(gtx.Ops)
|
||||||
call.Add(gtx.Ops)
|
call.Add(gtx.Ops)
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
return Dimensions{
|
return Dimensions{
|
||||||
|
|||||||
+1
-1
@@ -259,7 +259,7 @@ func (l *List) layout() Dimensions {
|
|||||||
}
|
}
|
||||||
stack := op.Push(ops)
|
stack := op.Push(ops)
|
||||||
clip.Rect{Rect: FRect(r)}.Op(ops).Add(ops)
|
clip.Rect{Rect: FRect(r)}.Op(ops).Add(ops)
|
||||||
op.TransformOp{}.Offset(FPt(axisPoint(l.Axis, pos, cross))).Add(ops)
|
op.Offset(FPt(axisPoint(l.Axis, pos, cross))).Add(ops)
|
||||||
child.call.Add(ops)
|
child.call.Add(ops)
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
pos += childSize
|
pos += childSize
|
||||||
|
|||||||
+1
-1
@@ -108,7 +108,7 @@ func (s Stack) Layout(gtx Context, children ...StackChild) Dimensions {
|
|||||||
p.Y = maxSZ.Y - sz.Y
|
p.Y = maxSZ.Y - sz.Y
|
||||||
}
|
}
|
||||||
stack := op.Push(gtx.Ops)
|
stack := op.Push(gtx.Ops)
|
||||||
op.TransformOp{}.Offset(FPt(p)).Add(gtx.Ops)
|
op.Offset(FPt(p)).Add(gtx.Ops)
|
||||||
ch.call.Add(gtx.Ops)
|
ch.call.Add(gtx.Ops)
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
if baseline == 0 {
|
if baseline == 0 {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ The StackOp saves the current state to the state stack and restores it later:
|
|||||||
// Save the current state, in particular the transform.
|
// Save the current state, in particular the transform.
|
||||||
stack := op.Push(ops)
|
stack := op.Push(ops)
|
||||||
// Apply a transform to subsequent operations.
|
// Apply a transform to subsequent operations.
|
||||||
op.TransformOp{}.Offset(...).Add(ops)
|
op.Offset(...).Add(ops)
|
||||||
...
|
...
|
||||||
// Restore the previous transform.
|
// Restore the previous transform.
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
@@ -274,12 +274,6 @@ func Affine(a f32.Affine2D) TransformOp {
|
|||||||
return TransformOp{t: a}
|
return TransformOp{t: a}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Offset the transfomraiton.
|
|
||||||
func (t TransformOp) Offset(o f32.Point) TransformOp {
|
|
||||||
t.t = t.t.Offset(o)
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t TransformOp) Add(o *Ops) {
|
func (t TransformOp) Add(o *Ops) {
|
||||||
data := o.Write(opconst.TypeTransformLen)
|
data := o.Write(opconst.TypeTransformLen)
|
||||||
data[0] = byte(opconst.TypeTransform)
|
data[0] = byte(opconst.TypeTransform)
|
||||||
|
|||||||
+1
-1
@@ -405,7 +405,7 @@ func (e *Editor) PaintText(gtx layout.Context) {
|
|||||||
clip.Max = clip.Max.Add(e.viewSize)
|
clip.Max = clip.Max.Add(e.viewSize)
|
||||||
for _, shape := range e.shapes {
|
for _, shape := range e.shapes {
|
||||||
stack := op.Push(gtx.Ops)
|
stack := op.Push(gtx.Ops)
|
||||||
op.TransformOp{}.Offset(shape.offset).Add(gtx.Ops)
|
op.Offset(shape.offset).Add(gtx.Ops)
|
||||||
shape.clip.Add(gtx.Ops)
|
shape.clip.Add(gtx.Ops)
|
||||||
paint.PaintOp{Rect: layout.FRect(clip).Sub(shape.offset)}.Add(gtx.Ops)
|
paint.PaintOp{Rect: layout.FRect(clip).Sub(shape.offset)}.Add(gtx.Ops)
|
||||||
stack.Pop()
|
stack.Pop()
|
||||||
|
|||||||
+1
-1
@@ -108,7 +108,7 @@ func (l Label) Layout(gtx layout.Context, s text.Shaper, font text.Font, size un
|
|||||||
}
|
}
|
||||||
lclip := layout.FRect(clip).Sub(off)
|
lclip := layout.FRect(clip).Sub(off)
|
||||||
stack := op.Push(gtx.Ops)
|
stack := op.Push(gtx.Ops)
|
||||||
op.TransformOp{}.Offset(off).Add(gtx.Ops)
|
op.Offset(off).Add(gtx.Ops)
|
||||||
str := txt[start:end]
|
str := txt[start:end]
|
||||||
s.ShapeString(font, textSize, str, l).Add(gtx.Ops)
|
s.ShapeString(font, textSize, str, l).Add(gtx.Ops)
|
||||||
paint.PaintOp{Rect: lclip}.Add(gtx.Ops)
|
paint.PaintOp{Rect: lclip}.Add(gtx.Ops)
|
||||||
|
|||||||
@@ -281,10 +281,10 @@ func drawInk(gtx layout.Context, c widget.Press) {
|
|||||||
ink := paint.ColorOp{Color: color.RGBA{A: ba, R: bc, G: bc, B: bc}}
|
ink := paint.ColorOp{Color: color.RGBA{A: ba, R: bc, G: bc, B: bc}}
|
||||||
ink.Add(gtx.Ops)
|
ink.Add(gtx.Ops)
|
||||||
rr := size * .5
|
rr := size * .5
|
||||||
op.TransformOp{}.Offset(c.Position).Offset(f32.Point{
|
op.Offset(c.Position.Add(f32.Point{
|
||||||
X: -rr,
|
X: -rr,
|
||||||
Y: -rr,
|
Y: -rr,
|
||||||
}).Add(gtx.Ops)
|
})).Add(gtx.Ops)
|
||||||
clip.Rect{
|
clip.Rect{
|
||||||
Rect: f32.Rectangle{Max: f32.Point{
|
Rect: f32.Rectangle{Max: f32.Point{
|
||||||
X: float32(size),
|
X: float32(size),
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
|
|||||||
col = mulAlpha(col, 150)
|
col = mulAlpha(col, 150)
|
||||||
}
|
}
|
||||||
trackColor := mulAlpha(col, 150)
|
trackColor := mulAlpha(col, 150)
|
||||||
op.TransformOp{}.Offset(f32.Point{Y: trackOff}).Add(gtx.Ops)
|
op.Offset(f32.Point{Y: trackOff}).Add(gtx.Ops)
|
||||||
clip.Rect{
|
clip.Rect{
|
||||||
Rect: trackRect,
|
Rect: trackRect,
|
||||||
NE: trackCorner, NW: trackCorner, SE: trackCorner, SW: trackCorner,
|
NE: trackCorner, NW: trackCorner, SE: trackCorner, SW: trackCorner,
|
||||||
@@ -72,7 +72,7 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
|
|||||||
X: float32(trackWidth)*.5 - rr,
|
X: float32(trackWidth)*.5 - rr,
|
||||||
Y: -rr + float32(trackHeight)*.5 + trackOff,
|
Y: -rr + float32(trackHeight)*.5 + trackOff,
|
||||||
}
|
}
|
||||||
op.TransformOp{}.Offset(inkOff).Add(gtx.Ops)
|
op.Offset(inkOff).Add(gtx.Ops)
|
||||||
gtx.Constraints.Min = image.Pt(inkSize, inkSize)
|
gtx.Constraints.Min = image.Pt(inkSize, inkSize)
|
||||||
clip.Rect{
|
clip.Rect{
|
||||||
Rect: f32.Rectangle{
|
Rect: f32.Rectangle{
|
||||||
@@ -89,7 +89,7 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
|
|||||||
stack = op.Push(gtx.Ops)
|
stack = op.Push(gtx.Ops)
|
||||||
if s.Switch.Value {
|
if s.Switch.Value {
|
||||||
off := trackWidth - thumbSize
|
off := trackWidth - thumbSize
|
||||||
op.TransformOp{}.Offset(f32.Point{X: float32(off)}).Add(gtx.Ops)
|
op.Offset(f32.Point{X: float32(off)}).Add(gtx.Ops)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw thumb shadow, a translucent disc slightly larger than the
|
// Draw thumb shadow, a translucent disc slightly larger than the
|
||||||
@@ -97,7 +97,7 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
|
|||||||
shadowStack := op.Push(gtx.Ops)
|
shadowStack := op.Push(gtx.Ops)
|
||||||
shadowSize := float32(2)
|
shadowSize := float32(2)
|
||||||
// Center shadow horizontally and slightly adjust its Y.
|
// Center shadow horizontally and slightly adjust its Y.
|
||||||
op.TransformOp{}.Offset(f32.Point{X: -shadowSize / 2, Y: -.75}).Add(gtx.Ops)
|
op.Offset(f32.Point{X: -shadowSize / 2, Y: -.75}).Add(gtx.Ops)
|
||||||
drawDisc(gtx.Ops, float32(thumbSize)+shadowSize, argb(0x55000000))
|
drawDisc(gtx.Ops, float32(thumbSize)+shadowSize, argb(0x55000000))
|
||||||
shadowStack.Pop()
|
shadowStack.Pop()
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
|
|||||||
X: (float32(trackWidth) - float32(clickSize)) * .5,
|
X: (float32(trackWidth) - float32(clickSize)) * .5,
|
||||||
Y: (float32(trackHeight)-float32(clickSize))*.5 + trackOff,
|
Y: (float32(trackHeight)-float32(clickSize))*.5 + trackOff,
|
||||||
}
|
}
|
||||||
op.TransformOp{}.Offset(clickOff).Add(gtx.Ops)
|
op.Offset(clickOff).Add(gtx.Ops)
|
||||||
sz := image.Pt(clickSize, clickSize)
|
sz := image.Pt(clickSize, clickSize)
|
||||||
pointer.Ellipse(image.Rectangle{Max: sz}).Add(gtx.Ops)
|
pointer.Ellipse(image.Rectangle{Max: sz}).Add(gtx.Ops)
|
||||||
gtx.Constraints.Min = sz
|
gtx.Constraints.Min = sz
|
||||||
|
|||||||
Reference in New Issue
Block a user