forked from adamk33n3r/GoBorderless
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui_defaults.go
More file actions
100 lines (91 loc) · 2.94 KB
/
gui_defaults.go
File metadata and controls
100 lines (91 loc) · 2.94 KB
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
package main
import (
"strconv"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
"github.com/adamk33n3r/GoBorderless/ui"
)
func buildDefaultsTab(settings *Settings) *fyne.Container {
defaultXOffsetLabel := widget.NewLabel("X Offset:")
defaultXOffset := widget.NewEntry()
defaultXOffset.Validator = intValidator
defaultXOffset.SetText(strconv.Itoa(int(settings.Defaults.OffsetX)))
defaultXOffset.OnChanged = func(s string) {
settings.Defaults.OffsetX = entryTextToInt(s)
settings.Save()
}
setOnFocusChanged(defaultXOffset, func(focused bool) {
if focused {
defaultXOffset.DoubleTapped(&fyne.PointEvent{})
}
})
defaultYOffsetLabel := widget.NewLabel("Y Offset:")
defaultYOffset := widget.NewEntry()
defaultYOffset.Validator = intValidator
defaultYOffset.SetText(strconv.Itoa(int(settings.Defaults.OffsetY)))
defaultYOffset.OnChanged = func(s string) {
settings.Defaults.OffsetY = entryTextToInt(s)
settings.Save()
}
setOnFocusChanged(defaultYOffset, func(focused bool) {
if focused {
defaultYOffset.DoubleTapped(&fyne.PointEvent{})
}
})
defaultWidthLabel := widget.NewLabel("Width:")
defaultWidth := widget.NewEntry()
defaultWidth.SetText(strconv.Itoa(int(settings.Defaults.Width)))
defaultWidth.Validator = intValidator
defaultWidth.OnChanged = func(s string) {
settings.Defaults.Width = entryTextToInt(s)
settings.Save()
}
setOnFocusChanged(defaultWidth, func(focused bool) {
if focused {
defaultWidth.DoubleTapped(&fyne.PointEvent{})
}
})
defaultHeightLabel := widget.NewLabel("Height:")
defaultHeight := widget.NewEntry()
defaultHeight.Validator = intValidator
defaultHeight.SetText(strconv.Itoa(int(settings.Defaults.Height)))
defaultHeight.OnChanged = func(s string) {
settings.Defaults.Height = entryTextToInt(s)
settings.Save()
}
setOnFocusChanged(defaultHeight, func(focused bool) {
if focused {
defaultHeight.DoubleTapped(&fyne.PointEvent{})
}
})
defaultDisplay := ui.NewSelect(monitors, func(selected Monitor) {
settings.Defaults.Monitor = selected.number
settings.Save()
})
defaultDisplay.SetSelectedIndex(settings.Defaults.Monitor - 1)
defaultMatchTypeLabel := widget.NewLabel("Match Type")
defaultMatchType := widget.NewRadioGroup(matchTypes, func(selected string) {
settings.Defaults.MatchType = GetMatchTypeFromString(selected)
settings.Save()
})
defaultMatchType.SetSelected(settings.Defaults.MatchType.String())
defaultMatchType.Horizontal = true
defaultMatchType.Required = true
defaultsGrid := container.NewGridWithRows(2,
container.NewGridWithColumns(2,
container.NewVBox(defaultXOffsetLabel, defaultXOffset),
container.NewVBox(defaultYOffsetLabel, defaultYOffset),
),
container.NewGridWithColumns(2,
container.NewVBox(defaultWidthLabel, defaultWidth),
container.NewVBox(defaultHeightLabel, defaultHeight),
),
)
return container.NewPadded(container.NewVBox(
defaultDisplay,
defaultMatchTypeLabel,
defaultMatchType,
defaultsGrid,
))
}