~eliasnaur/gio-patches

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] layout: refactor List.Layout and related functions

Details
Message ID
<20200712192332.98637-1-larry@theclapp.org>
DKIM signature
missing
Download raw message
Patch: +13 -18
I found the interplay of List's Layout/init/next/more/end methods
somewhat confusing and hard to reason about, so I refactored them.

Signed-off-by: Larry Clapp <larry@theclapp.org>
---
 layout/list.go | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/layout/list.go b/layout/list.go
index dad83cf..2375fea 100644
--- a/layout/list.go
+++ b/layout/list.go
@@ -30,8 +30,6 @@ type List struct {
	Alignment Alignment

	ctx         Context
	macro       op.MacroOp
	child       op.MacroOp
	scroll      gesture.Scroll
	scrollDelta int

@@ -95,20 +93,21 @@ func (l *List) init(gtx Context, len int) {
		l.Position.Offset = 0
		l.Position.First = len
	}
	l.macro = op.Record(gtx.Ops)
	l.next()
}

// Layout the List.
func (l *List) Layout(gtx Context, len int, w ListElement) Dimensions {
	for l.init(gtx, len); l.more(); l.next() {
		crossMin, crossMax := axisCrossConstraint(l.Axis, l.ctx.Constraints)
		cs := axisConstraints(l.Axis, 0, inf, crossMin, crossMax)
		i := l.index()
		gtx.Constraints = cs
		l.end(w(gtx, i))
	l.init(gtx, len)
	crossMin, crossMax := axisCrossConstraint(l.Axis, gtx.Constraints)
	gtx.Constraints = axisConstraints(l.Axis, 0, inf, crossMin, crossMax)
	macro := op.Record(gtx.Ops)
	for l.next(); l.more(); l.next() {
		child := op.Record(gtx.Ops)
		dims := w(gtx, l.index())
		call := child.Stop()
		l.end(dims, call)
	}
	return l.layout()
	return l.layout(macro)
}

func (l *List) scrollToEnd() bool {
@@ -136,9 +135,6 @@ func (l *List) next() {
		l.Position.Offset += l.scrollDelta
		l.dir = l.nextDir()
	}
	if l.more() {
		l.child = op.Record(l.ctx.Ops)
	}
}

// index is current child's position in the underlying list.
@@ -180,8 +176,7 @@ func (l *List) nextDir() iterationDir {
}

// End the current child by specifying its dimensions.
func (l *List) end(dims Dimensions) {
	call := l.child.Stop()
func (l *List) end(dims Dimensions, call op.CallOp) {
	child := scrollChild{dims.Size, call}
	mainSize := axisMain(l.Axis, child.size)
	l.maxSize += mainSize
@@ -199,7 +194,7 @@ func (l *List) end(dims Dimensions) {
}

// Layout the List and return its dimensions.
func (l *List) layout() Dimensions {
func (l *List) layout(macro op.MacroOp) Dimensions {
	if l.more() {
		panic("unfinished child")
	}
@@ -277,7 +272,7 @@ func (l *List) layout() Dimensions {
		pos = mainMax
	}
	dims := axisPoint(l.Axis, pos, maxCross)
	call := l.macro.Stop()
	call := macro.Stop()
	defer op.Push(l.ctx.Ops).Pop()
	pointer.Rect(image.Rectangle{Max: dims}).Add(ops)
	l.scroll.Add(ops)
-- 
2.26.2
Details
Message ID
<C44XQNWDBB1X.3QORNSSZNEA1U@themachine>
In-Reply-To
<20200712192332.98637-1-larry@theclapp.org> (view parent)
DKIM signature
pass
Download raw message
On Sun Jul 12, 2020 at 15:23, Larry Clapp wrote:
> I found the interplay of List's Layout/init/next/more/end methods
> somewhat confusing and hard to reason about, so I refactored them.
>

Makes sense: the methods are vestiges from when Layout was split.

Merged, thanks.

-- elias
Review patch Export thread (mbox)