horizontal & vertical scroll example – Fyne GUI Golang tutorial 43

horizontal scroll vertical scroll – Fyne GUI Golang tutorial 43

Are you looking for fyne scroll example tutorial ? Here is example/tutorial with soruce code.
In this tutorial , We are going to discuss horizonal and vertical scroll in fyne.
Very simple and easy to use fyne golang example.

Fyne  Vertical scroll

You need to import container and then use NewVScroll for vertical scrolling.
</div>
<div>
<div>c := container.NewVScroll(</div>
<div>// your widgets goes here</div>
<div>)</div>
</div>
<div>
For more than one element you need to use NewHBox or NewVBox container.
</div>
<div>
<div>        container.NewHBox( // New Horizontal Box</div>
<div>            red, // for red Rectangle</div>
<div>            blue, // for blue Rectangle</div>
<div>        ),</div>
</div>
<div>

Fyne  Horizontal scroll

You need to import container and then use NewHScroll for horizontal scrolling.
</div>
<div>
<div>c := container.NewHScroll(</div>
<div>// your widgets goes here</div>
<div>)</div>
</div>
<div>
For more than one element you need to use NewHBox or NewVBox container.
</div>
<div>
<div>        container.NewVBox( // New Horizontal Box</div>
<div>            red, // for red Rectangle</div>
<div>            blue, // for blue Rectangle</div>
<div>        ),</div>
</div>
<div>

How to change fyne scroll direction

Change scroll direction
</div>
<div><span style="font-family: Consolas, Monaco, monospace;">     c.Direction = container.ScrollHorizontalOnly</span></div>
<div>

<div>
<div>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 windown and title</div>
<div>    w := a.NewWindow("Scroll")</div>
<div>    // resize</div>
<div>    w.Resize(fyne.NewSize(400, 400))</div>
<div>    // red rectangle</div>
<div>    red := canvas.NewRectangle(</div>
<div>        color.NRGBA{R: 255, G: 0, B: 0, A: 255})</div>
<div>    red.SetMinSize(fyne.NewSize(400, 400))</div>
<div>    // blue rectangle</div>
<div>    blue := canvas.NewRectangle(</div>
<div>        color.NRGBA{R: 0, G: 0, B: 255, A: 255})</div>
<div>    blue.SetMinSize(fyne.NewSize(400, 400))</div>
<div>    // New Scroll &amp; Vbox</div>
<div>    c := container.NewVScroll(</div>
<div>        container.NewHBox( // New Horizontal Box</div>
<div>            red,</div>
<div>            blue,</div>
<div>        ),</div>
<div>    )</div>
<div>    // Change scroll direction</div>
<div>    c.Direction = container.ScrollHorizontalOnly</div>
<div>    // setup content</div>
<div>    w.SetContent(c)</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/main41.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: