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 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 ¶
- func Defer(o *Ops, c CallOp)
- type CallOp
- type InvalidateCmd
- type MacroOp
- type Ops
- type TransformOp
- func Affine(a f32.Affine2D) TransformOp
- func Offset(off image.Point) TransformOp
- func (t TransformOp) Add(o *Ops)
- func (t TransformOp) Push(o *Ops) TransformStack
- type TransformStack
Functions ¶
func Defer ¶
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 ¶
Add the recorded list of operations. Add panics if the Ops containing the recording has been reset.
type InvalidateCmd ¶
InvalidateCmd requests a redraw at the given time. Use the zero value to request an immediate redraw.
func (InvalidateCmd) ImplementsCommand ¶
func (InvalidateCmd) ImplementsCommand()
type MacroOp ¶
type MacroOp struct {
// contains filtered or unexported fields
}
MacroOp records a list of operations for later use.
func Record ¶
Record a macro of operations.
func (MacroOp) Stop ¶
Stop ends a previously started recording and returns an operation for replaying it.
type 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()
Source Files ¶
op.go
Directories ¶
Path | Synopsis |
---|---|
op/clip | Package clip provides operations for defining areas that applies to operations such as paints and pointer handlers. |
op/paint | Package paint provides drawing operations for 2D graphics. |
- Version
- v0.8.0 (latest)
- Published
- Jan 14, 2025
- Platform
- linux/amd64
- Imports
- 6 packages
- Last checked
- 6 hours ago –
Tools for package owners.