Skip to content

Commit

Permalink
Merge pull request #5412 from dweymouth/gridwrap-crash-before-renderer
Browse files Browse the repository at this point in the history
Fix GridWrap crash when resized to same size before renderer created
  • Loading branch information
dweymouth authored Jan 15, 2025
2 parents d7eeddc + 5df62d2 commit a41cb86
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions widget/gridwrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ func (l *GridWrap) RefreshItem(id GridWrapItemID) {
func (l *GridWrap) Resize(s fyne.Size) {
l.colCountCache = 0
l.BaseWidget.Resize(s)
l.offsetUpdated(l.scroller.Offset)
l.scroller.Content.(*fyne.Container).Layout.(*gridWrapLayout).updateGrid(true)
if l.scroller != nil {
l.offsetUpdated(l.scroller.Offset)
l.scroller.Content.(*fyne.Container).Layout.(*gridWrapLayout).updateGrid(true)
}
}

// Select adds the item identified by the given ID to the selection.
Expand Down
11 changes: 11 additions & 0 deletions widget/gridwrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,14 @@ func TestGridWrap_Selection(t *testing.T) {
assert.Equal(t, -1, selected)
assert.Equal(t, 9, unselected)
}

func TestGridWrap_ResizeToSameSizeBeforeRender(t *testing.T) {
g := NewGridWrap(
func() int { return 1 },
func() fyne.CanvasObject { return NewLabel("") },
func(gwii GridWrapItemID, co fyne.CanvasObject) { co.(*Label).SetText("foo") },
)
// will not create renderer.
// will crash if GridWrap scroller (not yet created) is accessed
g.Resize(fyne.NewSize(0, 0))
}

0 comments on commit a41cb86

Please sign in to comment.