mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
layout: added offset for last visible item to List
Signed-off-by: pierre <pierre.curto@gmail.com>
This commit is contained in:
+5
-1
@@ -69,6 +69,9 @@ type Position struct {
|
|||||||
// Offset is the distance in pixels from the top edge to the child at index
|
// Offset is the distance in pixels from the top edge to the child at index
|
||||||
// First.
|
// First.
|
||||||
Offset int
|
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 is the number of visible children.
|
||||||
Count int
|
Count int
|
||||||
}
|
}
|
||||||
@@ -230,9 +233,10 @@ 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
|
||||||
pos := -l.Position.Offset
|
pos := -l.Position.Offset
|
||||||
// ScrollToEnd lists are end aligned.
|
// ScrollToEnd lists are end aligned.
|
||||||
if space := mainMax - size; l.ScrollToEnd && space > 0 {
|
if space := l.Position.OffsetLast; l.ScrollToEnd && space > 0 {
|
||||||
pos += space
|
pos += space
|
||||||
}
|
}
|
||||||
for _, child := range children {
|
for _, child := range children {
|
||||||
|
|||||||
+31
-3
@@ -32,12 +32,14 @@ func TestListPosition(t *testing.T) {
|
|||||||
scroll []event.Event
|
scroll []event.Event
|
||||||
first int
|
first int
|
||||||
count int
|
count int
|
||||||
|
offset int
|
||||||
|
last int
|
||||||
}{
|
}{
|
||||||
{label: "no item"},
|
{label: "no item", last: 20},
|
||||||
{label: "1 visible 0 hidden", num: 1, count: 1},
|
{label: "1 visible 0 hidden", num: 1, count: 1, last: 10},
|
||||||
{label: "2 visible 0 hidden", num: 2, count: 2},
|
{label: "2 visible 0 hidden", num: 2, count: 2},
|
||||||
{label: "2 visible 1 hidden", num: 3, 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(
|
scroll: _s(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Source: pointer.Mouse,
|
Source: pointer.Mouse,
|
||||||
@@ -57,6 +59,26 @@ func TestListPosition(t *testing.T) {
|
|||||||
Position: f32.Pt(5, 0),
|
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,
|
{label: "2 visible 1 hidden large scroll", num: 3, count: 2, first: 1,
|
||||||
scroll: _s(
|
scroll: _s(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
@@ -97,6 +119,12 @@ func TestListPosition(t *testing.T) {
|
|||||||
if got, want := pos.Count, tc.count; got != want {
|
if got, want := pos.Count, tc.count; got != want {
|
||||||
t.Errorf("List: invalid number of visible children: got %v; want %v", 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)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user