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:
Elias Naur
2021-01-12 20:48:41 +01:00
parent ae2c74ec13
commit d331dd2de8
25 changed files with 177 additions and 177 deletions
+1 -1
View File
@@ -271,7 +271,7 @@ func drawInk(gtx layout.Context, c widget.Press) {
alpha := 0.7 * alphaBezier
const col = 0.8
ba, bc := byte(alpha*0xff), byte(col*0xff)
defer op.Push(gtx.Ops).Pop()
defer op.Save(gtx.Ops).Load()
rgba := f32color.MulAlpha(color.NRGBA{A: 0xff, R: bc, G: bc, B: bc}, ba)
ink := paint.ColorOp{Color: rgba}
ink.Add(gtx.Ops)
+1 -1
View File
@@ -40,7 +40,7 @@ func Editor(th *Theme, editor *widget.Editor, hint string) EditorStyle {
}
func (e EditorStyle) Layout(gtx layout.Context) layout.Dimensions {
defer op.Push(gtx.Ops).Pop()
defer op.Save(gtx.Ops).Load()
macro := op.Record(gtx.Ops)
paint.ColorOp{Color: e.HintColor}.Add(gtx.Ops)
var maxlines int
+1 -1
View File
@@ -36,7 +36,7 @@ func (l LoaderStyle) Layout(gtx layout.Context) layout.Dimensions {
}
sz := gtx.Constraints.Constrain(image.Pt(diam, diam))
radius := float64(sz.X) * .5
defer op.Push(gtx.Ops).Pop()
defer op.Save(gtx.Ops).Load()
op.Offset(f32.Pt(float32(radius), float32(radius))).Add(gtx.Ops)
dt := (time.Duration(gtx.Now.UnixNano()) % (time.Second)).Seconds()
+8 -8
View File
@@ -58,13 +58,13 @@ func (s SliderStyle) Layout(gtx layout.Context) layout.Dimensions {
size.Y = 2 * (touchSizePx / 2)
}
st := op.Push(gtx.Ops)
st := op.Save(gtx.Ops)
op.Offset(f32.Pt(thumbRadius, 0)).Add(gtx.Ops)
gtx.Constraints.Min = image.Pt(size.X-2*thumbRadiusInt, size.Y)
s.Float.Layout(gtx, thumbRadiusInt, s.Min, s.Max)
gtx.Constraints.Min.Y = size.Y
thumbPos := thumbRadius + s.Float.Pos()
st.Pop()
st.Load()
color := s.Color
if gtx.Queue == nil {
@@ -72,7 +72,7 @@ func (s SliderStyle) Layout(gtx layout.Context) layout.Dimensions {
}
// Draw track before thumb.
st = op.Push(gtx.Ops)
st = op.Save(gtx.Ops)
track := f32.Rectangle{
Min: f32.Point{
X: thumbRadius,
@@ -86,19 +86,19 @@ func (s SliderStyle) Layout(gtx layout.Context) layout.Dimensions {
clip.RRect{Rect: track}.Add(gtx.Ops)
paint.ColorOp{Color: color}.Add(gtx.Ops)
paint.PaintOp{}.Add(gtx.Ops)
st.Pop()
st.Load()
// Draw track after thumb.
st = op.Push(gtx.Ops)
st = op.Save(gtx.Ops)
track.Min.X = thumbPos
track.Max.X = float32(size.X) - thumbRadius
clip.RRect{Rect: track}.Add(gtx.Ops)
paint.ColorOp{Color: f32color.MulAlpha(color, 96)}.Add(gtx.Ops)
paint.PaintOp{}.Add(gtx.Ops)
st.Pop()
st.Load()
// Draw thumb.
st = op.Push(gtx.Ops)
st = op.Save(gtx.Ops)
thumb := f32.Rectangle{
Min: f32.Point{
X: thumbPos - thumbRadius,
@@ -116,7 +116,7 @@ func (s SliderStyle) Layout(gtx layout.Context) layout.Dimensions {
}.Add(gtx.Ops)
paint.ColorOp{Color: color}.Add(gtx.Ops)
paint.PaintOp{}.Add(gtx.Ops)
st.Pop()
st.Load()
return layout.Dimensions{Size: size}
}
+11 -11
View File
@@ -45,7 +45,7 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
trackOff := float32(thumbSize-trackHeight) * .5
// Draw track.
stack := op.Push(gtx.Ops)
stack := op.Save(gtx.Ops)
trackCorner := float32(trackHeight) / 2
trackRect := f32.Rectangle{Max: f32.Point{
X: float32(trackWidth),
@@ -66,10 +66,10 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
}.Add(gtx.Ops)
paint.ColorOp{Color: trackColor}.Add(gtx.Ops)
paint.PaintOp{}.Add(gtx.Ops)
stack.Pop()
stack.Load()
// Draw thumb ink.
stack = op.Push(gtx.Ops)
stack = op.Save(gtx.Ops)
inkSize := gtx.Px(unit.Dp(44))
rr := float32(inkSize) * .5
inkOff := f32.Point{
@@ -87,10 +87,10 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
for _, p := range s.Switch.History() {
drawInk(gtx, p)
}
stack.Pop()
stack.Load()
// Compute thumb offset and color.
stack = op.Push(gtx.Ops)
stack = op.Save(gtx.Ops)
if s.Switch.Value {
off := trackWidth - thumbSize
op.Offset(f32.Point{X: float32(off)}).Add(gtx.Ops)
@@ -98,19 +98,19 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
// Draw thumb shadow, a translucent disc slightly larger than the
// thumb itself.
shadowStack := op.Push(gtx.Ops)
shadowStack := op.Save(gtx.Ops)
shadowSize := float32(2)
// Center shadow horizontally and slightly adjust its Y.
op.Offset(f32.Point{X: -shadowSize / 2, Y: -.75}).Add(gtx.Ops)
drawDisc(gtx.Ops, float32(thumbSize)+shadowSize, argb(0x55000000))
shadowStack.Pop()
shadowStack.Load()
// Draw thumb.
drawDisc(gtx.Ops, float32(thumbSize), col)
stack.Pop()
stack.Load()
// Set up click area.
stack = op.Push(gtx.Ops)
stack = op.Save(gtx.Ops)
clickSize := gtx.Px(unit.Dp(40))
clickOff := f32.Point{
X: (float32(trackWidth) - float32(clickSize)) * .5,
@@ -121,14 +121,14 @@ func (s SwitchStyle) Layout(gtx layout.Context) layout.Dimensions {
pointer.Ellipse(image.Rectangle{Max: sz}).Add(gtx.Ops)
gtx.Constraints.Min = sz
s.Switch.Layout(gtx)
stack.Pop()
stack.Load()
dims := image.Point{X: trackWidth, Y: thumbSize}
return layout.Dimensions{Size: dims}
}
func drawDisc(ops *op.Ops, sz float32, col color.NRGBA) {
defer op.Push(ops).Pop()
defer op.Save(ops).Load()
rr := sz / 2
r := f32.Rectangle{Max: f32.Point{X: sz, Y: sz}}
clip.RRect{