Skip to content

Commit

Permalink
Fix crash when no text color is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Aug 4, 2021
1 parent 10f2573 commit 66a51e1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -3,7 +3,7 @@
This file lists the main changes with each version of the Fyne toolkit.
More detailed release notes can be found on the [releases page](https://github.com/fyne-io/fyne/releases).

## 2.0.4 - 4 August 2021
## 2.0.4 - 6 August 2021

### Changed

Expand All @@ -28,6 +28,8 @@ More detailed release notes can be found on the [releases page](https://github.c
* ScrollToBottom not always scrolling all the way when items added to container.Scroller
* Fixed scrollbar disappearing after changing content (#2303)
* Calling SetContent a second time with the same content will not show
* Drawing text can panic when Color is nil (#2347)
* Optimisations when drawing transparent rectangle or whitespace strings


## 2.0.3 - 30 April 2021
Expand Down
7 changes: 6 additions & 1 deletion internal/painter/gl/gl_common.go
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"runtime"

"fyne.io/fyne/v2/theme"
"github.com/goki/freetype"
"github.com/goki/freetype/truetype"
"golang.org/x/image/font"
Expand Down Expand Up @@ -72,6 +73,10 @@ func (p *glPainter) newGlStrokedRectTexture(obj fyne.CanvasObject) Texture {

func (p *glPainter) newGlTextTexture(obj fyne.CanvasObject) Texture {
text := obj.(*canvas.Text)
color := text.Color
if color == nil {
color = theme.ForegroundColor()
}

bounds := text.MinSize()
width := int(p.textureScale(bounds.Width))
Expand All @@ -86,7 +91,7 @@ func (p *glPainter) newGlTextTexture(obj fyne.CanvasObject) Texture {

d := font.Drawer{}
d.Dst = img
d.Src = &image.Uniform{C: text.Color}
d.Src = &image.Uniform{C: color}
d.Face = face
d.Dot = freetype.Pt(0, height-face.Metrics().Descent.Ceil())
d.DrawString(text.Text)
Expand Down
8 changes: 7 additions & 1 deletion internal/painter/software/draw.go
Expand Up @@ -9,6 +9,7 @@ import (
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/internal"
"fyne.io/fyne/v2/internal/painter"
"fyne.io/fyne/v2/theme"

"github.com/goki/freetype"
"github.com/goki/freetype/truetype"
Expand Down Expand Up @@ -139,6 +140,11 @@ func drawText(c fyne.Canvas, text *canvas.Text, pos fyne.Position, base *image.N
height := internal.ScaleInt(c, bounds.Height)
txtImg := image.NewRGBA(image.Rect(0, 0, width, height))

color := text.Color
if color == nil {
color = theme.ForegroundColor()
}

var opts truetype.Options
fontSize := text.TextSize * c.Scale()
opts.Size = float64(fontSize)
Expand All @@ -147,7 +153,7 @@ func drawText(c fyne.Canvas, text *canvas.Text, pos fyne.Position, base *image.N

d := font.Drawer{}
d.Dst = txtImg
d.Src = &image.Uniform{C: text.Color}
d.Src = &image.Uniform{C: color}
d.Face = face
d.Dot = freetype.Pt(0, height-face.Metrics().Descent.Ceil())
d.DrawString(text.Text)
Expand Down
1 change: 1 addition & 0 deletions widget/form.go
Expand Up @@ -111,6 +111,7 @@ func (f *Form) createInput(item *FormItem) fyne.CanvasObject {
func (f *Form) createLabel(text string) *canvas.Text {
return &canvas.Text{Text: text,
Alignment: fyne.TextAlignTrailing,
Color: theme.ForegroundColor(),
TextSize: theme.TextSize(),
TextStyle: fyne.TextStyle{Bold: true}}
}
Expand Down

0 comments on commit 66a51e1

Please sign in to comment.