mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 17:35:36 +00:00
layout.List: store constraints instead of whole context
Signed-off-by: pierre <pierre.curto@gmail.com>
This commit is contained in:
+10
-11
@@ -29,7 +29,7 @@ type List struct {
|
|||||||
// Alignment is the cross axis alignment of list elements.
|
// Alignment is the cross axis alignment of list elements.
|
||||||
Alignment Alignment
|
Alignment Alignment
|
||||||
|
|
||||||
ctx Context
|
cs Constraints
|
||||||
scroll gesture.Scroll
|
scroll gesture.Scroll
|
||||||
scrollDelta int
|
scrollDelta int
|
||||||
|
|
||||||
@@ -84,11 +84,11 @@ func (l *List) init(gtx Context, len int) {
|
|||||||
if l.more() {
|
if l.more() {
|
||||||
panic("unfinished child")
|
panic("unfinished child")
|
||||||
}
|
}
|
||||||
l.ctx = gtx
|
l.cs = gtx.Constraints
|
||||||
l.maxSize = 0
|
l.maxSize = 0
|
||||||
l.children = l.children[:0]
|
l.children = l.children[:0]
|
||||||
l.len = len
|
l.len = len
|
||||||
l.update()
|
l.update(gtx)
|
||||||
if l.scrollToEnd() || l.Position.First > len {
|
if l.scrollToEnd() || l.Position.First > len {
|
||||||
l.Position.Offset = 0
|
l.Position.Offset = 0
|
||||||
l.Position.First = len
|
l.Position.First = len
|
||||||
@@ -107,7 +107,7 @@ func (l *List) Layout(gtx Context, len int, w ListElement) Dimensions {
|
|||||||
call := child.Stop()
|
call := child.Stop()
|
||||||
l.end(dims, call)
|
l.end(dims, call)
|
||||||
}
|
}
|
||||||
return l.layout(macro)
|
return l.layout(gtx.Ops, macro)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *List) scrollToEnd() bool {
|
func (l *List) scrollToEnd() bool {
|
||||||
@@ -119,8 +119,8 @@ func (l *List) Dragging() bool {
|
|||||||
return l.scroll.State() == gesture.StateDragging
|
return l.scroll.State() == gesture.StateDragging
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *List) update() {
|
func (l *List) update(gtx Context) {
|
||||||
d := l.scroll.Scroll(l.ctx.Metric, l.ctx, l.ctx.Now, gesture.Axis(l.Axis))
|
d := l.scroll.Scroll(gtx.Metric, gtx, gtx.Now, gesture.Axis(l.Axis))
|
||||||
l.scrollDelta = d
|
l.scrollDelta = d
|
||||||
l.Position.Offset += d
|
l.Position.Offset += d
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ func (l *List) more() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *List) nextDir() iterationDir {
|
func (l *List) nextDir() iterationDir {
|
||||||
_, vsize := axisMainConstraint(l.Axis, l.ctx.Constraints)
|
_, vsize := axisMainConstraint(l.Axis, l.cs)
|
||||||
last := l.Position.First + len(l.children)
|
last := l.Position.First + len(l.children)
|
||||||
// Clamp offset.
|
// Clamp offset.
|
||||||
if l.maxSize-l.Position.Offset < vsize && last == l.len {
|
if l.maxSize-l.Position.Offset < vsize && last == l.len {
|
||||||
@@ -196,11 +196,11 @@ func (l *List) end(dims Dimensions, call op.CallOp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Layout the List and return its dimensions.
|
// Layout the List and return its dimensions.
|
||||||
func (l *List) layout(macro op.MacroOp) Dimensions {
|
func (l *List) layout(ops *op.Ops, macro op.MacroOp) Dimensions {
|
||||||
if l.more() {
|
if l.more() {
|
||||||
panic("unfinished child")
|
panic("unfinished child")
|
||||||
}
|
}
|
||||||
mainMin, mainMax := axisMainConstraint(l.Axis, l.ctx.Constraints)
|
mainMin, mainMax := axisMainConstraint(l.Axis, l.cs)
|
||||||
children := l.children
|
children := l.children
|
||||||
// Skip invisible children
|
// Skip invisible children
|
||||||
for len(children) > 0 {
|
for len(children) > 0 {
|
||||||
@@ -226,7 +226,6 @@ func (l *List) layout(macro op.MacroOp) Dimensions {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ops := l.ctx.Ops
|
|
||||||
pos := -l.Position.Offset
|
pos := -l.Position.Offset
|
||||||
// ScrollToEnd lists are end aligned.
|
// ScrollToEnd lists are end aligned.
|
||||||
if space := mainMax - size; l.ScrollToEnd && space > 0 {
|
if space := mainMax - size; l.ScrollToEnd && space > 0 {
|
||||||
@@ -275,7 +274,7 @@ func (l *List) layout(macro op.MacroOp) Dimensions {
|
|||||||
}
|
}
|
||||||
dims := axisPoint(l.Axis, pos, maxCross)
|
dims := axisPoint(l.Axis, pos, maxCross)
|
||||||
call := macro.Stop()
|
call := macro.Stop()
|
||||||
defer op.Push(l.ctx.Ops).Pop()
|
defer op.Push(ops).Pop()
|
||||||
pointer.Rect(image.Rectangle{Max: dims}).Add(ops)
|
pointer.Rect(image.Rectangle{Max: dims}).Add(ops)
|
||||||
l.scroll.Add(ops)
|
l.scroll.Add(ops)
|
||||||
call.Add(ops)
|
call.Add(ops)
|
||||||
|
|||||||
Reference in New Issue
Block a user