Index | Files | Directories

package op

import ""

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 ""
import ""
import ""

var w app.Window
var e system.FrameEvent
ops := new(op.Ops)
paint.ColorOp{Color: ...}.Add(ops)
paint.PaintOp{Rect: ...}.Add(ops)


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 StackOp saves the current state to the state stack and restores it later:

ops := new(op.Ops)
var stack op.StackOp
// Save the current state, in particular the transform.
// Apply a transform to subsequent operations.
// Restore the previous transform.

The CallOp invokes another operation list:

ops := new(op.Ops)
ops2 := new(op.Ops)
op.CallOp{Ops: ops2}.Add(ops)

The MacroOp records a list of operations to be executed later:

ops := new(op.Ops)
var macro op.MacroOp
// Record operations by adding them.
// End recording.

// replay the recorded operations by calling Add:


Package Files


type CallOp Uses

type CallOp struct {
    // Ops is the list of operations to invoke.
    Ops *Ops

CallOp invokes all the operations from a separate operations list.

func (CallOp) Add Uses

func (c CallOp) Add(o *Ops)

Add the call to the operation list.

type InvalidateOp Uses

type InvalidateOp struct {
    At time.Time

InvalidateOp requests a redraw at the given time. Use the zero value to request an immediate redraw.

func (InvalidateOp) Add Uses

func (r InvalidateOp) Add(o *Ops)

type MacroOp Uses

type MacroOp struct {
    // contains filtered or unexported fields

MacroOp records a list of operations for later use.

func (*MacroOp) Add Uses

func (m *MacroOp) Add()

Add the recorded list of operations.

func (*MacroOp) Record Uses

func (m *MacroOp) Record(o *Ops)

Record a macro of operations.

func (*MacroOp) Stop Uses

func (m *MacroOp) Stop()

Stop ends a previously started recording.

type Ops Uses

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) Data Uses

func (o *Ops) Data() []byte

Data is for internal use only.

func (*Ops) Refs Uses

func (o *Ops) Refs() []interface{}

Refs is for internal use only.

func (*Ops) Reset Uses

func (o *Ops) Reset()

Reset the Ops, preparing it for re-use.

func (*Ops) Version Uses

func (o *Ops) Version() int

Version is for internal use only.

func (*Ops) Write Uses

func (o *Ops) Write(n int, refs ...interface{}) []byte

Write is for internal use only.

type StackOp Uses

type StackOp struct {
    // contains filtered or unexported fields

StackOp saves and restores the operation state in a stack-like manner.

func (*StackOp) Pop Uses

func (s *StackOp) Pop()

Pop (restore) a previously Pushed operations state.

func (*StackOp) Push Uses

func (s *StackOp) Push(o *Ops)

Push (save) the current operations state.

type TransformOp Uses

type TransformOp struct {
    // contains filtered or unexported fields

TransformOp applies a transform to the current transform.

func (TransformOp) Add Uses

func (t TransformOp) Add(o *Ops)

func (TransformOp) Invert Uses

func (t TransformOp) Invert() TransformOp

Invert the transformation.

func (TransformOp) Multiply Uses

func (t TransformOp) Multiply(t2 TransformOp) TransformOp

Multiply by a transformation.

func (TransformOp) Offset Uses

func (t TransformOp) Offset(o f32.Point) TransformOp

Offset the transformation.

func (TransformOp) Transform Uses

func (t TransformOp) Transform(p f32.Point) f32.Point

Transform a point.


clipPackage clip provides operations for clipping paint operations.
paintPackage paint provides drawing operations for 2D graphics.

Package op imports 5 packages (graph) and is imported by 55 packages. Updated 2020-05-28. Refresh now. Tools for package owners.