-
Notifications
You must be signed in to change notification settings - Fork 0
/
DefaultWidgetSetup.go
189 lines (174 loc) · 6.2 KB
/
DefaultWidgetSetup.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package DefaultWidgets
import (
"go.novellaforge.dev/novellaforge/pkg/NFData/NFObjects/NFWidget"
"log"
"fyne.io/fyne/v2"
"go.novellaforge.dev/novellaforge/pkg/NFData"
)
// Import is an empty function, created to allow the inclusion of this package in other parts of the code,
// even if none of its functions are directly used.
// This ensures that the init function is executed without triggering warnings about unused imports.
//
// While it's possible to import a package for its side effects by changing its alias to _,
// using the Import function provides the added benefit of retaining direct access to the package's contents.
func Import() {}
// This init() registers the default layouts to be used within the game
// In go the init function is called when the package is imported, but in order
// to avoid unused import warnings, you can call the empty Import() function, which does nothing
func init() {
Import()
log.Println("Registering Default Widgets")
//Null Widget for a placeholder widget
null := NFWidget.Widget{
Type: "Null",
RequiredArgs: NFData.NewNFInterfaceMap(),
OptionalArgs: NFData.NewNFInterfaceMap(),
}
null.Register(func(window fyne.Window, args *NFData.NFInterfaceMap, widget *NFWidget.Widget) (fyne.CanvasObject, error) {
return nil, nil
})
// VBoxContainerHandler
vbox := NFWidget.Widget{
Type: "VBoxContainer",
RequiredArgs: NFData.NewNFInterfaceMap(),
OptionalArgs: NFData.NewNFInterfaceMap(
NFData.NewKeyVal("Size", fyne.NewSize(0, 0)),
NFData.NewKeyVal("Position", fyne.NewPos(0, 0)),
NFData.NewKeyVal("Hidden", false),
),
}
vbox.Register(VBoxContainerHandler)
// HBoxContainerHandler
hbox := NFWidget.Widget{
Type: "HBoxContainer",
RequiredArgs: NFData.NewNFInterfaceMap(),
OptionalArgs: NFData.NewNFInterfaceMap(
NFData.NewKeyVal("Size", fyne.NewSize(0, 0)),
NFData.NewKeyVal("Position", fyne.NewPos(0, 0)),
NFData.NewKeyVal("Hidden", false),
),
}
hbox.Register(HBoxContainerHandler)
// FormHandler
form := NFWidget.Widget{
Type: "Form",
RequiredArgs: NFData.NewNFInterfaceMap(),
OptionalArgs: NFData.NewNFInterfaceMap(
NFData.NewKeyVal("Size", fyne.NewSize(0, 0)),
NFData.NewKeyVal("Position", fyne.NewPos(0, 0)),
NFData.NewKeyVal("Hidden", false),
NFData.NewKeyVal("SubmitText", ""),
NFData.NewKeyVal("CancelText", ""),
NFData.NewKeyVal("OnSubmitted", ""),
NFData.NewKeyVal("OnSubmittedArgs", NFData.NewNFInterfaceMap()),
NFData.NewKeyVal("OnCancelled", ""),
NFData.NewKeyVal("OnCancelledArgs", NFData.NewNFInterfaceMap()),
NFData.NewKeyVal("Enabled", true),
),
}
form.Register(FormHandler)
// LabelHandler
label := NFWidget.Widget{
Type: "Label",
RequiredArgs: NFData.NewNFInterfaceMap(NFData.NewKeyVal("Text", "")),
OptionalArgs: NFData.NewNFInterfaceMap(),
}
label.Register(LabelHandler)
// ButtonHandler
button := NFWidget.Widget{
Type: "Button",
RequiredArgs: NFData.NewNFInterfaceMap(),
OptionalArgs: NFData.NewNFInterfaceMap(
NFData.NewKeyVal("Text", ""),
NFData.NewKeyVal("Icon", ""),
NFData.NewKeyVal("OnTapped", ""),
NFData.NewKeyVal("OnTappedArgs", NFData.NewNFInterfaceMap()),
NFData.NewKeyVal("Hidden", false),
NFData.NewKeyVal("Position", fyne.NewPos(0, 0)),
NFData.NewKeyVal("Size", fyne.NewSize(0, 0)),
NFData.NewKeyVal("Enabled", true),
),
}
button.Register(ButtonHandler)
// ImageHandler
image := NFWidget.Widget{
Type: "Image",
RequiredArgs: NFData.NewNFInterfaceMap(NFData.NewKeyVal("Path", "")),
OptionalArgs: NFData.NewNFInterfaceMap(
NFData.NewKeyVal("Hidden", false),
NFData.NewKeyVal("Position", fyne.NewPos(0, 0)),
NFData.NewKeyVal("MinSize", fyne.NewSize(1080, 720)),
),
}
image.Register(ImageHandler)
// ToolBarHandler
toolbar := NFWidget.Widget{
Type: "ToolBar",
RequiredArgs: NFData.NewNFInterfaceMap(),
OptionalArgs: NFData.NewNFInterfaceMap(
NFData.NewKeyVal("Size", fyne.NewSize(0, 0)),
NFData.NewKeyVal("Position", fyne.NewPos(0, 0)),
NFData.NewKeyVal("Hidden", false),
),
}
toolbar.Register(ToolBarHandler)
// EntryHandler
entry := NFWidget.Widget{
Type: "Entry",
RequiredArgs: NFData.NewNFInterfaceMap(),
OptionalArgs: NFData.NewNFInterfaceMap(
NFData.NewKeyVal("PlaceHolder", ""),
NFData.NewKeyVal("Text", ""),
NFData.NewKeyVal("OnChanged", ""),
NFData.NewKeyVal("OnChangedArgs", NFData.NewNFInterfaceMap()),
NFData.NewKeyVal("OnSubmitted", ""),
NFData.NewKeyVal("OnSubmittedArgs", NFData.NewNFInterfaceMap()),
NFData.NewKeyVal("OnCursorChanged", ""),
NFData.NewKeyVal("OnCursorChangedArgs", NFData.NewNFInterfaceMap()),
NFData.NewKeyVal("Hidden", false),
NFData.NewKeyVal("Position", fyne.NewPos(0, 0)),
NFData.NewKeyVal("Size", fyne.NewSize(0, 0)),
NFData.NewKeyVal("Enabled", true),
),
}
entry.Register(EntryHandler)
// PasswordEntryHandler
passwordEntry := NFWidget.Widget{
Type: "PasswordEntry",
RequiredArgs: NFData.NewNFInterfaceMap(),
OptionalArgs: NFData.NewNFInterfaceMap(
NFData.NewKeyVal("PlaceHolder", ""),
NFData.NewKeyVal("Text", ""),
NFData.NewKeyVal("OnChanged", ""),
NFData.NewKeyVal("OnChangedArgs", NFData.NewNFInterfaceMap()),
NFData.NewKeyVal("OnSubmitted", ""),
NFData.NewKeyVal("OnSubmittedArgs", NFData.NewNFInterfaceMap()),
NFData.NewKeyVal("OnCursorChanged", ""),
NFData.NewKeyVal("OnCursorChangedArgs", NFData.NewNFInterfaceMap()),
NFData.NewKeyVal("Hidden", false),
NFData.NewKeyVal("Position", fyne.NewPos(0, 0)),
NFData.NewKeyVal("Size", fyne.NewSize(0, 0)),
NFData.NewKeyVal("Enabled", true),
),
}
passwordEntry.Register(PasswordEntryHandler)
// SliderHandler
slider := NFWidget.Widget{
Type: "Slider",
RequiredArgs: NFData.NewNFInterfaceMap(
NFData.NewKeyVal("Min", 0.0),
NFData.NewKeyVal("Max", 1.0),
),
OptionalArgs: NFData.NewNFInterfaceMap(
NFData.NewKeyVal("Value", 0.0),
NFData.NewKeyVal("Step", 0.1),
NFData.NewKeyVal("OnChanged", ""),
NFData.NewKeyVal("OnChangedArgs", NFData.NewNFInterfaceMap()),
NFData.NewKeyVal("Hidden", false),
NFData.NewKeyVal("Position", fyne.NewPos(0, 0)),
NFData.NewKeyVal("Size", fyne.NewSize(0, 0)),
NFData.NewKeyVal("Enabled", true),
),
}
slider.Register(SliderHandler)
}