Documentation ¶
Overview ¶
Package op implements operations for updating a user interface.
Gio programs use operations, or ops, for describing their user interfaces. There are operations for drawing, defining input handlers, changing window properties as well as operations for controlling the execution of other operations.
Ops represents a list of operations. The most important use for an Ops list is to describe a complete user interface update to a ui/app.Window's Update method.
Drawing a colored square:
import "github.com/cybriq/gio/unit" import "github.com/cybriq/gio/app" import "github.com/cybriq/gio/op/paint" var w app.Window var e system.FrameEvent ops := new(op.Ops) ... ops.Reset() paint.ColorOp{Color: ...}.Add(ops) paint.PaintOp{Rect: ...}.Add(ops) e.Frame(ops)
State ¶
An Ops list can be viewed as a very simple virtual machine: it has an implicit mutable state stack and execution flow can be controlled with macros.
The Save function saves the current state for later restoring:
ops := new(op.Ops) // Save the current state, in particular the transform. state := op.Save(ops) // Apply a transform to subsequent operations. op.Offset(...).Add(ops) ... // Restore the previous transform. state.Load()
You can also use this one-line to save the current state and restore it at the end of a function :
defer op.Save(ops).Load()
The MacroOp records a list of operations to be executed later:
ops := new(op.Ops) macro := op.Record(ops) // Record operations by adding them. op.InvalidateOp{}.Add(ops) ... // End recording. call := macro.Stop() // replay the recorded operations: call.Add(ops)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Defer ¶
Defer executes c after all other operations have completed, including previously deferred operations. Defer saves the current transformation and restores it prior to execution. All other operation state is reset.
Note that deferred operations are executed in first-in-first-out order, unlike the Go facility of the same name.
Types ¶
type CallOp ¶
type CallOp struct {
// contains filtered or unexported fields
}
CallOp invokes the operations recorded by Record.
type InvalidateOp ¶
InvalidateOp requests a redraw at the given time. Use the zero value to request an immediate redraw.
func (InvalidateOp) Add ¶
func (r InvalidateOp) Add(o *Ops)
type MacroOp ¶
type MacroOp struct {
// contains filtered or unexported fields
}
MacroOp records a list of operations for later use.
type Ops ¶
type Ops struct {
// contains filtered or unexported fields
}
Ops holds a list of operations. Operations are stored in serialized form to avoid garbage during construction of the ops list.
func (*Ops) Reset ¶
func (o *Ops) Reset()
Reset the Ops, preparing it for re-use. Reset invalidates any recorded macros.
type StateOp ¶
type StateOp struct {
// contains filtered or unexported fields
}
StateOp represents a saved operation snapshop to be restored later.
type TransformOp ¶
type TransformOp struct {
// contains filtered or unexported fields
}
TransformOp applies a transform to the current transform. The zero value for TransformOp represents the identity transform.
func Affine ¶
func Affine(a f32.Affine2D) TransformOp
Affine creates a TransformOp representing the transformation a.
func (TransformOp) Add ¶
func (t TransformOp) Add(o *Ops)