forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container.go
154 lines (129 loc) · 4.57 KB
/
container.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package tutorials
import (
"fmt"
"image/color"
"strconv"
"github.com/gorustyt/fyne/v2"
"github.com/gorustyt/fyne/v2/canvas"
"github.com/gorustyt/fyne/v2/cmd/fyne_demo/data"
"github.com/gorustyt/fyne/v2/container"
"github.com/gorustyt/fyne/v2/widget"
)
// containerScreen loads a tab panel for containers
func containerScreen(_ fyne.Window) fyne.CanvasObject {
content := container.NewBorder(
widget.NewLabelWithStyle("Top", fyne.TextAlignCenter, fyne.TextStyle{}),
widget.NewLabelWithStyle("Bottom", fyne.TextAlignCenter, fyne.TextStyle{}),
widget.NewLabel("Left"),
widget.NewLabel("Right"),
widget.NewLabel("Border Container"))
return container.NewCenter(content)
}
func makeAppTabsTab(_ fyne.Window) fyne.CanvasObject {
tabs := container.NewAppTabs(
container.NewTabItem("Tab 1", widget.NewLabel("Content of tab 1")),
container.NewTabItem("Tab 2 bigger", widget.NewLabel("Content of tab 2")),
container.NewTabItem("Tab 3", widget.NewLabel("Content of tab 3")),
)
for i := 4; i <= 12; i++ {
tabs.Append(container.NewTabItem(fmt.Sprintf("Tab %d", i), widget.NewLabel(fmt.Sprintf("Content of tab %d", i))))
}
locations := makeTabLocationSelect(tabs.SetTabLocation)
return container.NewBorder(locations, nil, nil, nil, tabs)
}
func makeBorderLayout(_ fyne.Window) fyne.CanvasObject {
top := makeCell()
bottom := makeCell()
left := makeCell()
right := makeCell()
middle := widget.NewLabelWithStyle("BorderLayout", fyne.TextAlignCenter, fyne.TextStyle{})
return container.NewBorder(top, bottom, left, right, middle)
}
func makeBoxLayout(_ fyne.Window) fyne.CanvasObject {
top := makeCell()
bottom := makeCell()
middle := widget.NewLabel("BoxLayout")
center := makeCell()
right := makeCell()
col := container.NewVBox(top, middle, bottom)
return container.NewHBox(col, center, right)
}
func makeButtonList(count int) []fyne.CanvasObject {
var items []fyne.CanvasObject
for i := 1; i <= count; i++ {
index := i // capture
items = append(items, widget.NewButton("Button "+strconv.Itoa(index), func() {
fmt.Println("Tapped", index)
}))
}
return items
}
func makeCell() fyne.CanvasObject {
rect := canvas.NewRectangle(&color.NRGBA{128, 128, 128, 255})
rect.SetMinSize(fyne.NewSize(30, 30))
return rect
}
func makeCenterLayout(_ fyne.Window) fyne.CanvasObject {
middle := widget.NewButton("CenterLayout", func() {})
return container.NewCenter(middle)
}
func makeDocTabsTab(_ fyne.Window) fyne.CanvasObject {
tabs := container.NewDocTabs(
container.NewTabItem("Doc 1", widget.NewLabel("Content of document 1")),
container.NewTabItem("Doc 2 bigger", widget.NewLabel("Content of document 2")),
container.NewTabItem("Doc 3", widget.NewLabel("Content of document 3")),
)
i := 3
tabs.CreateTab = func() *container.TabItem {
i++
return container.NewTabItem(fmt.Sprintf("Doc %d", i), widget.NewLabel(fmt.Sprintf("Content of document %d", i)))
}
locations := makeTabLocationSelect(tabs.SetTabLocation)
return container.NewBorder(locations, nil, nil, nil, tabs)
}
func makeGridLayout(_ fyne.Window) fyne.CanvasObject {
box1 := makeCell()
box2 := widget.NewLabel("Grid")
box3 := makeCell()
box4 := makeCell()
return container.NewGridWithColumns(2,
box1, box2, box3, box4)
}
func makeScrollTab(_ fyne.Window) fyne.CanvasObject {
hlist := makeButtonList(20)
vlist := makeButtonList(50)
horiz := container.NewHScroll(container.NewHBox(hlist...))
vert := container.NewVScroll(container.NewVBox(vlist...))
return container.NewAdaptiveGrid(2,
container.NewBorder(horiz, nil, nil, nil, vert),
makeScrollBothTab())
}
func makeScrollBothTab() fyne.CanvasObject {
logo := canvas.NewImageFromResource(data.FyneLogo)
logo.SetMinSize(fyne.NewSize(800, 800))
scroll := container.NewScroll(logo)
scroll.Resize(fyne.NewSize(400, 400))
return scroll
}
func makeSplitTab(_ fyne.Window) fyne.CanvasObject {
left := widget.NewMultiLineEntry()
left.Wrapping = fyne.TextWrapWord
left.SetText("Long text is looooooooooooooong")
right := container.NewVSplit(
widget.NewLabel("Label"),
widget.NewButton("Button", func() { fmt.Println("button tapped!") }),
)
return container.NewHSplit(container.NewVScroll(left), right)
}
func makeTabLocationSelect(callback func(container.TabLocation)) *widget.Select {
locations := widget.NewSelect([]string{"Top", "Bottom", "Leading", "Trailing"}, func(s string) {
callback(map[string]container.TabLocation{
"Top": container.TabLocationTop,
"Bottom": container.TabLocationBottom,
"Leading": container.TabLocationLeading,
"Trailing": container.TabLocationTrailing,
}[s])
})
locations.SetSelected("Top")
return locations
}