~eliasnaur/gio

3c924e2a180fb75c13e9ee1f9f219db61fdee648 — Elias Naur 1 year, 3 months ago aa703df
ui: document types and methods

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2 files changed, 16 insertions(+), 4 deletions(-)

M ui/ops.go
M ui/unit.go
M ui/ops.go => ui/ops.go +12 -4
@@ 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")

M ui/unit.go => ui/unit.go +4 -0
@@ 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}
}