layout: added offset for last visible item to List

Signed-off-by: pierre <pierre.curto@gmail.com>
This commit is contained in:
pierre
2021-01-21 18:17:10 +01:00
committed by Elias Naur
parent 74eb0a4a34
commit a928c07a1c
2 changed files with 36 additions and 4 deletions
+31 -3
View File
@@ -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)
}
})
}
}