Class 13 Fyne GoLang GUI Linear, Radial, Horizontal and Vertical Gradient
Want to color your widget. Here is an option in FYNE for gradients.
Gradient is simply 2 or more color combination which can beautify your design and UI.
Normally we use two most common gradients.
LINER AND HORIZONTAL
But you can use LINER gradient in two different ways.
HORIZONTALLY & VERTICALLY.
Remember we need to use 2 colors to create a gradient.
You need to specify both colors first.
Here is the code for linear gradient.
// Linear Gradient gradient2 := canvas.NewLinearGradient( color.White, color.NRGBA{R: 255, G: 0, B: 0, A: 255}, 270) // 45 degree angle
Here is the code for radial gradient.
// Radial Gradient gradient1 := canvas.NewRadialGradient( color.White, color.NRGBA{R: 255, G: 0, B: 0, A: 255}) // 45 degree angle
Here is the code for horizontal gradient.
// Horizontal Gradient gradient3 := canvas.NewHorizontalGradient( color.White, color.NRGBA{R: 255, G: 0, B: 0, A: 255}) // 45 degree angle
Here is the code for vertical gradient.
// Vertical Gradient gradient4 := canvas.NewVerticalGradient( color.White, color.NRGBA{R: 255, G: 0, B: 0, A: 255}) // 45 degree angle
package main // import Fyne import ( "image/color" "fyne.io/fyne/v2" "fyne.io/fyne/v2/app" "fyne.io/fyne/v2/canvas" ) func main() { // New App a := app.New() // New Window and Title w := a.NewWindow("Gradient : Canvas") w.Resize(fyne.NewSize(400, 400)) // Radial Gradient gradient1 := canvas.NewRadialGradient( color.White, color.NRGBA{R: 255, G: 0, B: 0, A: 255}) // 45 degree angle // Linear Gradient //gradient2 := canvas.NewLinearGradient( // color.White, color.NRGBA{R: 255, G: 0, B: 0, A: 255}, 270) // 45 degree angle // Horizontal Gradient //gradient3 := canvas.NewHorizontalGradient( // color.White, color.NRGBA{R: 255, G: 0, B: 0, A: 255}) // Vertical Gradient //gradient4 := canvas.NewVerticalGradient( // color.White, color.NRGBA{R: 255, G: 0, B: 0, A: 255}) // 45 degree angle // setup content w.SetContent(gradient1) w.ShowAndRun() }[easy_media_download url=”http://blogvali.com/wp-content/uploads/fyne-golang-downloads/main13.go” text=”Download Code” color=”red_darker”]
Fyne GoLang GUI Course