Skip to content

Commit

Permalink
Fix scrolling a List item to be visible when it is larger than the te…
Browse files Browse the repository at this point in the history
…mplate

Fixes fyne-io#5281
  • Loading branch information
andydotxyz committed Jan 17, 2025
1 parent 6fc5c9a commit 682827f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 6 additions & 2 deletions widget/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,18 @@ func (l *List) scrollTo(id ListItemID) {
if len(l.itemHeights) == 0 {
y = (float32(id) * l.itemMin.Height) + (float32(id) * separatorThickness)
} else {
for i := 0; i < id; i++ {
i := 0
for ; i < id; i++ {
height := l.itemMin.Height
if h, ok := l.itemHeights[i]; ok {
height = h
}

y += height + separatorThickness
lastItemHeight = height
}
lastItemHeight = l.itemMin.Height
if h, ok := l.itemHeights[i]; ok {
lastItemHeight = h
}
}

Expand Down
19 changes: 19 additions & 0 deletions widget/list_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,25 @@ func TestList_RefreshUpdatesAllItems(t *testing.T) {
assert.Equal(t, "0.0.", printOut)
}

func TestList_ScrollToLargeItem(t *testing.T) {
list := NewList(
func() int {
return 10
},
func() fyne.CanvasObject {
return NewLabel("Row")
},
func(id ListItemID, item fyne.CanvasObject) {
},
)
list.SetItemHeight(9, 50)
w := test.NewTempWindow(t, list)

w.SetContent(list)
list.scrollTo(9)
assert.Equal(t, list.scroller.Content.MinSize().Height-list.Size().Height, list.scroller.Offset.Y)
}

var minSize fyne.Size

func BenchmarkContentMinSize(b *testing.B) {
Expand Down

0 comments on commit 682827f

Please sign in to comment.