Repository: fyne-io/fyne
File: canvas/gradient.go (Go)

Code before:
	return computeGradient(generator, iw, ih, g.StartColor, g.EndColor)
}

// Hide will set this gradient to not be visible
func (g *LinearGradient) Hide() {
	g.baseObject.Hide()

	repaint(g)
}

// Move the gradient to a new position, relative to its parent / canvas
func (g *LinearGradient) Move(pos fyne.Position) {
	g.baseObject.Move(pos)

	repaint(g)
}

func (g *LinearGradient) Resize(size fyne.Size) {
	if size == g.Size() {
		return
	}
	g.baseObject.Resize(size)

	g.Refresh()
}

// Refresh causes this gradient to be redrawn with its configured state.
func (g *LinearGradient) Refresh() {
	Refresh(g)
}

// RadialGradient defines a Gradient travelling radially from a center point outward.
type RadialGradient struct {
	baseObject

	StartColor color.Color // The beginning color of the gradient
	EndColor   color.Color // The end color of the gradient
	// The offset of the center for generation of the gradient.
	// This is not a DP measure but relates to the width/height.
	// A value of 0.5 would move the center by the half width/height.
	CenterOffsetX, CenterOffsetY float64
}

// Generate calculates an image of the gradient with the specified width and height.
func (g *RadialGradient) Generate(iw, ih int) image.Image {
	w, h := float64(iw), float64(ih)
	// define center plus offset
	centerX := w/2 + w*g.CenterOffsetX
	centerY := h/2 + h*g.CenterOffsetY

	// handle negative offsets

Review comment (suggestion):
I would just add a quick comment here (and in RadialGradient) saying that the reason a Refresh is needed is that the texture will need to be regenerated. It's not a common pattern to Refresh in a resize (but it makes total sense here), so let's make sure someone wouldn't remove it later thinking they're making an optimization

Code after:
	return computeGradient(generator, iw, ih, g.StartColor, g.EndColor)
}

// Hide will set this gradient to not be visible
func (g *LinearGradient) Hide() {
	g.baseObject.Hide()

	repaint(g)
}

// Move the gradient to a new position, relative to its parent / canvas
func (g *LinearGradient) Move(pos fyne.Position) {
	g.baseObject.Move(pos)

	repaint(g)
}

// Resize resizes the gradient to a new size.
func (g *LinearGradient) Resize(size fyne.Size) {
	if size == g.Size() {
		return
	}
	g.baseObject.Resize(size)

	// refresh needed to invalidate cached textures
	g.Refresh()
}

// Refresh causes this gradient to be redrawn with its configured state.
func (g *LinearGradient) Refresh() {
	Refresh(g)
}

// RadialGradient defines a Gradient travelling radially from a center point outward.
type RadialGradient struct {
	baseObject

	StartColor color.Color // The beginning color of the gradient
	EndColor   color.Color // The end color of the gradient
	// The offset of the center for generation of the gradient.
	// This is not a DP measure but relates to the width/height.
	// A value of 0.5 would move the center by the half width/height.
	CenterOffsetX, CenterOffsetY float64
}

// Generate calculates an image of the gradient with the specified width and height.
func (g *RadialGradient) Generate(iw, ih int) image.Image {
	w, h := float64(iw), float64(ih)
	// define center plus offset
	centerX := w/2 + w*g.CenterOffsetX
	centerY := h/2 + h*g.CenterOffsetY