Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix last row sometimes being missing in List #4911

Merged
merged 4 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions widget/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,11 @@ func (l *listLayout) calculateVisibleRowHeights(itemHeight float32, length int)
offY = 0
}

if maxRow > length {
maxRow = length
if maxRow > length-1 {
maxRow = length - 1
}

for i := 0; i < maxRow-minRow; i++ {
for i := 0; i <= maxRow-minRow; i++ {
l.visibleRowHeights = append(l.visibleRowHeights, itemHeight)
}
return
Expand Down
8 changes: 4 additions & 4 deletions widget/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func TestList_ScrollThenShrink(t *testing.T) {

visibles := list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children
visibleCount := len(visibles)
assert.Equal(t, visibleCount, 8)
assert.Equal(t, visibleCount, 9)

list.scroller.ScrollToBottom()
visibles = list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children
Expand Down Expand Up @@ -637,11 +637,11 @@ func TestList_LimitUpdateItem(t *testing.T) {
)
w.SetContent(list)
w.ShowAndRun()
assert.Equal(t, "0.0.", printOut)
assert.Equal(t, "0.1.0.1.", printOut)
list.scrollTo(1)
assert.Equal(t, "0.0.1.", printOut)
assert.Equal(t, "0.1.0.1.2.", printOut)
list.scrollTo(2)
assert.Equal(t, "0.0.1.2.", printOut)
assert.Equal(t, "0.1.0.1.2.3.", printOut)
}

func TestList_RefreshUpdatesAllItems(t *testing.T) {
Expand Down
15 changes: 15 additions & 0 deletions widget/testdata/list/initial.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@
</widget>
</container>
</widget>
<widget pos="0,429" size="192x35" type="*widget.listItem">
<container size="192x35">
<widget size="20x35" type="*widget.Icon">
<image fillMode="contain" rsc="documentIcon" size="20x35" themed="foreground"/>
</widget>
<widget pos="24,0" size="168x35" type="*widget.Label">
<widget size="168x35" type="*widget.RichText">
<text pos="8,8" size="80x19">Test Item 11</text>
</widget>
</widget>
</container>
</widget>
<widget size="0x0" type="*widget.Separator">
<rectangle fillColor="separator" size="0x0"/>
</widget>
Expand Down Expand Up @@ -168,6 +180,9 @@
<widget pos="0,388" size="192x1" type="*widget.Separator">
<rectangle fillColor="separator" size="192x1"/>
</widget>
<widget pos="0,427" size="192x1" type="*widget.Separator">
<rectangle fillColor="separator" size="192x1"/>
</widget>
</container>
<widget pos="0,392" size="192x0" type="*widget.Shadow">
<linearGradient endColor="shadow" pos="0,-8" size="192x8"/>
Expand Down
4 changes: 2 additions & 2 deletions widget/testdata/list/item_removed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<widget size="20x35" type="*widget.Icon">
<image fillMode="contain" rsc="documentIcon" size="20x35" themed="foreground"/>
</widget>
<widget pos="24,0" size="123x35" type="*widget.Label">
<widget size="123x35" type="*widget.RichText">
<widget pos="24,0" size="88x35" type="*widget.Label">
<widget size="88x35" type="*widget.RichText">
<text pos="8,8" size="72x19">Test Item 1</text>
</widget>
</widget>
Expand Down
15 changes: 15 additions & 0 deletions widget/testdata/list/new_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@
</widget>
</container>
</widget>
<widget pos="0,429" size="192x35" type="*widget.listItem">
<container size="192x35">
<widget size="20x35" type="*widget.Icon">
<image fillMode="contain" rsc="documentIcon" size="20x35" themed="foreground"/>
</widget>
<widget pos="24,0" size="168x35" type="*widget.Label">
<widget size="168x35" type="*widget.RichText">
<text pos="8,8" size="3x19">l</text>
</widget>
</widget>
</container>
</widget>
<widget size="0x0" type="*widget.Separator">
<rectangle fillColor="separator" size="0x0"/>
</widget>
Expand Down Expand Up @@ -168,6 +180,9 @@
<widget pos="0,388" size="192x1" type="*widget.Separator">
<rectangle fillColor="separator" size="192x1"/>
</widget>
<widget pos="0,427" size="192x1" type="*widget.Separator">
<rectangle fillColor="separator" size="192x1"/>
</widget>
</container>
<widget pos="0,392" size="192x0" type="*widget.Shadow">
<linearGradient endColor="shadow" pos="0,-8" size="192x8"/>
Expand Down
15 changes: 15 additions & 0 deletions widget/testdata/list/offset_changed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@
</widget>
</container>
</widget>
<widget pos="0,703" size="192x35" type="*widget.listItem">
<container size="192x35">
<widget size="20x35" type="*widget.Icon">
<image fillMode="contain" rsc="documentIcon" size="20x35" themed="foreground"/>
</widget>
<widget pos="24,0" size="168x35" type="*widget.Label">
<widget size="168x35" type="*widget.RichText">
<text pos="8,8" size="80x19">Test Item 18</text>
</widget>
</widget>
</container>
</widget>
<widget size="0x0" type="*widget.Separator">
<rectangle fillColor="separator" size="0x0"/>
</widget>
Expand Down Expand Up @@ -168,6 +180,9 @@
<widget pos="0,661" size="192x1" type="*widget.Separator">
<rectangle fillColor="separator" size="192x1"/>
</widget>
<widget pos="0,700" size="192x1" type="*widget.Separator">
<rectangle fillColor="separator" size="192x1"/>
</widget>
</container>
<widget size="192x0" type="*widget.Shadow">
<linearGradient size="192x8" startColor="shadow"/>
Expand Down
15 changes: 15 additions & 0 deletions widget/testdata/list/resized.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@
</widget>
</container>
</widget>
<widget pos="0,625" size="192x35" type="*widget.listItem">
<container size="192x35">
<widget size="20x35" type="*widget.Icon">
<image fillMode="contain" rsc="documentIcon" size="20x35" themed="foreground"/>
</widget>
<widget pos="24,0" size="168x35" type="*widget.Label">
<widget size="168x35" type="*widget.RichText">
<text pos="8,8" size="80x19">Test Item 16</text>
</widget>
</widget>
</container>
</widget>
<widget size="0x0" type="*widget.Separator">
<rectangle fillColor="separator" size="0x0"/>
</widget>
Expand Down Expand Up @@ -243,6 +255,9 @@
<widget pos="0,583" size="192x1" type="*widget.Separator">
<rectangle fillColor="separator" size="192x1"/>
</widget>
<widget pos="0,622" size="192x1" type="*widget.Separator">
<rectangle fillColor="separator" size="192x1"/>
</widget>
</container>
<widget pos="0,592" size="192x0" type="*widget.Shadow">
<linearGradient endColor="shadow" pos="0,-8" size="192x8"/>
Expand Down