Skip to content

Commit

Permalink
Merge pull request #4186 from Jacalz/fix-progressbar-color
Browse files Browse the repository at this point in the history
Fix progressbar text having the wrong color sometimes
  • Loading branch information
Jacalz authored Aug 23, 2023
2 parents 852632a + 862e6b4 commit 4a46f1a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions widget/progressbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func (p *progressRenderer) MinSize() fyne.Size {
tsize = fyne.MeasureText("100%", p.label.TextSize, p.label.TextStyle)
}

return fyne.NewSize(tsize.Width+theme.InnerPadding()*2, tsize.Height+theme.InnerPadding()*2)
padding := theme.InnerPadding() * 2
return fyne.NewSize(tsize.Width+padding, tsize.Height+padding)
}

func (p *progressRenderer) updateBar() {
Expand Down Expand Up @@ -76,6 +77,7 @@ func (p *progressRenderer) Refresh() {
p.updateBar()
p.background.Refresh()
p.bar.Refresh()
p.label.Refresh()
canvas.Refresh(p.progress.super())
}

Expand Down Expand Up @@ -127,7 +129,7 @@ func (p *ProgressBar) CreateRenderer() fyne.WidgetRenderer {
background.CornerRadius = theme.InputRadiusSize()
bar := canvas.NewRectangle(theme.PrimaryColor())
bar.CornerRadius = theme.InputRadiusSize()
label := canvas.NewText("0%", theme.ForegroundColor())
label := canvas.NewText("0%", theme.BackgroundColor())
label.Alignment = fyne.TextAlignCenter
return &progressRenderer{widget.NewBaseRenderer([]fyne.CanvasObject{background, bar, label}), background, bar, label, p}
}
Expand Down
5 changes: 5 additions & 0 deletions widget/progressbar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func TestProgressRenderer_ApplyTheme(t *testing.T) {
bar := NewProgressBar()
render := test.WidgetRenderer(bar).(*progressRenderer)

oldLabelColor := render.label.Color
render.Refresh()
newLabelColor := render.label.Color
assert.Equal(t, oldLabelColor, newLabelColor)

textSize := render.label.TextSize
customTextSize := textSize
test.WithTestTheme(t, func() {
Expand Down

0 comments on commit 4a46f1a

Please sign in to comment.