mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-02 16:06:19 +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:
+2
-2
@@ -24,7 +24,7 @@ func (b Border) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions {
|
||||
dims := w(gtx)
|
||||
sz := dims.Size
|
||||
rr := float32(gtx.Px(b.CornerRadius))
|
||||
st := op.Push(gtx.Ops)
|
||||
st := op.Save(gtx.Ops)
|
||||
width := gtx.Px(b.Width)
|
||||
clip.Border{
|
||||
Rect: f32.Rectangle{
|
||||
@@ -35,6 +35,6 @@ func (b Border) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions {
|
||||
}.Add(gtx.Ops)
|
||||
paint.ColorOp{Color: b.Color}.Add(gtx.Ops)
|
||||
paint.PaintOp{}.Add(gtx.Ops)
|
||||
st.Pop()
|
||||
st.Load()
|
||||
return dims
|
||||
}
|
||||
|
||||
+2
-2
@@ -74,10 +74,10 @@ func (b *Clickable) History() []Press {
|
||||
|
||||
func (b *Clickable) Layout(gtx layout.Context) layout.Dimensions {
|
||||
b.update(gtx)
|
||||
stack := op.Push(gtx.Ops)
|
||||
stack := op.Save(gtx.Ops)
|
||||
pointer.Rect(image.Rectangle{Max: gtx.Constraints.Min}).Add(gtx.Ops)
|
||||
b.click.Add(gtx.Ops)
|
||||
stack.Pop()
|
||||
stack.Load()
|
||||
for len(b.history) > 0 {
|
||||
c := b.history[0]
|
||||
if c.End.IsZero() || gtx.Now.Sub(c.End) < 1*time.Second {
|
||||
|
||||
+5
-5
@@ -451,12 +451,12 @@ func (e *Editor) PaintText(gtx layout.Context) {
|
||||
cl := textPadding(e.lines)
|
||||
cl.Max = cl.Max.Add(e.viewSize)
|
||||
for _, shape := range e.shapes {
|
||||
stack := op.Push(gtx.Ops)
|
||||
stack := op.Save(gtx.Ops)
|
||||
op.Offset(layout.FPt(shape.offset)).Add(gtx.Ops)
|
||||
shape.clip.Add(gtx.Ops)
|
||||
clip.Rect(cl.Sub(shape.offset)).Add(gtx.Ops)
|
||||
paint.PaintOp{}.Add(gtx.Ops)
|
||||
stack.Pop()
|
||||
stack.Load()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -469,7 +469,7 @@ func (e *Editor) PaintCaret(gtx layout.Context) {
|
||||
carX := e.caret.x
|
||||
carY := e.caret.y
|
||||
|
||||
defer op.Push(gtx.Ops).Pop()
|
||||
defer op.Save(gtx.Ops).Load()
|
||||
carX -= carWidth / 2
|
||||
carAsc, carDesc := -e.lines[e.caret.line].Bounds.Min.Y, e.lines[e.caret.line].Bounds.Max.Y
|
||||
carRect := image.Rectangle{
|
||||
@@ -492,10 +492,10 @@ func (e *Editor) PaintCaret(gtx layout.Context) {
|
||||
cl.Max = cl.Max.Add(e.viewSize)
|
||||
carRect = cl.Intersect(carRect)
|
||||
if !carRect.Empty() {
|
||||
st := op.Push(gtx.Ops)
|
||||
st := op.Save(gtx.Ops)
|
||||
clip.Rect(carRect).Add(gtx.Ops)
|
||||
paint.PaintOp{}.Add(gtx.Ops)
|
||||
st.Pop()
|
||||
st.Load()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ func (e *Enum) Changed() bool {
|
||||
|
||||
// Layout adds the event handler for key.
|
||||
func (e *Enum) Layout(gtx layout.Context, key string) layout.Dimensions {
|
||||
defer op.Push(gtx.Ops).Pop()
|
||||
defer op.Save(gtx.Ops).Load()
|
||||
pointer.Rect(image.Rectangle{Max: gtx.Constraints.Min}).Add(gtx.Ops)
|
||||
|
||||
if index(e.values, key) == -1 {
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ func (f *Float) Layout(gtx layout.Context, pointerMargin int, min, max float32)
|
||||
f.pos = 1
|
||||
}
|
||||
|
||||
defer op.Push(gtx.Ops).Pop()
|
||||
defer op.Save(gtx.Ops).Load()
|
||||
rect := image.Rectangle{Max: size}
|
||||
rect.Min.X -= pointerMargin
|
||||
rect.Max.X += pointerMargin
|
||||
|
||||
+2
-2
@@ -32,10 +32,10 @@ func (im Image) Layout(gtx layout.Context) layout.Dimensions {
|
||||
w, h := gtx.Px(unit.Dp(wf*scale)), gtx.Px(unit.Dp(hf*scale))
|
||||
cs := gtx.Constraints
|
||||
d := cs.Constrain(image.Pt(w, h))
|
||||
stack := op.Push(gtx.Ops)
|
||||
stack := op.Save(gtx.Ops)
|
||||
clip.Rect(image.Rectangle{Max: d}).Add(gtx.Ops)
|
||||
im.Src.Add(gtx.Ops)
|
||||
paint.PaintOp{}.Add(gtx.Ops)
|
||||
stack.Pop()
|
||||
stack.Load()
|
||||
return layout.Dimensions{Size: d}
|
||||
}
|
||||
|
||||
+2
-2
@@ -110,12 +110,12 @@ func (l Label) Layout(gtx layout.Context, s text.Shaper, font text.Font, size un
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
stack := op.Push(gtx.Ops)
|
||||
stack := op.Save(gtx.Ops)
|
||||
op.Offset(layout.FPt(off)).Add(gtx.Ops)
|
||||
s.Shape(font, textSize, l).Add(gtx.Ops)
|
||||
clip.Rect(cl.Sub(off)).Add(gtx.Ops)
|
||||
paint.PaintOp{}.Add(gtx.Ops)
|
||||
stack.Pop()
|
||||
stack.Load()
|
||||
}
|
||||
return dims
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user