Form Layout

The layout.FormLayout is like a 2 column grid layout but tweaked for layout out forms in an application. The height of each item will be the larger of the two minimum heights in each row. The width of the left item will be the largest minimum width of all items in the first column whilst the second item in each row will expand to fill the space.

This layout is more typically used within the widget.Form but it can be used directly with layout.NewFormLayout() passed to the first parameter of fyne.NewContainerWithLayout(...).

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
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("Form Layout")

	label1 := canvas.NewText("Label 1", color.Black)
	value1 := canvas.NewText("Value", color.White)
	label2 := canvas.NewText("Label 2", color.Black)
	value2 := canvas.NewText("Something", color.White)
	grid := fyne.NewContainerWithLayout(layout.NewFormLayout(),
		label1, value1, label2, value2)
	myWindow.SetContent(grid)
	myWindow.ShowAndRun()
}