-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
widget.go
159 lines (138 loc) · 4.51 KB
/
widget.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
155
156
157
158
159
package screens
import (
"fmt"
"time"
"fyne.io/fyne"
"fyne.io/fyne/canvas"
"fyne.io/fyne/layout"
"fyne.io/fyne/theme"
"fyne.io/fyne/widget"
)
func makeButtonTab() fyne.Widget {
disabled := widget.NewButton("Disabled", func() {})
disabled.Disable()
return widget.NewVBox(
widget.NewLabel("Text label"),
widget.NewButton("Text button", func() { fmt.Println("tapped text button") }),
widget.NewButtonWithIcon("With icon", theme.ConfirmIcon(), func() { fmt.Println("tapped icon button") }),
disabled,
)
}
func makeInputTab() fyne.Widget {
entry := widget.NewEntry()
entry.SetPlaceHolder("Entry")
entryReadOnly := widget.NewEntry()
entryReadOnly.SetText("Entry (disabled)")
entryReadOnly.Disable()
disabledCheck := widget.NewCheck("Disabled check", func(bool) {})
disabledCheck.Disable()
radio := widget.NewRadio([]string{"Radio Item 1", "Radio Item 2"}, func(s string) { fmt.Println("selected", s) })
radio.Horizontal = true
disabledRadio := widget.NewRadio([]string{"Disabled radio"}, func(string) {})
disabledRadio.Disable()
return widget.NewVBox(
entry,
entryReadOnly,
widget.NewSelect([]string{"Option 1", "Option 2", "Option 3"}, func(s string) { fmt.Println("selected", s) }),
widget.NewCheck("Check", func(on bool) { fmt.Println("checked", on) }),
disabledCheck,
radio,
disabledRadio,
widget.NewSlider(0, 100),
)
}
func makeProgressTab() fyne.Widget {
progress := widget.NewProgressBar()
infProgress := widget.NewProgressBarInfinite()
go func() {
num := 0.0
for num < 1.0 {
time.Sleep(100 * time.Millisecond)
progress.SetValue(num)
num += 0.01
}
progress.SetValue(1)
}()
return widget.NewVBox(
widget.NewLabel("Percent"), progress,
widget.NewLabel("Infinite"), infProgress)
}
func makeFormTab() fyne.Widget {
name := widget.NewEntry()
name.SetPlaceHolder("John Smith")
email := widget.NewEntry()
email.SetPlaceHolder("test@example.com")
password := widget.NewPasswordEntry()
password.SetPlaceHolder("Password")
largeText := widget.NewMultiLineEntry()
age := widget.NewIntegralSpinner(0, 100, 1)
weight := widget.NewSpinner(0.0, 100.0, 0.25)
form := &widget.Form{
OnCancel: func() {
fmt.Println("Cancelled")
},
OnSubmit: func() {
fmt.Println("Form submitted")
fmt.Println("Name:", name.Text)
fmt.Println("Email:", email.Text)
fmt.Println("Password:", password.Text)
fmt.Println("Message:", largeText.Text)
fmt.Println("Age:", age.GetValue())
fmt.Println("Weight:", weight.GetValue())
},
}
form.Append("Name", name)
form.Append("Email", email)
form.Append("Password", password)
form.Append("Message", largeText)
form.Append("Age", age)
form.Append("Weight", weight)
return form
}
func makeScrollTab() fyne.CanvasObject {
logo := canvas.NewImageFromResource(theme.FyneLogo())
logo.SetMinSize(fyne.NewSize(320, 320))
list := widget.NewHBox()
list2 := widget.NewVBox()
for i := 1; i <= 20; i++ {
index := i // capture
list.Append(widget.NewButton(fmt.Sprintf("Button %d", index), func() {
fmt.Println("Tapped", index)
}))
list2.Append(widget.NewButton(fmt.Sprintf("Button %d", index), func() {
fmt.Println("Tapped", index)
}))
}
horiz := widget.NewScrollContainer(list)
vert := widget.NewScrollContainer(list2)
scrolls := fyne.NewContainerWithLayout(layout.NewBorderLayout(horiz, nil, nil, nil),
horiz, vert)
return fyne.NewContainerWithLayout(layout.NewAdaptiveGridLayout(2), scrolls, makeScrollBothTab())
}
func makeScrollBothTab() fyne.CanvasObject {
logo := canvas.NewImageFromResource(theme.FyneLogo())
logo.SetMinSize(fyne.NewSize(800, 800))
scroll := widget.NewScrollContainer(logo)
scroll.Resize(fyne.NewSize(400, 400))
return scroll
}
// WidgetScreen shows a panel containing widget demos
func WidgetScreen() fyne.CanvasObject {
toolbar := widget.NewToolbar(widget.NewToolbarAction(theme.MailComposeIcon(), func() { fmt.Println("New") }),
widget.NewToolbarSeparator(),
widget.NewToolbarSpacer(),
widget.NewToolbarAction(theme.ContentCutIcon(), func() { fmt.Println("Cut") }),
widget.NewToolbarAction(theme.ContentCopyIcon(), func() { fmt.Println("Copy") }),
widget.NewToolbarAction(theme.ContentPasteIcon(), func() { fmt.Println("Paste") }),
)
return fyne.NewContainerWithLayout(layout.NewBorderLayout(toolbar, nil, nil, nil),
toolbar,
widget.NewTabContainer(
widget.NewTabItem("Buttons", makeButtonTab()),
widget.NewTabItem("Input", makeInputTab()),
widget.NewTabItem("Progress", makeProgressTab()),
widget.NewTabItem("Form", makeFormTab()),
widget.NewTabItem("Scroll", makeScrollTab()),
),
)
}