From 8216c18853fe81ea695dc4b3d3bb5aaca368d586 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Sat, 11 May 2024 08:54:42 -0700 Subject: [PATCH] handle SetItemHeight with the default height as a special case --- widget/list.go | 18 +++++++++++++----- widget/list_test.go | 4 ++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/widget/list.go b/widget/list.go index 88f1eecdce..db8e192c32 100644 --- a/widget/list.go +++ b/widget/list.go @@ -139,14 +139,22 @@ func (l *List) RefreshItem(id ListItemID) { func (l *List) SetItemHeight(id ListItemID, height float32) { l.propertyLock.Lock() - if l.itemHeights == nil { - l.itemHeights = make(map[ListItemID]float32) + var refresh bool + if height == l.itemMin.Height { + // special case - unset custom item height for this item + if l.itemHeights != nil { + _, refresh = l.itemHeights[id] + delete(l.itemHeights, id) + } + } else { + if l.itemHeights == nil { + l.itemHeights = make(map[ListItemID]float32) + } + refresh = l.itemHeights[id] != height + l.itemHeights[id] = height } - refresh := l.itemHeights[id] != height - l.itemHeights[id] = height l.propertyLock.Unlock() - if refresh { l.RefreshItem(id) } diff --git a/widget/list_test.go b/widget/list_test.go index 74f2019ece..edebf05570 100644 --- a/widget/list_test.go +++ b/widget/list_test.go @@ -129,6 +129,10 @@ func TestList_SetItemHeight(t *testing.T) { w := test.NewWindow(list) w.Resize(fyne.NewSize(200, 200)) test.AssertImageMatches(t, "list/list_item_height.png", w.Canvas().Capture()) + + // special case of resetting item back to default height + list.SetItemHeight(2, 10) + assert.Equal(t, 0, len(list.itemHeights)) } func TestList_SetItemHeight_InUpdate(t *testing.T) {