ui: document types and methods

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-08-08 14:54:51 +02:00
parent aa703dfc3e
commit 3c924e2a18
2 changed files with 16 additions and 4 deletions
+12 -4
View File
@@ -8,12 +8,13 @@ import (
"gioui.org/ui/internal/opconst" "gioui.org/ui/internal/opconst"
) )
// Ops holds a list of serialized Ops. // Ops holds a list of serialized operations.
type Ops struct { type Ops struct {
// Version is incremented at each Reset.
Version int Version int
// Serialized ops. // Serialized operations.
Data []byte Data []byte
// Op references. // External references for operations.
Refs []interface{} Refs []interface{}
stackDepth int stackDepth int
@@ -23,12 +24,16 @@ type Ops struct {
auxLen int auxLen int
} }
// StackOp can save and restore the operation state
// in a stack-like manner.
type StackOp struct { type StackOp struct {
depth int depth int
active bool active bool
ops *Ops ops *Ops
} }
// MacroOp can record a list of operations for later
// use.
type MacroOp struct { type MacroOp struct {
recording bool recording bool
ops *Ops ops *Ops
@@ -41,6 +46,7 @@ type pc struct {
refs int refs int
} }
// Push (save) the current operations state.
func (s *StackOp) Push(o *Ops) { func (s *StackOp) Push(o *Ops) {
if s.active { if s.active {
panic("unbalanced push") panic("unbalanced push")
@@ -52,6 +58,7 @@ func (s *StackOp) Push(o *Ops) {
o.Write([]byte{byte(opconst.TypePush)}) o.Write([]byte{byte(opconst.TypePush)})
} }
// Pop (restore) a previously Pushed operations state.
func (s *StackOp) Pop() { func (s *StackOp) Pop() {
if !s.active { if !s.active {
panic("unbalanced pop") panic("unbalanced pop")
@@ -91,6 +98,7 @@ func (d *Ops) write(op []byte, refs ...interface{}) {
d.Refs = append(d.Refs, refs...) d.Refs = append(d.Refs, refs...)
} }
// Internal use only.
func (o *Ops) Write(op []byte, refs ...interface{}) { func (o *Ops) Write(op []byte, refs ...interface{}) {
t := opconst.OpType(op[0]) t := opconst.OpType(op[0])
if len(refs) != t.NumRefs() { if len(refs) != t.NumRefs() {
@@ -135,7 +143,7 @@ func (m *MacroOp) Record(o *Ops) {
m.ops.Write(make([]byte, opconst.TypeMacroDefLen)) m.ops.Write(make([]byte, opconst.TypeMacroDefLen))
} }
// Stop recording the macro. // Stop ends a previously started recording.
func (m *MacroOp) Stop() { func (m *MacroOp) Stop() {
if !m.recording { if !m.recording {
panic("not recording") panic("not recording")
+4
View File
@@ -25,14 +25,18 @@ const (
UnitSp UnitSp
) )
// Px returns the Value for v device pixels.
func Px(v float32) Value { func Px(v float32) Value {
return Value{V: v, U: UnitPx} return Value{V: v, U: UnitPx}
} }
// Px returns the Value for v device independent
// pixels.
func Dp(v float32) Value { func Dp(v float32) Value {
return Value{V: v, U: UnitDp} return Value{V: v, U: UnitDp}
} }
// Sp returns the Value for v scaled dps.
func Sp(v float32) Value { func Sp(v float32) Value {
return Value{V: v, U: UnitSp} return Value{V: v, U: UnitSp}
} }