/
widget.go
137 lines (118 loc) · 3.7 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
package main
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.SetPlaceHolder("Entry (read only)")
entryReadOnly.ReadOnly = true
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,
)
}
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()
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)
},
}
form.Append("Name", name)
form.Append("Email", email)
form.Append("Password", password)
form.Append("Message", largeText)
return form
}
func makeScrollTab() fyne.Widget {
logo := canvas.NewImageFromResource(theme.FyneLogo())
logo.SetMinSize(fyne.NewSize(320, 320))
list := 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)
}))
}
scroll := widget.NewScrollContainer(list)
scroll.Resize(fyne.NewSize(200, 200))
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()),
),
)
}