mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 18:35:34 +00:00
ui/layout: implement List.Invert for end aligned lists
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+17
-5
@@ -18,8 +18,8 @@ type scrollChild struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type List struct {
|
type List struct {
|
||||||
Axis Axis
|
Axis Axis
|
||||||
|
Invert bool
|
||||||
CrossAxisAlignment CrossAxisAlignment
|
CrossAxisAlignment CrossAxisAlignment
|
||||||
|
|
||||||
// The distance scrolled since last call to Init.
|
// The distance scrolled since last call to Init.
|
||||||
@@ -68,6 +68,9 @@ func (l *List) Dragging() bool {
|
|||||||
func (l *List) Update(c *ui.Config, q input.Events) {
|
func (l *List) Update(c *ui.Config, q input.Events) {
|
||||||
l.Distance = 0
|
l.Distance = 0
|
||||||
d := l.scroll.Update(c, q, gesture.Axis(l.Axis))
|
d := l.scroll.Update(c, q, gesture.Axis(l.Axis))
|
||||||
|
if l.Invert {
|
||||||
|
d = -d
|
||||||
|
}
|
||||||
l.scrollDir = d
|
l.scrollDir = d
|
||||||
l.Distance += d
|
l.Distance += d
|
||||||
l.offset += d
|
l.offset += d
|
||||||
@@ -78,6 +81,9 @@ func (l *List) Next() (int, Constraints, bool) {
|
|||||||
panic("a previous Next was not finished with Elem")
|
panic("a previous Next was not finished with Elem")
|
||||||
}
|
}
|
||||||
i, ok := l.next()
|
i, ok := l.next()
|
||||||
|
if l.Invert {
|
||||||
|
i = l.len - 1 - i
|
||||||
|
}
|
||||||
var cs Constraints
|
var cs Constraints
|
||||||
if ok {
|
if ok {
|
||||||
cs = axisConstraints(l.Axis, Constraint{Max: ui.Inf}, l.crossConstraintChild(l.cs))
|
cs = axisConstraints(l.Axis, Constraint{Max: ui.Inf}, l.crossConstraintChild(l.cs))
|
||||||
@@ -167,7 +173,8 @@ func (l *List) Layout() Dimens {
|
|||||||
case Center:
|
case Center:
|
||||||
cross = (maxCross - axisCross(l.Axis, sz)) / 2
|
cross = (maxCross - axisCross(l.Axis, sz)) / 2
|
||||||
}
|
}
|
||||||
max := axisMain(l.Axis, sz) + pos
|
childSize := axisMain(l.Axis, sz)
|
||||||
|
max := childSize + pos
|
||||||
if max > mainc.Max {
|
if max > mainc.Max {
|
||||||
max = mainc.Max
|
max = mainc.Max
|
||||||
}
|
}
|
||||||
@@ -175,6 +182,11 @@ func (l *List) Layout() Dimens {
|
|||||||
if min < 0 {
|
if min < 0 {
|
||||||
min = 0
|
min = 0
|
||||||
}
|
}
|
||||||
|
transPos := pos
|
||||||
|
if l.Invert {
|
||||||
|
transPos = mainc.Max - transPos - childSize
|
||||||
|
min, max = mainc.Max-max, mainc.Max-min
|
||||||
|
}
|
||||||
r := image.Rectangle{
|
r := image.Rectangle{
|
||||||
Min: axisPoint(l.Axis, min, -ui.Inf),
|
Min: axisPoint(l.Axis, min, -ui.Inf),
|
||||||
Max: axisPoint(l.Axis, max, ui.Inf),
|
Max: axisPoint(l.Axis, max, ui.Inf),
|
||||||
@@ -182,11 +194,11 @@ func (l *List) Layout() Dimens {
|
|||||||
ui.OpPush{}.Add(ops)
|
ui.OpPush{}.Add(ops)
|
||||||
draw.RectClip(r).Add(ops)
|
draw.RectClip(r).Add(ops)
|
||||||
ui.OpTransform{
|
ui.OpTransform{
|
||||||
Transform: ui.Offset(toPointF(axisPoint(l.Axis, pos, cross))),
|
Transform: ui.Offset(toPointF(axisPoint(l.Axis, transPos, cross))),
|
||||||
}.Add(ops)
|
}.Add(ops)
|
||||||
child.block.Add(ops)
|
child.block.Add(ops)
|
||||||
ui.OpPop{}.Add(ops)
|
ui.OpPop{}.Add(ops)
|
||||||
pos += axisMain(l.Axis, sz)
|
pos += childSize
|
||||||
}
|
}
|
||||||
atStart := l.first == 0 && l.offset <= 0
|
atStart := l.first == 0 && l.offset <= 0
|
||||||
atEnd := l.first+len(l.children) == l.len && mainc.Max >= pos
|
atEnd := l.first+len(l.children) == l.len && mainc.Max >= pos
|
||||||
|
|||||||
Reference in New Issue
Block a user