mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
op: add package op for operations
Extract operation types from package ui into package op. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -4,64 +4,6 @@
|
||||
Package ui defines operations buffers, units and common operations
|
||||
for GUI programs written with the Gio module.
|
||||
|
||||
Operations
|
||||
|
||||
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/ui"
|
||||
import "gioui.org/app"
|
||||
import "gioui.org/paint"
|
||||
|
||||
var w app.Window
|
||||
ops := new(ui.Ops)
|
||||
...
|
||||
ops.Reset()
|
||||
paint.ColorOp{Color: ...}.Add(ops)
|
||||
paint.PaintOp{Rect: ...}.Add(ops)
|
||||
w.Update(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(ui.Ops)
|
||||
var stack ui.StackOp
|
||||
// Save the current state, in particular the transform.
|
||||
stack.Push(ops)
|
||||
// Apply a transform to subsequent operations.
|
||||
ui.TransformOp{}.Offset(...).Add(ops)
|
||||
...
|
||||
// Restore the previous transform.
|
||||
stack.Pop()
|
||||
|
||||
The MacroOp records a list of operations to be executed later:
|
||||
|
||||
ops := new(ui.Ops)
|
||||
var macro ui.MacroOp
|
||||
macro.Record()
|
||||
// Record operations by adding them.
|
||||
ui.InvalidateOp{}.Add(ops)
|
||||
...
|
||||
macro.Stop()
|
||||
...
|
||||
// Execute the recorded operations.
|
||||
macro.Add(ops)
|
||||
|
||||
Note that operations added between Record and Stop are not executed until
|
||||
the macro is Added.
|
||||
|
||||
Units
|
||||
|
||||
A Value is a value with a Unit attached.
|
||||
|
||||
Reference in New Issue
Block a user