diff --git a/layout/list.go b/layout/list.go index 69beabb8..39f72db2 100644 --- a/layout/list.go +++ b/layout/list.go @@ -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 diff --git a/layout/list_test.go b/layout/list_test.go index 1ba2691f..eb1da0f8 100644 --- a/layout/list_test.go +++ b/layout/list_test.go @@ -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)