Layout – Fyne GUI Golang tutorial 49
Layout – Fyne GUI Golang tutorial 49
Want to create fyne custom layout ?
Do You have a custom UI design?
Why not use container without layout
container.NewWithoutLayout()
It is very powerful layout.
Don’t forget to mention widget size
widget_name.Resize(fyne.NewSize(250, 30))
And widget position
widget_name.Move(fyne.NewPos(40, 150))
Source Code
package main // import fyne import ( "image/color" "fyne.io/fyne/v2" "fyne.io/fyne/v2/app" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/container" ) func main() { // New App a := app.New() // New title and window w := a.NewWindow("Layout = My FAV") // resize w.Resize(fyne.NewSize(400, 400)) //Rectangle Red_RECT := canvas.NewRectangle(color.RGBA{R: 255, G: 0, B: 0, A: 255}) // Size of Rectangle very important Red_RECT.Resize(fyne.NewSize(50, 50)) // 50x50 pixels // Position of rectangle on screen //Red_RECT.Move(fyne.NewPos(0, 0)) // (0,0) x axis & y axis is zero // I need rectangle at bottom // our canvas size is 400x400 // and rectangle size is 50x50 // 400-50 = 350 // 350 is bottom for our rectangle //Red_RECT.Move(fyne.NewPos(350, 350)) //I need my rectangle in center // so our calculation will be // 400-50= 350 // now for center divide by 2 // 350/2 = 175 // 175X175 Red_RECT.Move(fyne.NewPos(175, 175)) // Let setup content // we are going to use container without layout w.SetContent( container.NewWithoutLayout( Red_RECT, ), ) //show and run w.ShowAndRun() }
[easy_media_download url=”http://blogvali.com/wp-content/uploads/fyne-golang-downloads/main49.go” text=”Download Code” color=”red_darker”]