gioui.org: gioui.org/op Index | Files | Directories

package op

import "gioui.org/op"

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 "gioui.org/unit"
import "gioui.org/app"
import "gioui.org/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 StackOp saves the current state to the state stack and restores it later:

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

You can also use this one-line to save the current state and restore it at the end of a function :

defer op.Push(ops).Pop()

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

Package Files

op.go

type CallOp Uses

type CallOp struct {
    // contains filtered or unexported fields
}

CallOp invokes the operations recorded by Record.

func (CallOp) Add Uses

func (c CallOp) Add(o *Ops)

Add the recorded list of operations. Add panics if the Ops containing the recording has been reset.

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 Record Uses

func Record(o *Ops) MacroOp

Record a macro of operations.

func (MacroOp) Stop Uses

func (m MacroOp) Stop() CallOp

Stop ends a previously started recording and returns an operation for replaying it.

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. Reset invalidates any recorded macros.

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 Push Uses

func Push(o *Ops) StackOp

Push (save) the current operations state.

func (StackOp) Pop Uses

func (s StackOp) Pop()

Pop (restore) a previously Pushed operations state.

type TransformOp Uses

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 Uses

func Affine(a f32.Affine2D) TransformOp

Affine creates a TransformOp representing the transformation a.

func Offset Uses

func Offset(o f32.Point) TransformOp

Offset creates a TransformOp with the offset o.

func (TransformOp) Add Uses

func (t TransformOp) Add(o *Ops)

Directories

PathSynopsis
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 73 packages. Updated 2020-10-20. Refresh now. Tools for package owners.