Skip to content

Commit

Permalink
Merge pull request #4847 from Jacalz/progressbarinf-renderer-created-…
Browse files Browse the repository at this point in the history
…in-constructor

Don't create the renderer in the constructor for infinite progressbar
  • Loading branch information
Jacalz committed May 19, 2024
2 parents 2ede901 + da6c5d5 commit 75511b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 3 additions & 3 deletions widget/progressbarinfinite.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (p *ProgressBarInfinite) CreateRenderer() fyne.WidgetRenderer {
// SetValue() is not defined for infinite progress bar
// To stop the looping progress and set the progress bar to 100%, call ProgressBarInfinite.Stop()
func NewProgressBarInfinite() *ProgressBarInfinite {
p := &ProgressBarInfinite{}
cache.Renderer(p).Layout(p.MinSize())
return p
bar := &ProgressBarInfinite{}
bar.ExtendBaseWidget(bar)
return bar
}
17 changes: 16 additions & 1 deletion widget/progressbarinfinite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,24 @@ func BenchmarkProgressbarInf(b *testing.B) {

func TestProgressBarInfinite_Creation(t *testing.T) {
bar := NewProgressBarInfinite()
// ticker should start automatically

// ticker should be disabled until the widget is shown
assert.False(t, bar.Running())

win := test.NewWindow(bar)
defer win.Close()
win.Show()

// ticker should start automatically once the renderer is created
assert.True(t, bar.Running())
}

func TestProgressBarInfinite_Destroy(t *testing.T) {
bar := NewProgressBarInfinite()
win := test.NewWindow(bar)
defer win.Close()
win.Show()

assert.True(t, cache.IsRendered(bar))
assert.True(t, bar.Running())

Expand All @@ -46,6 +58,9 @@ func TestProgressBarInfinite_Destroy(t *testing.T) {

func TestProgressBarInfinite_Reshown(t *testing.T) {
bar := NewProgressBarInfinite()
win := test.NewWindow(bar)
defer win.Close()
win.Show()

assert.True(t, bar.Running())
bar.Hide()
Expand Down

0 comments on commit 75511b3

Please sign in to comment.