mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
layout: compute Position.Offset correctly for ScrollToEnd Lists
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+2
-2
@@ -266,11 +266,11 @@ func (l *List) layout(ops *op.Ops, macro op.MacroOp) Dimensions {
|
||||
}
|
||||
l.Position.Count = len(children)
|
||||
l.Position.OffsetLast = mainMax - size
|
||||
pos := -l.Position.Offset
|
||||
// ScrollToEnd lists are end aligned.
|
||||
if space := l.Position.OffsetLast; l.ScrollToEnd && space > 0 {
|
||||
pos += space
|
||||
l.Position.Offset -= space
|
||||
}
|
||||
pos := -l.Position.Offset
|
||||
layout := func(child scrollChild) {
|
||||
sz := l.Axis.Convert(child.size)
|
||||
var cross int
|
||||
|
||||
@@ -25,6 +25,24 @@ func TestEmptyList(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestListScrollToEnd(t *testing.T) {
|
||||
l := List{
|
||||
ScrollToEnd: true,
|
||||
}
|
||||
gtx := Context{
|
||||
Ops: new(op.Ops),
|
||||
Constraints: Exact(image.Pt(20, 10)),
|
||||
}
|
||||
l.Layout(gtx, 1, func(gtx Context, idx int) Dimensions {
|
||||
return Dimensions{
|
||||
Size: image.Pt(10, 10),
|
||||
}
|
||||
})
|
||||
if want, got := -10, l.Position.Offset; want != got {
|
||||
t.Errorf("got offset %d, want %d", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListPosition(t *testing.T) {
|
||||
_s := func(e ...event.Event) []event.Event { return e }
|
||||
r := new(router.Router)
|
||||
|
||||
Reference in New Issue
Block a user