Fixed Grid Layout

like the previous grid layout, the fixed grid creates an arrangement of elements in a grid pattern. However this grid does not have a set number of columns, instead it uses a fixed size for each cell and then flows the content to as many rows as is needed to display the items.

You create a fixed grid layout using layout.NewFixedGridLayout(size) where size specifies the size to apply to all child elements. This layout is then passed as the first parameter to fyne.NewContainerWithLayout(...). The number of columns and rows will be calculated based on the current size of the container.

Initially a fixed grid will have a single column, if you resize it (as illustrated in the code comment to the right) it will rearrange the child elements to fill the space.

Example Code

            
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package main

import (
	"image/color"

	"fyne.io/fyne"
	"fyne.io/fyne/app"
	"fyne.io/fyne/canvas"
	"fyne.io/fyne/layout"
)

func main() {
	myApp := app.New()
	myWindow := myApp.NewWindow("Fixed Grid Layout")

	text1 := canvas.NewText("1", color.White)
	text2 := canvas.NewText("2", color.White)
	text3 := canvas.NewText("3", color.White)
	grid := fyne.NewContainerWithLayout(layout.NewFixedGridLayout(fyne.NewSize(50, 50)),
		text1, text2, text3)
	myWindow.SetContent(grid)

	//	myWindow.Resize(fyne.NewSize(180, 75))
	myWindow.ShowAndRun()
}