-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings_widget.go
66 lines (52 loc) · 1.49 KB
/
settings_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
package main
import (
"image/color"
"fyne.io/fyne/v2"
"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"
)
type SettingsWidget struct {
toggleButton *widget.Button
overlay *widget.PopUp
widget *fyne.Container
enabled bool
title string
}
func (sw *SettingsWidget) create(c fyne.Canvas, onDismiss func()) {
b := widget.NewButtonWithIcon("", theme.CancelIcon(), func() { sw.toggle() })
b.Move(fyne.NewPos(WindowWidth-theme.IconInlineSize(), 0))
// b.Resize(fyne.NewSize(theme.IconInlineSize(), theme.IconInlineSize()))
title := container.New(layout.NewCenterLayout(), canvas.NewText(sw.title, color.White))
con := container.New(layout.NewMaxLayout(), title, container.New(layout.NewHBoxLayout(), layout.NewSpacer(), b))
sw.widget = container.New(layout.NewVBoxLayout(), con, widget.NewSeparator())
sw.overlay = widget.NewModalPopUp(sw.widget, c)
}
func (sw *SettingsWidget) add(title string, content *fyne.Container, layoutType fyne.Layout, spacer bool) {
t := canvas.NewText(title, color.White)
con := container.New(layoutType)
con.Add(t)
if spacer {
con.Add(layout.NewSpacer())
}
con.Add(content)
sw.widget.Add(con)
}
func (sw *SettingsWidget) toggle() {
if sw.enabled {
sw.hide()
} else {
sw.show()
}
sw.enabled = !sw.enabled
}
func (sw *SettingsWidget) hide() {
sw.widget.Hide()
sw.overlay.Hide()
}
func (sw *SettingsWidget) show() {
sw.widget.Show()
sw.overlay.Show()
}