-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathmain.go
72 lines (63 loc) · 1.83 KB
/
main.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
//go:generate fyne bundle -o data.go Icon.png
package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/fyne-io/examples/bugs"
"github.com/fyne-io/examples/clock"
"github.com/fyne-io/examples/fractal"
"github.com/fyne-io/examples/img/icon"
"github.com/fyne-io/examples/tictactoe"
"github.com/fyne-io/examples/xkcd"
)
type appInfo struct {
name string
icon fyne.Resource
canv bool
run func(fyne.Window) fyne.CanvasObject
}
var apps = []appInfo{
{"Bugs", icon.BugBitmap, false, bugs.Show},
{"XKCD", icon.XKCDBitmap, false, xkcd.Show},
{"Clock", icon.ClockBitmap, true, clock.Show},
{"Fractal", icon.FractalBitmap, true, fractal.Show},
{"Tic Tac Toe", nil, true, tictactoe.Show},
}
func main() {
a := app.New()
a.SetIcon(resourceIconPng)
content := container.NewMax()
w := a.NewWindow("Examples")
apps[4].icon = theme.RadioButtonIcon() // lazy load Fyne resource to avoid error
appList := widget.NewList(
func() int {
return len(apps)
},
func() fyne.CanvasObject {
icon := &canvas.Image{}
label := widget.NewLabel("Text Editor")
labelHeight := label.MinSize().Height
icon.SetMinSize(fyne.NewSize(labelHeight, labelHeight))
return container.NewBorder(nil, nil, icon, nil,
label)
},
func(id widget.ListItemID, obj fyne.CanvasObject) {
img := obj.(*fyne.Container).Objects[1].(*canvas.Image)
text := obj.(*fyne.Container).Objects[0].(*widget.Label)
img.Resource = apps[id].icon
img.Refresh()
text.SetText(apps[id].name)
})
appList.OnSelected = func(id widget.ListItemID) {
content.Objects = []fyne.CanvasObject{apps[id].run(w)}
}
split := container.NewHSplit(appList, content)
split.Offset = 0.1
w.SetContent(split)
w.Resize(fyne.NewSize(480, 360))
w.ShowAndRun()
}