mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +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.Count = len(children)
|
||||||
l.Position.OffsetLast = mainMax - size
|
l.Position.OffsetLast = mainMax - size
|
||||||
pos := -l.Position.Offset
|
|
||||||
// ScrollToEnd lists are end aligned.
|
// ScrollToEnd lists are end aligned.
|
||||||
if space := l.Position.OffsetLast; l.ScrollToEnd && space > 0 {
|
if space := l.Position.OffsetLast; l.ScrollToEnd && space > 0 {
|
||||||
pos += space
|
l.Position.Offset -= space
|
||||||
}
|
}
|
||||||
|
pos := -l.Position.Offset
|
||||||
layout := func(child scrollChild) {
|
layout := func(child scrollChild) {
|
||||||
sz := l.Axis.Convert(child.size)
|
sz := l.Axis.Convert(child.size)
|
||||||
var cross int
|
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) {
|
func TestListPosition(t *testing.T) {
|
||||||
_s := func(e ...event.Event) []event.Event { return e }
|
_s := func(e ...event.Event) []event.Event { return e }
|
||||||
r := new(router.Router)
|
r := new(router.Router)
|
||||||
|
|||||||
Reference in New Issue
Block a user