op

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2024 License: MIT, Unlicense Imports: 6 Imported by: 652

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 "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 state such as transformation and color and execution flow can be controlled with macros.

Some state, such as the current color, is modified directly by operations with Add methods. Other state, such as transformation and clip shape, are represented by stacks.

This example sets the simple color state and pushes an offset to the transformation stack.

ops := new(op.Ops)
// Set the color.
paint.ColorOp{...}.Add(ops)
// Apply an offset to subsequent operations.
stack := op.Offset(...).Push(ops)
...
// Undo the offset transformation.
stack.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.
...
// 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

func Defer(o *Ops, c CallOp)

Defer executes c after all other operations have completed, including previously deferred operations. Defer saves the transformation stack and pushes it prior to executing c. 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.

func (CallOp) Add

func (c CallOp) Add(o *Ops)

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

type InvalidateCmd added in v0.5.0

type InvalidateCmd struct {
	At time.Time
}

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

func (InvalidateCmd) ImplementsCommand added in v0.5.0

func (InvalidateCmd) ImplementsCommand()

type MacroOp

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

MacroOp records a list of operations for later use.

func Record

func Record(o *Ops) MacroOp

Record a macro of operations.

func (MacroOp) Stop

func (m MacroOp) Stop() CallOp

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

type Ops

type Ops struct {
	// Internal is for internal use, despite being exported.
	Internal ops.Ops
}

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 TransformOp

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

TransformOp represents a transformation that can be pushed on the transformation stack.

func Affine

func Affine(a f32.Affine2D) TransformOp

Affine creates a TransformOp representing the transformation a.

func Offset

func Offset(off image.Point) TransformOp

Offset converts an offset to a TransformOp.

func (TransformOp) Add

func (t TransformOp) Add(o *Ops)

Add is like Push except it doesn't push the current transformation to the stack.

func (TransformOp) Push

func (t TransformOp) Push(o *Ops) TransformStack

Push the current transformation to the stack and then multiply the current transformation with t.

type TransformStack

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

TransformStack represents a TransformOp pushed on the transformation stack.

func (TransformStack) Pop

func (t TransformStack) Pop()

Directories

Path Synopsis
Package clip provides operations for defining areas that applies to operations such as paints and pointer handlers.
Package clip provides operations for defining areas that applies to operations such as paints and pointer handlers.
Package paint provides drawing operations for 2D graphics.
Package paint provides drawing operations for 2D graphics.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL