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

<div>
<div>widget_name.Resize(fyne.NewSize(250, 30))</div>
</div>

And widget position

<div>
<div>widget_name.Move(fyne.NewPos(40, 150))</div>
</div>

Source Code


package main
<div>
<div>// import fyne</div>
<div>import (</div>
<div>    "image/color"</div>
<div>    "fyne.io/fyne/v2"</div>
<div>    "fyne.io/fyne/v2/app"</div>
<div>    "fyne.io/fyne/v2/canvas"</div>
<div>    "fyne.io/fyne/v2/container"</div>
<div>)</div>
<div>func main() {</div>
<div>    // New App</div>
<div>    a := app.New()</div>
<div>    // New title and window</div>
<div>    w := a.NewWindow("Layout = My FAV")</div>
<div>    // resize</div>
<div>    w.Resize(fyne.NewSize(400, 400))</div>
<div>    //Rectangle</div>
<div>    Red_RECT := canvas.NewRectangle(color.RGBA{R: 255, G: 0, B: 0, A: 255})</div>
<div>    // Size of Rectangle very important</div>
<div>    Red_RECT.Resize(fyne.NewSize(50, 50)) // 50x50 pixels</div>
<div>    // Position of rectangle on screen</div>
<div>    //Red_RECT.Move(fyne.NewPos(0, 0))</div>
<div>    // (0,0) x axis &amp; y axis is zero</div>
<div>    // I need rectangle at bottom</div>
<div>    // our canvas size is 400x400</div>
<div>    // and rectangle size is 50x50</div>
<div>    // 400-50 = 350 // 350 is bottom for our rectangle</div>
<div>    //Red_RECT.Move(fyne.NewPos(350, 350))</div>
<div>    //I need my rectangle in center</div>
<div>    // so our calculation will be</div>
<div>    // 400-50= 350</div>
<div>    // now for center divide by 2</div>
<div>    // 350/2 = 175</div>
<div>    // 175X175</div>
<div>    Red_RECT.Move(fyne.NewPos(175, 175))</div>
<div>    // Let setup content</div>
<div>    // we are going to use container without layout</div>
<div>    w.SetContent(</div>
<div>        container.NewWithoutLayout(</div>
<div>            Red_RECT,</div>
<div>        ),</div>
<div>    )</div>
<div>    //show and run</div>
<div>    w.ShowAndRun()</div>
<div>}</div>
</div>

 

[easy_media_download url=”http://blogvali.com/wp-content/uploads/fyne-golang-downloads/main49.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: