ui: rename block to macro

It is a more precise name.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-07-15 20:31:11 +02:00
parent f36070f716
commit 3b5fcfe2bb
10 changed files with 77 additions and 76 deletions
+7 -7
View File
@@ -6,8 +6,8 @@ type OpType byte
const firstOpIndex = 200
const (
TypeBlockDef OpType = iota + firstOpIndex
TypeBlock
TypeMacroDef OpType = iota + firstOpIndex
TypeMacro
TypeTransform
TypeLayer
TypeInvalidate
@@ -27,8 +27,8 @@ const (
)
const (
TypeBlockDefLen = 1 + 4 + 4
TypeBlockLen = 1 + 4 + 4 + 4
TypeMacroDefLen = 1 + 4 + 4
TypeMacroLen = 1 + 4 + 4 + 4
TypeTransformLen = 1 + 4*2
TypeLayerLen = 1
TypeRedrawLen = 1 + 8
@@ -49,8 +49,8 @@ const (
func (t OpType) Size() int {
return [...]int{
TypeBlockDefLen,
TypeBlockLen,
TypeMacroDefLen,
TypeMacroLen,
TypeTransformLen,
TypeLayerLen,
TypeRedrawLen,
@@ -72,7 +72,7 @@ func (t OpType) Size() int {
func (t OpType) NumRefs() int {
switch t {
case TypeBlock, TypeImage, TypeKeyHandler, TypePointerHandler, TypeProfile:
case TypeMacro, TypeImage, TypeKeyHandler, TypePointerHandler, TypeProfile:
return 1
default:
return 0
+5 -5
View File
@@ -24,7 +24,7 @@ type Flex struct {
}
type FlexChild struct {
block ui.BlockOp
macro ui.MacroOp
dims Dimens
}
@@ -74,7 +74,7 @@ func (f *Flex) begin(mode flexMode) {
panic("must End before adding a child")
}
f.mode = mode
f.ops.Begin()
f.ops.Record()
}
func (f *Flex) Rigid() Constraints {
@@ -107,7 +107,7 @@ func (f *Flex) End(dims Dimens) FlexChild {
if f.mode <= modeBegun {
panic("End called without an active child")
}
block := f.ops.End()
macro := f.ops.Stop()
sz := axisMain(f.Axis, dims.Size)
f.size += sz
if f.mode == modeRigid {
@@ -120,7 +120,7 @@ func (f *Flex) End(dims Dimens) FlexChild {
if b := dims.Baseline; b > f.maxBaseline {
f.maxBaseline = b
}
return FlexChild{block, dims}
return FlexChild{macro, dims}
}
func (f *Flex) Layout(children ...FlexChild) Dimens {
@@ -160,7 +160,7 @@ func (f *Flex) Layout(children ...FlexChild) Dimens {
ui.TransformOp{
Transform: ui.Offset(toPointF(axisPoint(f.Axis, mainSize, cross))),
}.Add(f.ops)
child.block.Add(f.ops)
child.macro.Add(f.ops)
ui.PopOp{}.Add(f.ops)
mainSize += axisMain(f.Axis, dims.Size)
if i < len(children)-1 {
+3 -3
View File
@@ -129,7 +129,7 @@ func (a *Align) Begin(ops *ui.Ops, cs Constraints) Constraints {
a.begun = true
a.ops = ops
a.cs = cs
ops.Begin()
ops.Record()
cs.Width.Min = 0
cs.Height.Min = 0
return cs
@@ -141,7 +141,7 @@ func (a *Align) End(dims Dimens) Dimens {
}
a.begun = false
ops := a.ops
block := ops.End()
macro := ops.Stop()
sz := dims.Size
if sz.X < a.cs.Width.Min {
sz.X = a.cs.Width.Min
@@ -164,7 +164,7 @@ func (a *Align) End(dims Dimens) Dimens {
}
ui.PushOp{}.Add(ops)
ui.TransformOp{Transform: ui.Offset(toPointF(p))}.Add(ops)
block.Add(ops)
macro.Add(ops)
ui.PopOp{}.Add(ops)
return Dimens{
Size: sz,
+8 -8
View File
@@ -14,7 +14,7 @@ import (
type scrollChild struct {
size image.Point
block ui.BlockOp
macro ui.MacroOp
}
type List struct {
@@ -70,7 +70,7 @@ func (l *List) Init(ops *ui.Ops, cs Constraints, len int) {
if l.first > len {
l.first = len
}
ops.Begin()
ops.Record()
l.Next()
}
@@ -103,7 +103,7 @@ func (l *List) Next() {
i = l.len - 1 - i
}
l.index = i
l.ops.Begin()
l.ops.Record()
}
// Index is the current element index.
@@ -146,8 +146,8 @@ func (l *List) next() (int, bool) {
// Elem completes an element.
func (l *List) Elem(dims Dimens) {
block := l.ops.End()
child := scrollChild{dims.Size, block}
macro := l.ops.Stop()
child := scrollChild{dims.Size, macro}
switch l.dir {
case iterateForward:
mainSize := axisMain(l.Axis, child.size)
@@ -227,7 +227,7 @@ func (l *List) Layout() Dimens {
ui.TransformOp{
Transform: ui.Offset(toPointF(axisPoint(l.Axis, transPos, cross))),
}.Add(ops)
child.block.Add(ops)
child.macro.Add(ops)
ui.PopOp{}.Add(ops)
pos += childSize
}
@@ -237,9 +237,9 @@ func (l *List) Layout() Dimens {
l.scroll.Stop()
}
dims := axisPoint(l.Axis, mainc.Constrain(pos), maxCross)
block := ops.End()
macro := ops.Stop()
pointer.RectAreaOp{Size: dims}.Add(ops)
l.scroll.Add(ops)
block.Add(ops)
macro.Add(ops)
return Dimens{Size: dims}
}
+4 -4
View File
@@ -20,7 +20,7 @@ type Stack struct {
}
type StackChild struct {
block ui.BlockOp
macro ui.MacroOp
dims Dimens
}
@@ -54,7 +54,7 @@ func (s *Stack) begin() {
panic("must End before adding a child")
}
s.begun = true
s.ops.Begin()
s.ops.Record()
}
func (s *Stack) Rigid() Constraints {
@@ -71,7 +71,7 @@ func (s *Stack) Expand() Constraints {
}
func (s *Stack) End(dims Dimens) StackChild {
b := s.ops.End()
b := s.ops.Stop()
s.begun = false
if w := dims.Size.X; w > s.maxSZ.X {
s.maxSZ.X = w
@@ -105,7 +105,7 @@ func (s *Stack) Layout(children ...StackChild) Dimens {
}
ui.PushOp{}.Add(s.ops)
ui.TransformOp{Transform: ui.Offset(toPointF(p))}.Add(s.ops)
ch.block.Add(s.ops)
ch.macro.Add(s.ops)
ui.PopOp{}.Add(s.ops)
}
b := s.baseline
+5 -5
View File
@@ -30,7 +30,7 @@ type cachedLayout struct {
type cachedPath struct {
active bool
path ui.BlockOp
path ui.MacroOp
}
type layoutKey struct {
@@ -119,7 +119,7 @@ func (f *textFace) Layout(str string, opts text.LayoutOptions) *text.Layout {
return l
}
func (f *textFace) Path(str text.String) ui.BlockOp {
func (f *textFace) Path(str text.String) ui.MacroOp {
ppem := fixed.Int26_6(f.faces.Config.Px(f.size) * 64)
pk := pathKey{
f: f.font.Font,
@@ -227,14 +227,14 @@ func layoutText(ppem fixed.Int26_6, str string, f *opentype, opts text.LayoutOpt
return &text.Layout{Lines: lines}
}
func textPath(ppem fixed.Int26_6, f *opentype, str text.String) ui.BlockOp {
func textPath(ppem fixed.Int26_6, f *opentype, str text.String) ui.MacroOp {
var lastPos f32.Point
var builder draw.PathBuilder
ops := new(ui.Ops)
builder.Init(ops)
var x fixed.Int26_6
var advIdx int
ops.Begin()
ops.Record()
for _, r := range str.String {
if !unicode.IsSpace(r) {
segs, ok := f.LoadGlyph(ppem, r)
@@ -287,5 +287,5 @@ func textPath(ppem fixed.Int26_6, f *opentype, str text.String) ui.BlockOp {
advIdx++
}
builder.End()
return ops.End()
return ops.Stop()
}
+41 -40
View File
@@ -10,7 +10,7 @@ import (
// Ops holds a list of serialized Ops.
type Ops struct {
// Stack of block start indices.
// Stack of macro start indices.
stack []pc
ops opsData
@@ -30,7 +30,7 @@ type opsData struct {
// OpsReader parses an ops list. Internal use only.
type OpsReader struct {
pc pc
stack []block
stack []macro
ops *opsData
}
@@ -49,7 +49,7 @@ type OpKey struct {
version int
}
type block struct {
type macro struct {
ops *opsData
retPC pc
endPC pc
@@ -64,13 +64,13 @@ type PushOp struct{}
type PopOp struct{}
type BlockOp struct {
type MacroOp struct {
ops *opsData
version int
pc pc
}
type opBlockDef struct {
type opMacroDef struct {
endpc pc
}
@@ -86,11 +86,12 @@ func (p PopOp) Add(o *Ops) {
o.Write([]byte{byte(ops.TypePop)})
}
// Begin a block of ops.
func (o *Ops) Begin() {
// Record starts recording a macro. Multiple simultaneous
// recordings are supported. Stop ends the most recent.
func (o *Ops) Record() {
o.stack = append(o.stack, o.ops.pc())
// Make room for a block definition. Filled out in End.
o.Write(make([]byte, ops.TypeBlockDefLen))
// Make room for a macro definition. Filled out in Stop.
o.Write(make([]byte, ops.TypeMacroDefLen))
}
func (op *opAux) decode(data []byte) {
@@ -103,14 +104,14 @@ func (op *opAux) decode(data []byte) {
}
}
func (op *opBlockDef) decode(data []byte) {
if ops.OpType(data[0]) != ops.TypeBlockDef {
func (op *opMacroDef) decode(data []byte) {
if ops.OpType(data[0]) != ops.TypeMacroDef {
panic("invalid op")
}
bo := binary.LittleEndian
dataIdx := int(bo.Uint32(data[1:]))
refsIdx := int(bo.Uint32(data[5:]))
*op = opBlockDef{
*op = opMacroDef{
endpc: pc{
data: dataIdx,
refs: refsIdx,
@@ -118,22 +119,22 @@ func (op *opBlockDef) decode(data []byte) {
}
}
// End the most recent block and return
// an op for invoking the completed block.
func (o *Ops) End() BlockOp {
// Stop the most recent recording and return the macro for later
// use.
func (o *Ops) Stop() MacroOp {
if len(o.stack) == 0 {
panic(errors.New("End with no matching Begin"))
panic(errors.New("not recording a macro"))
}
start := o.stack[len(o.stack)-1]
o.stack = o.stack[:len(o.stack)-1]
pc := o.ops.pc()
// Write the block header reserved in Begin.
data := o.ops.data[start.data : start.data+ops.TypeBlockDefLen]
data[0] = byte(ops.TypeBlockDef)
// Write the macro header reserved in Begin.
data := o.ops.data[start.data : start.data+ops.TypeMacroDefLen]
data[0] = byte(ops.TypeMacroDef)
bo := binary.LittleEndian
bo.PutUint32(data[1:], uint32(pc.data))
bo.PutUint32(data[5:], uint32(pc.refs))
return BlockOp{ops: &o.ops, pc: start, version: o.ops.version}
return MacroOp{ops: &o.ops, pc: start, version: o.ops.version}
}
// Reset the Ops, preparing it for re-use.
@@ -198,15 +199,15 @@ func (d *opsData) pc() pc {
return pc{data: len(d.data), refs: len(d.refs)}
}
func (b *BlockOp) decode(data []byte, refs []interface{}) {
if ops.OpType(data[0]) != ops.TypeBlock {
func (b *MacroOp) decode(data []byte, refs []interface{}) {
if ops.OpType(data[0]) != ops.TypeMacro {
panic("invalid op")
}
bo := binary.LittleEndian
dataIdx := int(bo.Uint32(data[1:]))
refsIdx := int(bo.Uint32(data[5:]))
version := int(bo.Uint32(data[9:]))
*b = BlockOp{
*b = MacroOp{
ops: refs[0].(*opsData),
pc: pc{
data: dataIdx,
@@ -216,12 +217,12 @@ func (b *BlockOp) decode(data []byte, refs []interface{}) {
}
}
func (b BlockOp) Add(o *Ops) {
func (b MacroOp) Add(o *Ops) {
if b.ops == nil {
return
}
data := make([]byte, ops.TypeBlockLen)
data[0] = byte(ops.TypeBlock)
data := make([]byte, ops.TypeMacroLen)
data[0] = byte(ops.TypeMacro)
bo := binary.LittleEndian
bo.PutUint32(data[1:], uint32(b.pc.data))
bo.PutUint32(data[5:], uint32(b.pc.refs))
@@ -272,33 +273,33 @@ func (r *OpsReader) Decode() (EncodedOp, bool) {
op.decode(data)
n += op.len
data = r.ops.data[r.pc.data : r.pc.data+n]
case ops.TypeBlock:
var op BlockOp
case ops.TypeMacro:
var op MacroOp
op.decode(data, refs)
blockOps := op.ops
if ops.OpType(blockOps.data[op.pc.data]) != ops.TypeBlockDef {
panic("invalid block reference")
macroOps := op.ops
if ops.OpType(macroOps.data[op.pc.data]) != ops.TypeMacroDef {
panic("invalid macro reference")
}
if op.version != op.ops.version {
panic("invalid BlockOp reference to reset Ops")
panic("invalid MacroOp reference to reset Ops")
}
var opDef opBlockDef
opDef.decode(blockOps.data[op.pc.data : op.pc.data+ops.TypeBlockDef.Size()])
var opDef opMacroDef
opDef.decode(macroOps.data[op.pc.data : op.pc.data+ops.TypeMacroDef.Size()])
retPC := r.pc
retPC.data += n
retPC.refs += nrefs
r.stack = append(r.stack, block{
r.stack = append(r.stack, macro{
ops: r.ops,
retPC: retPC,
endPC: opDef.endpc,
})
r.ops = blockOps
r.ops = macroOps
r.pc = op.pc
r.pc.data += ops.TypeBlockDef.Size()
r.pc.refs += ops.TypeBlockDef.NumRefs()
r.pc.data += ops.TypeMacroDef.Size()
r.pc.refs += ops.TypeMacroDef.NumRefs()
continue
case ops.TypeBlockDef:
var op opBlockDef
case ops.TypeMacroDef:
var op opMacroDef
op.decode(data)
r.pc = op.endpc
continue
+2 -2
View File
@@ -28,9 +28,9 @@ type Editor struct {
SingleLine bool
Submit bool
Material ui.BlockOp
Material ui.MacroOp
Hint string
HintMaterial ui.BlockOp
HintMaterial ui.MacroOp
oldScale int
blinkStart time.Time
+1 -1
View File
@@ -18,7 +18,7 @@ import (
type Label struct {
Face Face
Material ui.BlockOp
Material ui.MacroOp
Alignment Alignment
Text string
MaxLines int
+1 -1
View File
@@ -40,7 +40,7 @@ type LayoutOptions struct {
type Face interface {
Layout(str string, opts LayoutOptions) *Layout
Path(str String) ui.BlockOp
Path(str String) ui.MacroOp
}
type Alignment uint8