~eliasnaur/gio

5e1f078b12aeaa9c5c0dc9c6736b57123add22bf — Elias Naur 1 year, 3 months ago d178167
ui: merge Transform into TransformOp

The separate Transform type is not worth its weight.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
M ui/app/internal/gpu/gpu.go => ui/app/internal/gpu/gpu.go +2 -2
@@ 73,7 73,7 @@ type drawOps struct {

type drawState struct {
	clip  f32.Rectangle
	t     ui.Transform
	t     ui.TransformOp
	cpath *pathOp
	rect  bool
	z     int


@@ 664,7 664,7 @@ loop:
		case ops.TypeTransform:
			var op ui.TransformOp
			op.Decode(encOp.Data)
			state.t = state.t.Mul(op.Transform)
			state.t = state.t.Mul(op)
		case ops.TypeAux:
			aux = encOp.Data[ops.TypeAuxLen:]
			auxKey = encOp.Key

M ui/app/internal/input/pointer.go => ui/app/internal/input/pointer.go +5 -5
@@ 41,7 41,7 @@ type pointerInfo struct {
type pointerHandler struct {
	area      int
	active    bool
	transform ui.Transform
	transform ui.TransformOp
	wantsGrab bool
}



@@ 51,7 51,7 @@ type areaOp struct {
}

type areaNode struct {
	trans ui.Transform
	trans ui.TransformOp
	next  int
	area  areaOp
}


@@ 63,7 63,7 @@ const (
	areaEllipse
)

func (q *pointerQueue) collectHandlers(r *ui.OpsReader, events *handlerEvents, t ui.Transform, area, node int, pass bool) {
func (q *pointerQueue) collectHandlers(r *ui.OpsReader, events *handlerEvents, t ui.TransformOp, area, node int, pass bool) {
	for encOp, ok := r.Decode(); ok; encOp, ok = r.Decode() {
		switch ops.OpType(encOp.Data[0]) {
		case ops.TypePush:


@@ 88,7 88,7 @@ func (q *pointerQueue) collectHandlers(r *ui.OpsReader, events *handlerEvents, t
		case ops.TypeTransform:
			var op ui.TransformOp
			op.Decode(encOp.Data)
			t = t.Mul(op.Transform)
			t = t.Mul(op)
		case ops.TypePointerHandler:
			var op pointer.HandlerOp
			op.Decode(encOp.Data, encOp.Refs)


@@ 169,7 169,7 @@ func (q *pointerQueue) Frame(root *ui.Ops, events *handlerEvents) {
	q.hitTree = q.hitTree[:0]
	q.areas = q.areas[:0]
	q.reader.Reset(root)
	q.collectHandlers(&q.reader, events, ui.Transform{}, -1, -1, false)
	q.collectHandlers(&q.reader, events, ui.TransformOp{}, -1, -1, false)
	for k, h := range q.handlers {
		if !h.active {
			q.dropHandler(k)

M ui/layout/flex.go => ui/layout/flex.go +1 -3
@@ 159,9 159,7 @@ func (f *Flex) Layout(children ...FlexChild) Dimens {
		}
		var stack ui.StackOp
		stack.Push(f.ops)
		ui.TransformOp{
			Transform: ui.Offset(toPointF(axisPoint(f.Axis, mainSize, cross))),
		}.Add(f.ops)
		ui.TransformOp{}.Offset(toPointF(axisPoint(f.Axis, mainSize, cross))).Add(f.ops)
		child.macro.Add(f.ops)
		stack.Pop()
		mainSize += axisMain(f.Axis, dims.Size)

M ui/layout/layout.go => ui/layout/layout.go +2 -2
@@ 96,7 96,7 @@ func (in *Inset) Begin(c ui.Config, ops *ui.Ops, cs Constraints) Constraints {
		}
	}
	in.stack.Push(ops)
	ui.TransformOp{Transform: ui.Offset(toPointF(image.Point{X: in.left, Y: in.top}))}.Add(ops)
	ui.TransformOp{}.Offset(toPointF(image.Point{X: in.left, Y: in.top})).Add(ops)
	return mcs
}



@@ 169,7 169,7 @@ func (a *Align) End(dims Dimens) Dimens {
	}
	var stack ui.StackOp
	stack.Push(ops)
	ui.TransformOp{Transform: ui.Offset(toPointF(p))}.Add(ops)
	ui.TransformOp{}.Offset(toPointF(p)).Add(ops)
	a.macro.Add(ops)
	stack.Pop()
	return Dimens{

M ui/layout/list.go => ui/layout/list.go +1 -3
@@ 229,9 229,7 @@ func (l *List) Layout() Dimens {
		var stack ui.StackOp
		stack.Push(ops)
		draw.RectClip(r).Add(ops)
		ui.TransformOp{
			Transform: ui.Offset(toPointF(axisPoint(l.Axis, transPos, cross))),
		}.Add(ops)
		ui.TransformOp{}.Offset(toPointF(axisPoint(l.Axis, transPos, cross))).Add(ops)
		child.macro.Add(ops)
		stack.Pop()
		pos += childSize

M ui/layout/stack.go => ui/layout/stack.go +1 -1
@@ 106,7 106,7 @@ func (s *Stack) Layout(children ...StackChild) Dimens {
		}
		var stack ui.StackOp
		stack.Push(s.ops)
		ui.TransformOp{Transform: ui.Offset(toPointF(p))}.Add(s.ops)
		ui.TransformOp{}.Offset(toPointF(p)).Add(s.ops)
		ch.macro.Add(s.ops)
		stack.Pop()
	}

M ui/text/editor.go => ui/text/editor.go +1 -1
@@ 209,7 209,7 @@ func (e *Editor) Layout(cfg ui.Config, queue input.Queue, ops *ui.Ops, cs layout
		}
		var stack ui.StackOp
		stack.Push(ops)
		ui.TransformOp{Transform: ui.Offset(lineOff)}.Add(ops)
		ui.TransformOp{}.Offset(lineOff).Add(ops)
		e.Face.Path(str).Add(ops)
		draw.DrawOp{Rect: toRectF(clip).Sub(lineOff)}.Add(ops)
		stack.Pop()

M ui/text/label.go => ui/text/label.go +1 -1
@@ 109,7 109,7 @@ func (l Label) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
		lclip := toRectF(clip).Sub(off)
		var stack ui.StackOp
		stack.Push(ops)
		ui.TransformOp{Transform: ui.Offset(off)}.Add(ops)
		ui.TransformOp{}.Offset(off).Add(ops)
		l.Face.Path(str).Add(ops)
		// Set a default color in case the material is empty.
		draw.ColorOp{Color: color.RGBA{A: 0xff}}.Add(ops)

M ui/ui.go => ui/ui.go +15 -21
@@ 28,11 28,7 @@ type InvalidateOp struct {

// TransformOp applies a transform to later ops.
type TransformOp struct {
	Transform Transform
}

type Transform struct {
	// TODO: general transforms.
	// TODO: general transformations.
	offset f32.Point
}



@@ 63,16 59,20 @@ func (r *InvalidateOp) Decode(d []byte) {
	}
}

func (t Transform) InvTransform(p f32.Point) f32.Point {
func (t TransformOp) Offset(o f32.Point) TransformOp {
	return TransformOp{o}
}

func (t TransformOp) InvTransform(p f32.Point) f32.Point {
	return p.Sub(t.offset)
}

func (t Transform) Transform(p f32.Point) f32.Point {
func (t TransformOp) Transform(p f32.Point) f32.Point {
	return p.Add(t.offset)
}

func (t Transform) Mul(t2 Transform) Transform {
	return Transform{
func (t TransformOp) Mul(t2 TransformOp) TransformOp {
	return TransformOp{
		offset: t.offset.Add(t2.offset),
	}
}


@@ 81,8 81,8 @@ func (t TransformOp) Add(o *Ops) {
	data := make([]byte, ops.TypeTransformLen)
	data[0] = byte(ops.TypeTransform)
	bo := binary.LittleEndian
	bo.PutUint32(data[1:], math.Float32bits(t.Transform.offset.X))
	bo.PutUint32(data[5:], math.Float32bits(t.Transform.offset.Y))
	bo.PutUint32(data[1:], math.Float32bits(t.offset.X))
	bo.PutUint32(data[5:], math.Float32bits(t.offset.Y))
	o.Write(data)
}



@@ 91,14 91,8 @@ func (t *TransformOp) Decode(d []byte) {
	if ops.OpType(d[0]) != ops.TypeTransform {
		panic("invalid op")
	}
	*t = TransformOp{
		Transform: Offset(f32.Point{
			X: math.Float32frombits(bo.Uint32(d[1:])),
			Y: math.Float32frombits(bo.Uint32(d[5:])),
		}),
	}
}

func Offset(o f32.Point) Transform {
	return Transform{o}
	*t = TransformOp{f32.Point{
		X: math.Float32frombits(bo.Uint32(d[1:])),
		Y: math.Float32frombits(bo.Uint32(d[5:])),
	}}
}