Skip to content

Commit

Permalink
Actually set the cache correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed May 2, 2024
1 parent e3095b9 commit 11c3782
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
4 changes: 3 additions & 1 deletion internal/widget/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ func (w *Base) MinSize() fyne.Size {
return fyne.NewSize(0, 0)
}

return r.MinSize()
minSize := r.MinSize()
w.minCache.Store(minSize)
return minSize
}

// Visible returns whether or not this widget should be visible.
Expand Down
4 changes: 3 additions & 1 deletion widget/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ func (w *BaseWidget) MinSize() fyne.Size {
return fyne.Size{}
}

return r.MinSize()
minSize := r.MinSize()
w.minCache.Store(minSize)
return minSize
}

// Visible returns whether or not this widget should be visible.
Expand Down
34 changes: 31 additions & 3 deletions widget/widget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,49 @@ func TestSimpleRenderer(t *testing.T) {
test.AssertImageMatches(t, "simple_renderer.png", window.Canvas().Capture())
}

func TestMinSizeCache(t *testing.T) {
label := NewLabel("a")

wid := newTestWidget(label)
assert.Equal(t, 0, wid.minSizeCalls)

minSize := wid.MinSize()
assert.NotEqual(t, 0, minSize)
assert.Equal(t, 1, wid.minSizeCalls)

wid.MinSize()
assert.Equal(t, 1, wid.minSizeCalls)
}

type testWidget struct {
BaseWidget
obj fyne.CanvasObject
obj fyne.CanvasObject
minSizeCalls int
}

func newTestWidget(o fyne.CanvasObject) fyne.Widget {
func newTestWidget(o fyne.CanvasObject) *testWidget {
t := &testWidget{obj: o}
t.ExtendBaseWidget(t)
return t
}

func (t *testWidget) CreateRenderer() fyne.WidgetRenderer {
return NewSimpleRenderer(t.obj)
return &testRenderer{
WidgetRenderer: NewSimpleRenderer(t.obj),
widget: t,
}
}

func waitForBinding() {
time.Sleep(time.Millisecond * 100) // data resolves on background thread
}

type testRenderer struct {
widget *testWidget
fyne.WidgetRenderer
}

func (r *testRenderer) MinSize() fyne.Size {
r.widget.minSizeCalls++
return r.WidgetRenderer.MinSize()
}

0 comments on commit 11c3782

Please sign in to comment.