forked from fyne-io/fyne
/
layout.go
76 lines (61 loc) · 1.81 KB
/
layout.go
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"image/color"
"fyne.io/fyne"
"fyne.io/fyne/canvas"
"fyne.io/fyne/layout"
"fyne.io/fyne/widget"
)
func makeCell() fyne.CanvasObject {
rect := canvas.NewRectangle(&color.RGBA{128, 128, 128, 255})
rect.SetMinSize(fyne.NewSize(30, 30))
return rect
}
func makeBorderLayout() *fyne.Container {
top := makeCell()
bottom := makeCell()
left := makeCell()
right := makeCell()
middle := widget.NewLabelWithStyle("BorderLayout", fyne.TextAlignCenter, fyne.TextStyle{})
borderLayout := layout.NewBorderLayout(top, bottom, left, right)
return fyne.NewContainerWithLayout(borderLayout,
top, bottom, left, right, middle)
}
func makeBoxLayout() *fyne.Container {
top := makeCell()
bottom := makeCell()
middle := widget.NewLabel("BoxLayout")
center := makeCell()
right := makeCell()
col := fyne.NewContainerWithLayout(layout.NewVBoxLayout(),
top, middle, bottom)
return fyne.NewContainerWithLayout(layout.NewHBoxLayout(),
col, center, right)
}
func makeFixedGridLayout() *fyne.Container {
box1 := makeCell()
box2 := widget.NewLabel("FixedGrid")
box3 := makeCell()
box4 := makeCell()
return fyne.NewContainerWithLayout(layout.NewFixedGridLayout(fyne.NewSize(75, 75)),
box1, box2, box3, box4)
}
func makeGridLayout() *fyne.Container {
box1 := makeCell()
box2 := widget.NewLabel("Grid")
box3 := makeCell()
box4 := makeCell()
return fyne.NewContainerWithLayout(layout.NewGridLayout(2),
box1, box2, box3, box4)
}
// Layout loads a window that shows the layouts available for a container
func Layout(app fyne.App) {
w := app.NewWindow("Layout")
w.SetContent(widget.NewTabContainer(
widget.NewTabItem("Border", makeBorderLayout()),
widget.NewTabItem("Box", makeBoxLayout()),
widget.NewTabItem("Fixed Grid", makeFixedGridLayout()),
widget.NewTabItem("Grid", makeGridLayout()),
))
w.Show()
}