Skip to content

Commit

Permalink
A few cache fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Feb 27, 2024
1 parent 52c0abb commit 71ebcd2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 10 additions & 1 deletion internal/widget/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Base struct {
hidden atomic.Bool
position async.Position
size async.Size
minCache async.Size
impl atomic.Pointer[fyne.Widget]
}

Expand Down Expand Up @@ -63,14 +64,21 @@ func (w *Base) Move(pos fyne.Position) {

// MinSize for the widget - it should never be resized below this value.
func (w *Base) MinSize() fyne.Size {
minCache := w.minCache.Load()
if !minCache.IsZero() {
return minCache
}

impl := w.super()

r := cache.Renderer(impl)
if r == nil {
return fyne.NewSize(0, 0)
}

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

// Visible returns whether or not this widget should be visible.
Expand Down Expand Up @@ -114,6 +122,7 @@ func (w *Base) Refresh() {

render := cache.Renderer(impl)
render.Refresh()
w.minCache.Store(fyne.Size{})
}

// super will return the actual object that this represents.
Expand Down
4 changes: 3 additions & 1 deletion widget/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ func (w *BaseWidget) MinSize() fyne.Size {
return minCache
}

return w.MinSizeFromRenderer()
min := w.MinSizeFromRenderer()
w.minCache.Store(min)
return min
}

// MinSizeFromRenderer returns the MinSize has defined by this widget's renderer.
Expand Down

0 comments on commit 71ebcd2

Please sign in to comment.