mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-02 07:57:29 +00:00
op: rename StackOp/Push/Pop to StateOp/Save/Load
The semantics were relaxed in a previous commit; this change renames to operations accordingly. API change. Use gofmt to adjust your code accordingly: gofmt -r 'op.Push(a).Pop() -> op.Save(a).Load()' gofmt -r 'op.Push(a) -> op.Save(a)' gofmt -r 'v.Pop() -> v.Load()' gofmt -r 'op.StackOp -> op.StateOp' Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -82,13 +82,13 @@ func BenchmarkDrawUI(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
resetOps(gtx)
|
||||
|
||||
p := op.Push(gtx.Ops)
|
||||
p := op.Save(gtx.Ops)
|
||||
off := float32(math.Mod(float64(i)/10, 10))
|
||||
op.Offset(f32.Pt(off, off)).Add(gtx.Ops)
|
||||
|
||||
drawCore(gtx, th)
|
||||
|
||||
p.Pop()
|
||||
p.Load()
|
||||
w.Frame(gtx.Ops)
|
||||
}
|
||||
finishBenchmark(b, w)
|
||||
@@ -104,14 +104,14 @@ func BenchmarkDrawUITransformed(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
resetOps(gtx)
|
||||
|
||||
p := op.Push(gtx.Ops)
|
||||
p := op.Save(gtx.Ops)
|
||||
angle := float32(math.Mod(float64(i)/1000, 0.05))
|
||||
a := f32.Affine2D{}.Shear(f32.Point{}, angle, angle).Rotate(f32.Point{}, angle)
|
||||
op.Affine(a).Add(gtx.Ops)
|
||||
|
||||
drawCore(gtx, th)
|
||||
|
||||
p.Pop()
|
||||
p.Load()
|
||||
w.Frame(gtx.Ops)
|
||||
}
|
||||
finishBenchmark(b, w)
|
||||
@@ -153,7 +153,7 @@ func Benchmark1000CirclesInstanced(b *testing.B) {
|
||||
func draw1000Circles(gtx layout.Context) {
|
||||
ops := gtx.Ops
|
||||
for x := 0; x < 100; x++ {
|
||||
p := op.Push(ops)
|
||||
p := op.Save(ops)
|
||||
op.Offset(f32.Pt(float32(x*10), 0)).Add(ops)
|
||||
for y := 0; y < 10; y++ {
|
||||
paint.FillShape(ops,
|
||||
@@ -162,7 +162,7 @@ func draw1000Circles(gtx layout.Context) {
|
||||
)
|
||||
op.Offset(f32.Pt(0, float32(100))).Add(ops)
|
||||
}
|
||||
p.Pop()
|
||||
p.Load()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,16 +175,16 @@ func draw1000CirclesInstanced(gtx layout.Context) {
|
||||
c := r.Stop()
|
||||
|
||||
for x := 0; x < 100; x++ {
|
||||
p := op.Push(ops)
|
||||
p := op.Save(ops)
|
||||
op.Offset(f32.Pt(float32(x*10), 0)).Add(ops)
|
||||
for y := 0; y < 10; y++ {
|
||||
pi := op.Push(ops)
|
||||
pi := op.Save(ops)
|
||||
paint.ColorOp{Color: color.NRGBA{R: 100 + uint8(x), G: 100 + uint8(y), B: 100, A: 120}}.Add(ops)
|
||||
c.Add(ops)
|
||||
pi.Pop()
|
||||
pi.Load()
|
||||
op.Offset(f32.Pt(0, float32(100))).Add(ops)
|
||||
}
|
||||
p.Pop()
|
||||
p.Load()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ func drawIndividualShapes(gtx layout.Context, th *material.Theme) chan op.CallOp
|
||||
ops := &op1
|
||||
c := op.Record(ops)
|
||||
for x := 0; x < 9; x++ {
|
||||
p := op.Push(ops)
|
||||
p := op.Save(ops)
|
||||
op.Offset(f32.Pt(float32(x*50), 0)).Add(ops)
|
||||
for y := 0; y < 9; y++ {
|
||||
paint.FillShape(ops,
|
||||
@@ -213,7 +213,7 @@ func drawIndividualShapes(gtx layout.Context, th *material.Theme) chan op.CallOp
|
||||
)
|
||||
op.Offset(f32.Pt(0, float32(50))).Add(ops)
|
||||
}
|
||||
p.Pop()
|
||||
p.Load()
|
||||
}
|
||||
c1 <- c.Stop()
|
||||
}()
|
||||
@@ -235,10 +235,10 @@ func drawShapeInstances(gtx layout.Context, th *material.Theme) chan op.CallOp {
|
||||
rad := float32(0)
|
||||
for x := 0; x < 20; x++ {
|
||||
for y := 0; y < 20; y++ {
|
||||
p := op.Push(ops)
|
||||
p := op.Save(ops)
|
||||
op.Offset(f32.Pt(float32(x*50+25), float32(y*50+25))).Add(ops)
|
||||
c.Add(ops)
|
||||
p.Pop()
|
||||
p.Load()
|
||||
rad += math.Pi * 2 / 400
|
||||
}
|
||||
}
|
||||
@@ -256,11 +256,11 @@ func drawText(gtx layout.Context, th *material.Theme) chan op.CallOp {
|
||||
txt := material.H6(th, "")
|
||||
for x := 0; x < 40; x++ {
|
||||
txt.Text = textRows[x]
|
||||
p := op.Push(ops)
|
||||
p := op.Save(ops)
|
||||
op.Offset(f32.Pt(float32(0), float32(24*x))).Add(ops)
|
||||
gtx.Ops = ops
|
||||
txt.Layout(gtx)
|
||||
p.Pop()
|
||||
p.Load()
|
||||
}
|
||||
c3 <- c.Stop()
|
||||
}()
|
||||
|
||||
@@ -229,7 +229,7 @@ func TestStrokedPathRoundRound(t *testing.T) {
|
||||
func TestStrokedPathFlatMiter(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
{
|
||||
stk := op.Push(o)
|
||||
stk := op.Save(o)
|
||||
p := newZigZagPath(o)
|
||||
clip.Stroke{
|
||||
Path: p,
|
||||
@@ -241,10 +241,10 @@ func TestStrokedPathFlatMiter(t *testing.T) {
|
||||
},
|
||||
}.Op().Add(o)
|
||||
paint.Fill(o, red)
|
||||
stk.Pop()
|
||||
stk.Load()
|
||||
}
|
||||
{
|
||||
stk := op.Push(o)
|
||||
stk := op.Save(o)
|
||||
p := newZigZagPath(o)
|
||||
clip.Stroke{
|
||||
Path: p,
|
||||
@@ -253,7 +253,7 @@ func TestStrokedPathFlatMiter(t *testing.T) {
|
||||
},
|
||||
}.Op().Add(o)
|
||||
paint.Fill(o, black)
|
||||
stk.Pop()
|
||||
stk.Load()
|
||||
}
|
||||
|
||||
}, func(r result) {
|
||||
@@ -266,7 +266,7 @@ func TestStrokedPathFlatMiter(t *testing.T) {
|
||||
func TestStrokedPathFlatMiterInf(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
{
|
||||
stk := op.Push(o)
|
||||
stk := op.Save(o)
|
||||
p := newZigZagPath(o)
|
||||
clip.Stroke{
|
||||
Path: p,
|
||||
@@ -278,10 +278,10 @@ func TestStrokedPathFlatMiterInf(t *testing.T) {
|
||||
},
|
||||
}.Op().Add(o)
|
||||
paint.Fill(o, red)
|
||||
stk.Pop()
|
||||
stk.Load()
|
||||
}
|
||||
{
|
||||
stk := op.Push(o)
|
||||
stk := op.Save(o)
|
||||
p := newZigZagPath(o)
|
||||
clip.Stroke{
|
||||
Path: p,
|
||||
@@ -290,7 +290,7 @@ func TestStrokedPathFlatMiterInf(t *testing.T) {
|
||||
},
|
||||
}.Op().Add(o)
|
||||
paint.Fill(o, black)
|
||||
stk.Pop()
|
||||
stk.Load()
|
||||
}
|
||||
|
||||
}, func(r result) {
|
||||
@@ -303,7 +303,7 @@ func TestStrokedPathFlatMiterInf(t *testing.T) {
|
||||
func TestStrokedPathZeroWidth(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
{
|
||||
stk := op.Push(o)
|
||||
stk := op.Save(o)
|
||||
p := new(clip.Path)
|
||||
p.Begin(o)
|
||||
p.Move(f32.Pt(10, 50))
|
||||
@@ -316,11 +316,11 @@ func TestStrokedPathZeroWidth(t *testing.T) {
|
||||
}.Op().Add(o)
|
||||
|
||||
paint.Fill(o, black)
|
||||
stk.Pop()
|
||||
stk.Load()
|
||||
}
|
||||
|
||||
{
|
||||
stk := op.Push(o)
|
||||
stk := op.Save(o)
|
||||
p := new(clip.Path)
|
||||
p.Begin(o)
|
||||
p.Move(f32.Pt(10, 50))
|
||||
@@ -330,7 +330,7 @@ func TestStrokedPathZeroWidth(t *testing.T) {
|
||||
}.Op().Add(o) // width=0, disable stroke
|
||||
|
||||
paint.Fill(o, red)
|
||||
stk.Pop()
|
||||
stk.Load()
|
||||
}
|
||||
|
||||
}, func(r result) {
|
||||
@@ -344,7 +344,7 @@ func TestStrokedPathZeroWidth(t *testing.T) {
|
||||
func TestDashedPathFlatCapEllipse(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
{
|
||||
stk := op.Push(o)
|
||||
stk := op.Save(o)
|
||||
p := newEllipsePath(o)
|
||||
|
||||
var dash clip.Dash
|
||||
@@ -367,10 +367,10 @@ func TestDashedPathFlatCapEllipse(t *testing.T) {
|
||||
o,
|
||||
red,
|
||||
)
|
||||
stk.Pop()
|
||||
stk.Load()
|
||||
}
|
||||
{
|
||||
stk := op.Push(o)
|
||||
stk := op.Save(o)
|
||||
p := newEllipsePath(o)
|
||||
clip.Stroke{
|
||||
Path: p,
|
||||
@@ -383,7 +383,7 @@ func TestDashedPathFlatCapEllipse(t *testing.T) {
|
||||
o,
|
||||
black,
|
||||
)
|
||||
stk.Pop()
|
||||
stk.Load()
|
||||
}
|
||||
|
||||
}, func(r result) {
|
||||
@@ -396,7 +396,7 @@ func TestDashedPathFlatCapEllipse(t *testing.T) {
|
||||
func TestDashedPathFlatCapZ(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
{
|
||||
stk := op.Push(o)
|
||||
stk := op.Save(o)
|
||||
p := newZigZagPath(o)
|
||||
var dash clip.Dash
|
||||
dash.Begin(o)
|
||||
@@ -414,18 +414,18 @@ func TestDashedPathFlatCapZ(t *testing.T) {
|
||||
Dashes: dash.End(),
|
||||
}.Op().Add(o)
|
||||
paint.Fill(o, red)
|
||||
stk.Pop()
|
||||
stk.Load()
|
||||
}
|
||||
|
||||
{
|
||||
stk := op.Push(o)
|
||||
stk := op.Save(o)
|
||||
p := newZigZagPath(o)
|
||||
clip.Stroke{
|
||||
Path: p,
|
||||
Style: clip.StrokeStyle{Width: 2},
|
||||
}.Op().Add(o)
|
||||
paint.Fill(o, black)
|
||||
stk.Pop()
|
||||
stk.Load()
|
||||
}
|
||||
}, func(r result) {
|
||||
r.expect(0, 0, colornames.White)
|
||||
@@ -438,7 +438,7 @@ func TestDashedPathFlatCapZ(t *testing.T) {
|
||||
func TestDashedPathFlatCapZNoDash(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
{
|
||||
stk := op.Push(o)
|
||||
stk := op.Save(o)
|
||||
p := newZigZagPath(o)
|
||||
var dash clip.Dash
|
||||
dash.Begin(o)
|
||||
@@ -455,16 +455,16 @@ func TestDashedPathFlatCapZNoDash(t *testing.T) {
|
||||
Dashes: dash.End(),
|
||||
}.Op().Add(o)
|
||||
paint.Fill(o, red)
|
||||
stk.Pop()
|
||||
stk.Load()
|
||||
}
|
||||
{
|
||||
stk := op.Push(o)
|
||||
stk := op.Save(o)
|
||||
clip.Stroke{
|
||||
Path: newZigZagPath(o),
|
||||
Style: clip.StrokeStyle{Width: 2},
|
||||
}.Op().Add(o)
|
||||
paint.Fill(o, black)
|
||||
stk.Pop()
|
||||
stk.Load()
|
||||
}
|
||||
}, func(r result) {
|
||||
r.expect(0, 0, colornames.White)
|
||||
@@ -477,7 +477,7 @@ func TestDashedPathFlatCapZNoDash(t *testing.T) {
|
||||
func TestDashedPathFlatCapZNoPath(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
{
|
||||
stk := op.Push(o)
|
||||
stk := op.Save(o)
|
||||
var dash clip.Dash
|
||||
dash.Begin(o)
|
||||
dash.Dash(0)
|
||||
@@ -492,17 +492,17 @@ func TestDashedPathFlatCapZNoPath(t *testing.T) {
|
||||
Dashes: dash.End(),
|
||||
}.Op().Add(o)
|
||||
paint.Fill(o, red)
|
||||
stk.Pop()
|
||||
stk.Load()
|
||||
}
|
||||
{
|
||||
stk := op.Push(o)
|
||||
stk := op.Save(o)
|
||||
p := newZigZagPath(o)
|
||||
clip.Stroke{
|
||||
Path: p,
|
||||
Style: clip.StrokeStyle{Width: 2},
|
||||
}.Op().Add(o)
|
||||
paint.Fill(o, black)
|
||||
stk.Pop()
|
||||
stk.Load()
|
||||
}
|
||||
}, func(r result) {
|
||||
r.expect(0, 0, colornames.White)
|
||||
|
||||
@@ -33,26 +33,26 @@ func TestTransformMacro(t *testing.T) {
|
||||
m2 := op.Record(o)
|
||||
paint.ColorOp{Color: red}.Add(o)
|
||||
// Simulate a draw text call
|
||||
stack := op.Push(o)
|
||||
stack := op.Save(o)
|
||||
op.Offset(f32.Pt(0, 10)).Add(o)
|
||||
|
||||
// Apply the clip-path.
|
||||
c.Add(o)
|
||||
|
||||
paint.PaintOp{}.Add(o)
|
||||
stack.Pop()
|
||||
stack.Load()
|
||||
|
||||
c2 := m2.Stop()
|
||||
|
||||
// Call each of them in a transform
|
||||
s1 := op.Push(o)
|
||||
s1 := op.Save(o)
|
||||
op.Offset(f32.Pt(0, 0)).Add(o)
|
||||
c1.Add(o)
|
||||
s1.Pop()
|
||||
s2 := op.Push(o)
|
||||
s1.Load()
|
||||
s2 := op.Save(o)
|
||||
op.Offset(f32.Pt(0, 0)).Add(o)
|
||||
c2.Add(o)
|
||||
s2.Pop()
|
||||
s2.Load()
|
||||
}, func(r result) {
|
||||
r.expect(5, 15, colornames.Red)
|
||||
r.expect(15, 15, colornames.Black)
|
||||
@@ -140,14 +140,14 @@ func TestReuseStencil(t *testing.T) {
|
||||
c2 := drawChild(ops, txt)
|
||||
|
||||
// lay out the children
|
||||
stack1 := op.Push(ops)
|
||||
stack1 := op.Save(ops)
|
||||
c1.Add(ops)
|
||||
stack1.Pop()
|
||||
stack1.Load()
|
||||
|
||||
stack2 := op.Push(ops)
|
||||
stack2 := op.Save(ops)
|
||||
op.Offset(f32.Pt(0, 50)).Add(ops)
|
||||
c2.Add(ops)
|
||||
stack2.Pop()
|
||||
stack2.Load()
|
||||
}, func(r result) {
|
||||
r.expect(5, 5, colornames.Black)
|
||||
r.expect(5, 55, colornames.Black)
|
||||
@@ -161,11 +161,11 @@ func TestBuildOffscreen(t *testing.T) {
|
||||
|
||||
txt := constSqCirc()
|
||||
draw := func(off float32, o *op.Ops) {
|
||||
s := op.Push(o)
|
||||
s := op.Save(o)
|
||||
op.Offset(f32.Pt(0, off)).Add(o)
|
||||
txt.Add(o)
|
||||
paint.PaintOp{}.Add(o)
|
||||
s.Pop()
|
||||
s.Load()
|
||||
}
|
||||
|
||||
multiRun(t,
|
||||
@@ -230,12 +230,12 @@ func TestLinearGradient(t *testing.T) {
|
||||
Stop2: f32.Pt(gr.Max.X, gr.Min.Y),
|
||||
Color2: g.To,
|
||||
}.Add(ops)
|
||||
st := op.Push(ops)
|
||||
st := op.Save(ops)
|
||||
clip.RRect{Rect: gr}.Add(ops)
|
||||
op.Affine(f32.Affine2D{}.Offset(pixelAligned.Min)).Add(ops)
|
||||
scale(pixelAligned.Dx()/128, 1).Add(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
st.Pop()
|
||||
st.Load()
|
||||
gr = gr.Add(f32.Pt(0, gradienth))
|
||||
}
|
||||
}, func(r result) {
|
||||
@@ -260,10 +260,10 @@ func TestLinearGradientAngled(t *testing.T) {
|
||||
Stop2: f32.Pt(0, 0),
|
||||
Color2: red,
|
||||
}.Add(ops)
|
||||
st := op.Push(ops)
|
||||
st := op.Save(ops)
|
||||
clip.Rect(image.Rect(0, 0, 64, 64)).Add(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
st.Pop()
|
||||
st.Load()
|
||||
|
||||
paint.LinearGradientOp{
|
||||
Stop1: f32.Pt(64, 64),
|
||||
@@ -271,10 +271,10 @@ func TestLinearGradientAngled(t *testing.T) {
|
||||
Stop2: f32.Pt(128, 0),
|
||||
Color2: green,
|
||||
}.Add(ops)
|
||||
st = op.Push(ops)
|
||||
st = op.Save(ops)
|
||||
clip.Rect(image.Rect(64, 0, 128, 64)).Add(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
st.Pop()
|
||||
st.Load()
|
||||
|
||||
paint.LinearGradientOp{
|
||||
Stop1: f32.Pt(64, 64),
|
||||
@@ -282,10 +282,10 @@ func TestLinearGradientAngled(t *testing.T) {
|
||||
Stop2: f32.Pt(128, 128),
|
||||
Color2: blue,
|
||||
}.Add(ops)
|
||||
st = op.Push(ops)
|
||||
st = op.Save(ops)
|
||||
clip.Rect(image.Rect(64, 64, 128, 128)).Add(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
st.Pop()
|
||||
st.Load()
|
||||
|
||||
paint.LinearGradientOp{
|
||||
Stop1: f32.Pt(64, 64),
|
||||
@@ -293,10 +293,10 @@ func TestLinearGradientAngled(t *testing.T) {
|
||||
Stop2: f32.Pt(0, 128),
|
||||
Color2: magenta,
|
||||
}.Add(ops)
|
||||
st = op.Push(ops)
|
||||
st = op.Save(ops)
|
||||
clip.Rect(image.Rect(0, 64, 64, 128)).Add(ops)
|
||||
paint.PaintOp{}.Add(ops)
|
||||
st.Pop()
|
||||
st.Load()
|
||||
}, func(r result) {})
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ func TestOffsetScaleTexture(t *testing.T) {
|
||||
|
||||
func TestRotateTexture(t *testing.T) {
|
||||
run(t, func(o *op.Ops) {
|
||||
defer op.Push(o).Pop()
|
||||
defer op.Save(o).Load()
|
||||
squares.Add(o)
|
||||
a := f32.Affine2D{}.Offset(f32.Pt(30, 30)).Rotate(f32.Pt(40, 40), math.Pi/4)
|
||||
op.Affine(a).Add(o)
|
||||
|
||||
Reference in New Issue
Block a user