mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 18:35:34 +00:00
layout: make List approximate its length in Position
This commit adds a Length field to the layout.Position. This field contains an approximation of the overall length of the list's contents. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
@@ -74,6 +74,8 @@ type Position struct {
|
|||||||
OffsetLast int
|
OffsetLast int
|
||||||
// Count is the number of visible children.
|
// Count is the number of visible children.
|
||||||
Count int
|
Count int
|
||||||
|
// Length is the estimated total size of all children, measured in pixels.
|
||||||
|
Length int
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -106,11 +108,22 @@ func (l *List) Layout(gtx Context, len int, w ListElement) Dimensions {
|
|||||||
crossMin, crossMax := l.Axis.crossConstraint(gtx.Constraints)
|
crossMin, crossMax := l.Axis.crossConstraint(gtx.Constraints)
|
||||||
gtx.Constraints = l.Axis.constraints(0, inf, crossMin, crossMax)
|
gtx.Constraints = l.Axis.constraints(0, inf, crossMin, crossMax)
|
||||||
macro := op.Record(gtx.Ops)
|
macro := op.Record(gtx.Ops)
|
||||||
|
laidOutTotalLength := 0
|
||||||
|
numLaidOut := 0
|
||||||
|
|
||||||
for l.next(); l.more(); l.next() {
|
for l.next(); l.more(); l.next() {
|
||||||
child := op.Record(gtx.Ops)
|
child := op.Record(gtx.Ops)
|
||||||
dims := w(gtx, l.index())
|
dims := w(gtx, l.index())
|
||||||
call := child.Stop()
|
call := child.Stop()
|
||||||
l.end(dims, call)
|
l.end(dims, call)
|
||||||
|
laidOutTotalLength += l.Axis.Convert(dims.Size).X
|
||||||
|
numLaidOut++
|
||||||
|
}
|
||||||
|
|
||||||
|
if numLaidOut > 0 {
|
||||||
|
l.Position.Length = laidOutTotalLength * len / numLaidOut
|
||||||
|
} else {
|
||||||
|
l.Position.Length = 0
|
||||||
}
|
}
|
||||||
return l.layout(gtx.Ops, macro)
|
return l.layout(gtx.Ops, macro)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user