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()
}

 

Download Code

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: