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
+4 -4
View File
@@ -51,13 +51,13 @@ For example:
var stack op.StackOp
var h1, h2 *Handler
stack := op.Push(ops)
state := op.Save(ops)
pointer.InputOp{Tag: h1}.Add(Ops)
stack.Pop()
state.Load()
stack = op.Push(ops)
state = op.Save(ops)
pointer.InputOp{Tag: h2}.Add(ops)
stack.Pop()
state.Load()
implies a tree of two inner nodes, each with one pointer handler.
+38 -38
View File
@@ -38,30 +38,30 @@ func TestKeyStacked(t *testing.T) {
ops := new(op.Ops)
r := new(Router)
s := op.Push(ops)
s := op.Save(ops)
key.InputOp{Tag: &handlers[0]}.Add(ops)
// FocusOp must not overwrite the
// FocusOp{Focus: true}.
key.FocusOp{Focus: false}.Add(ops)
s.Pop()
s = op.Push(ops)
s.Load()
s = op.Save(ops)
key.SoftKeyboardOp{Show: false}.Add(ops)
key.InputOp{Tag: &handlers[1]}.Add(ops)
key.FocusOp{Focus: true}.Add(ops)
s.Pop()
s = op.Push(ops)
s.Load()
s = op.Save(ops)
key.InputOp{Tag: &handlers[2]}.Add(ops)
// SoftwareKeyboardOp will open the keyboard,
// overwriting `SoftKeyboardOp{Show: false}`.
key.SoftKeyboardOp{Show: true}.Add(ops)
s.Pop()
s = op.Push(ops)
s.Load()
s = op.Save(ops)
key.SoftKeyboardOp{Show: false}.Add(ops)
key.InputOp{Tag: &handlers[3]}.Add(ops)
// FocusOp must not overwrite the
// FocusOp{Focus: true}.
key.FocusOp{Focus: false}.Add(ops)
s.Pop()
s.Load()
r.Frame(ops)
@@ -93,16 +93,16 @@ func TestKeyRemoveFocus(t *testing.T) {
r := new(Router)
// New InputOp with Focus and Keyboard:
s := op.Push(ops)
s := op.Save(ops)
key.InputOp{Tag: &handlers[0]}.Add(ops)
key.FocusOp{Focus: true}.Add(ops)
key.SoftKeyboardOp{Show: true}.Add(ops)
s.Pop()
s.Load()
// New InputOp without any focus:
s = op.Push(ops)
s = op.Save(ops)
key.InputOp{Tag: &handlers[1]}.Add(ops)
s.Pop()
s.Load()
r.Frame(ops)
@@ -118,19 +118,19 @@ func TestKeyRemoveFocus(t *testing.T) {
ops.Reset()
// Will get the focus removed:
s = op.Push(ops)
s = op.Save(ops)
key.InputOp{Tag: &handlers[0]}.Add(ops)
s.Pop()
s.Load()
// Unchanged:
s = op.Push(ops)
s = op.Save(ops)
key.InputOp{Tag: &handlers[1]}.Add(ops)
s.Pop()
s.Load()
// Removing any Focus:
s = op.Push(ops)
s = op.Save(ops)
key.FocusOp{Focus: false}.Add(ops)
s.Pop()
s.Load()
r.Frame(ops)
@@ -141,18 +141,18 @@ func TestKeyRemoveFocus(t *testing.T) {
ops.Reset()
s = op.Push(ops)
s = op.Save(ops)
key.InputOp{Tag: &handlers[0]}.Add(ops)
s.Pop()
s.Load()
// Setting Focus without InputOp:
s = op.Push(ops)
s = op.Save(ops)
key.FocusOp{Focus: true}.Add(ops)
s.Pop()
s.Load()
s = op.Push(ops)
s = op.Save(ops)
key.InputOp{Tag: &handlers[1]}.Add(ops)
s.Pop()
s.Load()
r.Frame(ops)
@@ -165,18 +165,18 @@ func TestKeyRemoveFocus(t *testing.T) {
// Set focus to InputOp which already
// exists in the previous frame:
s = op.Push(ops)
s = op.Save(ops)
key.FocusOp{Focus: true}.Add(ops)
key.InputOp{Tag: &handlers[0]}.Add(ops)
key.SoftKeyboardOp{Show: true}.Add(ops)
s.Pop()
s.Load()
// Tries to remove focus:
// It must not overwrite the previous `FocusOp`.
s = op.Push(ops)
s = op.Save(ops)
key.InputOp{Tag: &handlers[1]}.Add(ops)
key.FocusOp{Focus: false}.Add(ops)
s.Pop()
s.Load()
r.Frame(ops)
@@ -192,16 +192,16 @@ func TestKeyFocusedInvisible(t *testing.T) {
r := new(Router)
// Set new InputOp with focus:
s := op.Push(ops)
s := op.Save(ops)
key.FocusOp{Focus: true}.Add(ops)
key.InputOp{Tag: &handlers[0]}.Add(ops)
key.SoftKeyboardOp{Show: true}.Add(ops)
s.Pop()
s.Load()
// Set new InputOp without focus:
s = op.Push(ops)
s = op.Save(ops)
key.InputOp{Tag: &handlers[1]}.Add(ops)
s.Pop()
s.Load()
r.Frame(ops)
@@ -217,9 +217,9 @@ func TestKeyFocusedInvisible(t *testing.T) {
//
// Unchanged:
s = op.Push(ops)
s = op.Save(ops)
key.InputOp{Tag: &handlers[1]}.Add(ops)
s.Pop()
s.Load()
r.Frame(ops)
@@ -232,14 +232,14 @@ func TestKeyFocusedInvisible(t *testing.T) {
// Respawn the first element:
// It must receive one `Event{Focus: false}`.
s = op.Push(ops)
s = op.Save(ops)
key.InputOp{Tag: &handlers[0]}.Add(ops)
s.Pop()
s.Load()
// Unchanged
s = op.Push(ops)
s = op.Save(ops)
key.InputOp{Tag: &handlers[1]}.Add(ops)
s.Pop()
s.Load()
r.Frame(ops)
+3 -3
View File
@@ -243,12 +243,12 @@ func TestMultipleAreas(t *testing.T) {
var ops op.Ops
addPointerHandler(&ops, handler, image.Rect(0, 0, 100, 100))
st := op.Push(&ops)
st := op.Save(&ops)
pointer.Rect(image.Rect(50, 50, 200, 200)).Add(&ops)
// Second area has no Types set, yet should receive events because
// Types for the same handles are or-ed together.
pointer.InputOp{Tag: handler}.Add(&ops)
st.Pop()
st.Load()
var r Router
r.Frame(&ops)
@@ -468,7 +468,7 @@ func TestCursorNameOp(t *testing.T) {
// addPointerHandler adds a pointer.InputOp for the tag in a
// rectangular area.
func addPointerHandler(ops *op.Ops, tag event.Tag, area image.Rectangle) {
defer op.Push(ops).Pop()
defer op.Save(ops).Load()
pointer.Rect(area).Add(ops)
pointer.InputOp{
Tag: tag,