~eliasnaur/gio

a928c07a1c44daa22308615cae6a2d3be79c06ca — pierre 3 months ago 74eb0a4
layout: added offset for last visible item to List

Signed-off-by: pierre <pierre.curto@gmail.com>
2 files changed, 36 insertions(+), 4 deletions(-)

M layout/list.go
M layout/list_test.go
M layout/list.go => layout/list.go +5 -1
@@ 69,6 69,9 @@ type Position struct {
	// Offset is the distance in pixels from the top edge to the child at index
	// First.
	Offset int
	// OffsetLast is the signed distance in pixels from the bottom edge to the
	// bottom edge of the child at index First+Count.
	OffsetLast int
	// Count is the number of visible children.
	Count int
}


@@ 230,9 233,10 @@ 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 := mainMax - size; l.ScrollToEnd && space > 0 {
	if space := l.Position.OffsetLast; l.ScrollToEnd && space > 0 {
		pos += space
	}
	for _, child := range children {

M layout/list_test.go => layout/list_test.go +31 -3
@@ 32,12 32,14 @@ func TestListPosition(t *testing.T) {
		scroll []event.Event
		first  int
		count  int
		offset int
		last   int
	}{
		{label: "no item"},
		{label: "1 visible 0 hidden", num: 1, count: 1},
		{label: "no item", last: 20},
		{label: "1 visible 0 hidden", num: 1, count: 1, last: 10},
		{label: "2 visible 0 hidden", num: 2, count: 2},
		{label: "2 visible 1 hidden", num: 3, count: 2},
		{label: "3 visible 0 hidden small scroll", num: 3, count: 3,
		{label: "3 visible 0 hidden small scroll", num: 3, count: 3, offset: 5, last: -5,
			scroll: _s(
				pointer.Event{
					Source:   pointer.Mouse,


@@ 57,6 59,26 @@ func TestListPosition(t *testing.T) {
					Position: f32.Pt(5, 0),
				},
			)},
		{label: "3 visible 0 hidden small scroll 2", num: 3, count: 3, offset: 3, last: -7,
			scroll: _s(
				pointer.Event{
					Source:   pointer.Mouse,
					Buttons:  pointer.ButtonLeft,
					Type:     pointer.Press,
					Position: f32.Pt(0, 0),
				},
				pointer.Event{
					Source: pointer.Mouse,
					Type:   pointer.Scroll,
					Scroll: f32.Pt(3, 0),
				},
				pointer.Event{
					Source:   pointer.Mouse,
					Buttons:  pointer.ButtonLeft,
					Type:     pointer.Release,
					Position: f32.Pt(5, 0),
				},
			)},
		{label: "2 visible 1 hidden large scroll", num: 3, count: 2, first: 1,
			scroll: _s(
				pointer.Event{


@@ 97,6 119,12 @@ func TestListPosition(t *testing.T) {
			if got, want := pos.Count, tc.count; got != want {
				t.Errorf("List: invalid number of visible children: got %v; want %v", got, want)
			}
			if got, want := pos.Offset, tc.offset; got != want {
				t.Errorf("List: invalid first visible offset: got %v; want %v", got, want)
			}
			if got, want := pos.OffsetLast, tc.last; got != want {
				t.Errorf("List: invalid last visible offset: got %v; want %v", got, want)
			}
		})
	}
}