/
window.go
71 lines (62 loc) · 2.02 KB
/
window.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
package tutorials
import (
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
)
func windowScreen(_ fyne.Window) fyne.CanvasObject {
windowGroup := container.NewVBox(
widget.NewButton("New window", func() {
w := fyne.CurrentApp().NewWindow("Hello")
w.SetContent(widget.NewLabel("Hello World!"))
w.Show()
}),
widget.NewButton("Fixed size window", func() {
w := fyne.CurrentApp().NewWindow("Fixed")
w.SetContent(fyne.NewContainerWithLayout(layout.NewCenterLayout(), widget.NewLabel("Hello World!")))
w.Resize(fyne.NewSize(240, 180))
w.SetFixedSize(true)
w.Show()
}),
widget.NewButton("Toggle between fixed/not fixed window size", func() {
w := fyne.CurrentApp().NewWindow("Toggle fixed size")
w.SetContent(fyne.NewContainerWithLayout(layout.NewCenterLayout(), widget.NewCheck("Fixed size", func(toggle bool) {
if toggle {
w.Resize(fyne.NewSize(240, 180))
}
w.SetFixedSize(toggle)
})))
w.Show()
}),
widget.NewButton("Centered window", func() {
w := fyne.CurrentApp().NewWindow("Central")
w.SetContent(fyne.NewContainerWithLayout(layout.NewCenterLayout(), widget.NewLabel("Hello World!")))
w.CenterOnScreen()
w.Show()
}))
drv := fyne.CurrentApp().Driver()
if drv, ok := drv.(desktop.Driver); ok {
windowGroup.Objects = append(windowGroup.Objects,
widget.NewButton("Splash Window (only use on start)", func() {
w := drv.CreateSplashWindow()
w.SetContent(widget.NewLabelWithStyle("Hello World!\n\nMake a splash!",
fyne.TextAlignCenter, fyne.TextStyle{Bold: true}))
w.Show()
go func() {
time.Sleep(time.Second * 3)
w.Close()
}()
}))
}
otherGroup := widget.NewCard("Other", "",
widget.NewButton("Notification", func() {
fyne.CurrentApp().SendNotification(&fyne.Notification{
Title: "Fyne Demo",
Content: "Testing notifications...",
})
}))
return container.NewVBox(widget.NewCard("Windows", "", windowGroup), otherGroup)
}