diff --git a/ui/ops.go b/ui/ops.go index 00b436ba..9314fa9f 100644 --- a/ui/ops.go +++ b/ui/ops.go @@ -8,12 +8,13 @@ import ( "gioui.org/ui/internal/opconst" ) -// Ops holds a list of serialized Ops. +// Ops holds a list of serialized operations. type Ops struct { + // Version is incremented at each Reset. Version int - // Serialized ops. + // Serialized operations. Data []byte - // Op references. + // External references for operations. Refs []interface{} stackDepth int @@ -23,12 +24,16 @@ type Ops struct { auxLen int } +// StackOp can save and restore the operation state +// in a stack-like manner. type StackOp struct { depth int active bool ops *Ops } +// MacroOp can record a list of operations for later +// use. type MacroOp struct { recording bool ops *Ops @@ -41,6 +46,7 @@ type pc struct { refs int } +// Push (save) the current operations state. func (s *StackOp) Push(o *Ops) { if s.active { panic("unbalanced push") @@ -52,6 +58,7 @@ func (s *StackOp) Push(o *Ops) { o.Write([]byte{byte(opconst.TypePush)}) } +// Pop (restore) a previously Pushed operations state. func (s *StackOp) Pop() { if !s.active { panic("unbalanced pop") @@ -91,6 +98,7 @@ func (d *Ops) write(op []byte, refs ...interface{}) { d.Refs = append(d.Refs, refs...) } +// Internal use only. func (o *Ops) Write(op []byte, refs ...interface{}) { t := opconst.OpType(op[0]) if len(refs) != t.NumRefs() { @@ -135,7 +143,7 @@ func (m *MacroOp) Record(o *Ops) { m.ops.Write(make([]byte, opconst.TypeMacroDefLen)) } -// Stop recording the macro. +// Stop ends a previously started recording. func (m *MacroOp) Stop() { if !m.recording { panic("not recording") diff --git a/ui/unit.go b/ui/unit.go index 7b58891a..665aa58d 100644 --- a/ui/unit.go +++ b/ui/unit.go @@ -25,14 +25,18 @@ const ( UnitSp ) +// Px returns the Value for v device pixels. func Px(v float32) Value { return Value{V: v, U: UnitPx} } +// Px returns the Value for v device independent +// pixels. func Dp(v float32) Value { return Value{V: v, U: UnitDp} } +// Sp returns the Value for v scaled dps. func Sp(v float32) Value { return Value{V: v, U: UnitSp} }