-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
80 lines (70 loc) · 1.95 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
73
74
75
76
77
78
79
80
//go:generate fyne bundle -o data.go data
package main
import (
"fmt"
"image/color"
"net/url"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
func makeUI(s *snow) fyne.CanvasObject {
merry := canvas.NewText("Merry Christmas", color.White)
merry.Alignment = fyne.TextAlignCenter
merry.TextSize = 42
to := widget.NewLabel("To all our customers, investors\nand the whole Fyne community")
to.Alignment = fyne.TextAlignCenter
texts := container.NewVBox(merry,
container.NewHBox(widget.NewLabel("From the Fyne Labs team"),
layout.NewSpacer(),
widget.NewButton("Sponsor", func() {
u, _ := url.Parse("https://fyne.io/sponsor/")
_ = fyne.CurrentApp().OpenURL(u)
})))
flake := newSnowFlake(2)
label := widget.NewLabel(fmt.Sprintf("%d", flake.Count))
down := widget.NewButtonWithIcon("", theme.MoveDownIcon(), func() {
if flake.Count <= 0 {
return
}
flake.Count--
label.SetText(fmt.Sprintf("%d", flake.Count))
flake.Refresh()
})
down.Importance = widget.LowImportance
up := widget.NewButtonWithIcon("", theme.MoveUpIcon(), func() {
if flake.Count >= 5 {
return
}
flake.Count++
label.SetText(fmt.Sprintf("%d", flake.Count))
flake.Refresh()
})
up.Importance = widget.LowImportance
start := widget.NewButton("Snow", func() {
s.snow()
})
start.Importance = widget.LowImportance
return container.NewBorder(to, texts, nil, nil, flake,
container.NewCenter(container.NewVBox(container.NewHBox(
down, label, up),
start)))
}
func main() {
a := app.New()
a.Settings().SetTheme(theme.FromLegacy(&cardTheme{}))
w := a.NewWindow("Snowflake")
s := newSnowLayer()
w.SetPadded(false)
s.bg = canvas.NewRectangle(&color.NRGBA{R: 0, G: 0, B: 0x4d, A: 0xff})
w.SetContent(container.NewMax(
s.bg,
container.NewPadded(container.NewPadded(makeUI(s))),
s))
w.Resize(fyne.NewSize(360, 520))
w.ShowAndRun()
}