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.
[sourcecode lang=”go”] // Linear Gradient
gradient2 := canvas.NewLinearGradient(
color.White, color.NRGBA{R: 255, G: 0, B: 0, A: 255}, 270)
// 45 degree angle

[/sourcecode] Here is the code for radial gradient.
[sourcecode lang=”go”] // Radial Gradient
gradient1 := canvas.NewRadialGradient(
color.White, color.NRGBA{R: 255, G: 0, B: 0, A: 255})
// 45 degree angle

[/sourcecode] Here is the code for horizontal gradient.
[sourcecode lang=”go”]

// Horizontal Gradient
gradient3 := canvas.NewHorizontalGradient(
color.White, color.NRGBA{R: 255, G: 0, B: 0, A: 255})
// 45 degree angle
[/sourcecode] Here is the code for vertical gradient.
[sourcecode lang=”go”]

// Vertical Gradient
gradient4 := canvas.NewVerticalGradient(
color.White, color.NRGBA{R: 255, G: 0, B: 0, A: 255})
// 45 degree angle

[/sourcecode] [sourcecode lang=”go” autolinks=”false” classname=”myclass” collapse=”false” firstline=”1″ gutter=”true” highlight=”1-3,6,9″ htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false” title=”Source Code main.go”] 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()
}

[/sourcecode] [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

 

Tony BB
 

TonyBB is a Coach , marketer, hypnotist and a founder of RSKVF Production who specializes in providing simple, affordable, and easy to use solutions for Life.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: