forked from fyne-io/fyne
/
icons.go
121 lines (98 loc) · 3.26 KB
/
icons.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
package main
import (
"image/color"
"fyne.io/fyne"
"fyne.io/fyne/canvas"
"fyne.io/fyne/layout"
"fyne.io/fyne/theme"
"fyne.io/fyne/widget"
)
type browser struct {
canvas fyne.Canvas
current int
name *widget.Label
icon *widget.Icon
}
func (b *browser) setIcon(index int) {
if index < 0 || index > len(icons)-1 {
return
}
b.current = index
b.name.SetText(icons[index].name)
b.icon.SetResource(icons[index].icon)
}
// Icons loads a window that shows the various icons available in Fyne
func Icons(app fyne.App) {
win := app.NewWindow("Icons")
b := &browser{canvas: win.Canvas()}
prev := widget.NewButtonWithIcon("", theme.NavigateBackIcon(), func() {
b.setIcon(b.current - 1)
})
next := widget.NewButtonWithIcon("", theme.NavigateNextIcon(), func() {
b.setIcon(b.current + 1)
})
b.name = widget.NewLabel(icons[b.current].name)
bar := widget.NewHBox(prev, next, b.name)
background := canvas.NewRasterWithPixels(checkerPattern)
background.SetMinSize(fyne.NewSize(280, 280))
b.icon = widget.NewIcon(icons[b.current].icon)
win.SetContent(fyne.NewContainerWithLayout(layout.NewBorderLayout(
bar, nil, nil, nil), bar, background, b.icon))
win.Show()
}
func checkerPattern(x, y, _, _ int) color.Color {
x /= 20
y /= 20
if x%2 == y%2 {
return theme.BackgroundColor()
}
return theme.ButtonColor()
}
var icons = []struct {
name string
icon fyne.Resource
}{
{"CancelIcon", theme.CancelIcon()},
{"ConfirmIcon", theme.ConfirmIcon()},
{"DeleteIcon", theme.DeleteIcon()},
{"SearchIcon", theme.SearchIcon()},
{"SearchReplaceIcon", theme.SearchReplaceIcon()},
{"CheckButtonIcon", theme.CheckButtonIcon()},
{"CheckButtonCheckedIcon", theme.CheckButtonCheckedIcon()},
{"RadioButtonIcon", theme.RadioButtonIcon()},
{"RadioButtonCheckedIcon", theme.RadioButtonCheckedIcon()},
{"ContentAddIcon", theme.ContentAddIcon()},
{"ContentRemoveIcon", theme.ContentRemoveIcon()},
{"ContentClearIcon", theme.ContentClearIcon()},
{"ContentCutIcon", theme.ContentCutIcon()},
{"ContentCopyIcon", theme.ContentCopyIcon()},
{"ContentPasteIcon", theme.ContentPasteIcon()},
{"ContentRedoIcon", theme.ContentRedoIcon()},
{"ContentUndoIcon", theme.ContentUndoIcon()},
{"InfoIcon", theme.InfoIcon()},
{"QuestionIcon", theme.QuestionIcon()},
{"WarningIcon", theme.WarningIcon()},
{"DocumentCreateIcon", theme.DocumentCreateIcon()},
{"DocumentPrintIcon", theme.DocumentPrintIcon()},
{"DocumentSaveIcon", theme.DocumentSaveIcon()},
{"FolderIcon", theme.FolderIcon()},
{"FolderNewIcon", theme.FolderNewIcon()},
{"FolderOpenIcon", theme.FolderOpenIcon()},
{"HomeIcon", theme.HomeIcon()},
{"HelpIcon", theme.HelpIcon()},
{"ViewFullScreenIcon", theme.ViewFullScreenIcon()},
{"ViewRestoreIcon", theme.ViewRestoreIcon()},
{"ZoomFitIcon", theme.ZoomFitIcon()},
{"ZoomInIcon", theme.ZoomInIcon()},
{"ZoomOutIcon", theme.ZoomOutIcon()},
{"MoveDownIcon", theme.MoveDownIcon()},
{"MoveUpIcon", theme.MoveUpIcon()},
{"NavigateBackIcon", theme.NavigateBackIcon()},
{"NavigateNextIcon", theme.NavigateNextIcon()},
{"MailAttachmentIcon", theme.MailAttachmentIcon()},
{"MailComposeIcon", theme.MailComposeIcon()},
{"MailForwardIcon", theme.MailForwardIcon()},
{"MailReplyIcon", theme.MailReplyIcon()},
{"MailReplyAllIcon", theme.MailReplyAllIcon()},
{"MailSendIcon", theme.MailSendIcon()},
}