Skip to content

Commit

Permalink
Avoid possible re-draw requests when our content has not changed
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Jul 4, 2023
1 parent f73816f commit 56db81e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions widget/textgrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ type textGridRenderer struct {

cellSize fyne.Size
objects []fyne.CanvasObject
current fyne.Canvas
}

func (t *textGridRenderer) appendTextCell(str rune) {
Expand Down Expand Up @@ -369,9 +370,12 @@ func (t *textGridRenderer) setCellRune(str rune, pos int, style, rowStyle TextGr
} else if rowStyle != nil && rowStyle.TextColor() != nil {
fg = rowStyle.TextColor()
}
text.Text = string(str)
text.Color = fg
canvas.Refresh(text)
newStr := string(str)
if text.Text != newStr || text.Color != fg {
text.Text = newStr
text.Color = fg
canvas.Refresh(text)
}

rect := t.objects[pos*2].(*canvas.Rectangle)
bg := color.Color(color.Transparent)
Expand All @@ -380,8 +384,10 @@ func (t *textGridRenderer) setCellRune(str rune, pos int, style, rowStyle TextGr
} else if rowStyle != nil && rowStyle.BackgroundColor() != nil {
bg = rowStyle.BackgroundColor()
}
rect.FillColor = bg
canvas.Refresh(rect)
if rect.FillColor != bg {
rect.FillColor = bg
canvas.Refresh(rect)
}
}

func (t *textGridRenderer) addCellsIfRequired() {
Expand Down

0 comments on commit 56db81e

Please sign in to comment.