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 issue where some List items were invisible after window resize #3031

Merged
merged 1 commit into from Jun 3, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions widget/list.go
Expand Up @@ -111,6 +111,7 @@ func (l *List) scrollTo(id ListItemID) {
// Resize is called when this list should change size. We refresh to ensure invisible items are drawn.
func (l *List) Resize(s fyne.Size) {
l.BaseWidget.Resize(s)
l.offsetUpdated(l.scroller.Offset)
l.scroller.Content.(*fyne.Container).Layout.(*listLayout).updateList(true)
}

Expand Down
34 changes: 34 additions & 0 deletions widget/list_test.go
Expand Up @@ -384,6 +384,40 @@ func TestList_ScrollThenShrink(t *testing.T) {
assert.Equal(t, "Data 0", visibles[0].(*listItem).child.(*Label).Text)
}

func TestList_ScrollThenResizeWindow(t *testing.T) {
test.NewApp()
defer test.NewApp()

data := make([]string, 0, 20)
for i := 0; i < 20; i++ {
data = append(data, fmt.Sprintf("Data %d", i))
}

list := NewList(
func() int {
return len(data)
},
func() fyne.CanvasObject {
return NewLabel("TEMPLATE")
},
func(id ListItemID, item fyne.CanvasObject) {
item.(*Label).SetText(data[id])
},
)
w := test.NewWindow(list)
w.Resize(fyne.NewSize(300, 300))

list.scroller.ScrollToBottom()

// increase window size enough so that all elements are visible
w.Resize(fyne.NewSize(300, 1000))

visibles := list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children
visibleCount := len(visibles)
assert.Equal(t, 20, visibleCount)
assert.Equal(t, "Data 0", visibles[0].(*listItem).child.(*Label).Text)
}

func TestList_NoFunctionsSet(t *testing.T) {
list := &List{}
w := test.NewWindow(list)
Expand Down