Skip to content

Commit

Permalink
fix: some List items were invisible after window resize
Browse files Browse the repository at this point in the history
  • Loading branch information
cmitsakis committed Jun 3, 2022
1 parent 20fbb51 commit f72af1e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
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

0 comments on commit f72af1e

Please sign in to comment.