-
Notifications
You must be signed in to change notification settings - Fork 1
/
Window.go
362 lines (308 loc) · 8.95 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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
package demo
import (
"fmt"
"strings"
"github.com/AllenDang/cimgui-go"
)
type windowFlags struct {
noTitlebar bool
noScrollbar bool
noMenu bool
noMove bool
noResize bool
noCollapse bool
noNav bool
noBackground bool
noBringToFront bool
}
func (f windowFlags) combined() imgui.WindowFlags {
var flags imgui.WindowFlags = imgui.WindowFlagsNone
if f.noTitlebar {
flags |= imgui.WindowFlagsNoTitleBar
}
if f.noScrollbar {
flags |= imgui.WindowFlagsNoScrollbar
}
if !f.noMenu {
flags |= imgui.WindowFlagsMenuBar
}
if f.noMove {
flags |= imgui.WindowFlagsNoMove
}
if f.noResize {
flags |= imgui.WindowFlagsNoResize
}
if f.noCollapse {
flags |= imgui.WindowFlagsNoCollapse
}
if f.noNav {
flags |= imgui.WindowFlagsNoNav
}
if f.noBackground {
flags |= imgui.WindowFlagsNoBackground
}
if f.noBringToFront {
flags |= imgui.WindowFlagsNoBringToFrontOnFocus
}
return flags
}
var window = struct {
flags windowFlags
noClose bool
widgets widgets
layout layout
popups popups
columns columns
tables tables
misc misc
}{}
func bulletText(text string) {
imgui.Bullet()
imgui.Text(text)
}
// Show demonstrates most ImGui features that were ported to Go.
// This function tries to recreate the original demo window as closely as possible.
//
// In theory, if both windows would provide the identical functionality, then the wrapper would be complete.
func Show(keepOpen *bool) {
imgui.SetNextWindowPosV(imgui.Vec2{X: 650, Y: 20}, imgui.CondFirstUseEver, imgui.Vec2{})
imgui.SetNextWindowSizeV(imgui.Vec2{X: 550, Y: 680}, imgui.CondFirstUseEver)
if window.noClose {
keepOpen = nil
}
if !imgui.BeginV("ImGui-Go Demo", keepOpen, window.flags.combined()) {
// Early out if the window is collapsed, as an optimization.
imgui.End()
return
}
// Use fixed width for labels (by passing a negative value), the rest goes to widgets.
// We choose a width proportional to our font size.
imgui.PushItemWidth(imgui.FontSize() * -12)
// MenuBar
if imgui.BeginMenuBar() {
if imgui.BeginMenu("Menu") {
imgui.EndMenu()
}
if imgui.BeginMenu("Examples") {
imgui.EndMenu()
}
if imgui.BeginMenu("Tools") {
imgui.EndMenu()
}
imgui.EndMenuBar()
}
imgui.Text(fmt.Sprintf("dear cimgui says hello. (%s)", imgui.Version()))
imgui.Spacing()
if imgui.CollapsingHeaderTreeNodeFlagsV("Help", imgui.TreeNodeFlagsNone) {
imgui.Text("ABOUT THIS DEMO:")
bulletText("Sections below are demonstrating many aspects of the wrapper.")
bulletText("This demo may not be complete. Refer to the \"native\" demo window for a full overview.")
bulletText("The \"Examples\" menu above leads to more demo contents.")
bulletText("The \"Tools\" menu above gives access to: About Box, Style Editor,\n" +
"and Metrics (general purpose Dear ImGui debugging tool).")
imgui.Separator()
imgui.Text("PROGRAMMER GUIDE:")
bulletText("See the demo.Show() code in internal/demo/Window.go. <- you are here!")
bulletText("See comments in cimgui.cpp.")
bulletText("See example applications in the examples/ folder.")
bulletText("Read the FAQ at http://www.dearimgui.org/faq/")
bulletText("Set 'io.ConfigFlags |= NavEnableKeyboard' for keyboard controls.")
bulletText("Set 'io.ConfigFlags |= NavEnableGamepad' for gamepad controls.")
imgui.Separator()
imgui.Text("USER GUIDE:")
showUserGuide()
}
// MISSING: Configuration
if imgui.CollapsingHeaderTreeNodeFlagsV("Window options", imgui.TreeNodeFlagsNone) {
imgui.Checkbox("No titlebar", &window.flags.noTitlebar)
imgui.SameLineV(150, -1)
imgui.Checkbox("No scrollbar", &window.flags.noScrollbar)
imgui.SameLineV(300, -1)
imgui.Checkbox("No menu", &window.flags.noMenu)
imgui.Checkbox("No move", &window.flags.noMove)
imgui.SameLineV(150, -1)
imgui.Checkbox("No resize", &window.flags.noResize)
imgui.SameLineV(300, -1)
imgui.Checkbox("No collapse", &window.flags.noCollapse)
imgui.Checkbox("No close", &window.noClose)
imgui.SameLineV(150, -1)
imgui.Checkbox("No nav", &window.flags.noNav)
imgui.SameLineV(300, -1)
imgui.Checkbox("No background", &window.flags.noBackground)
imgui.Checkbox("No bring to front", &window.flags.noBringToFront)
}
// All demo contents
window.widgets.show()
window.layout.show()
window.popups.show()
window.columns.show()
window.tables.show()
window.misc.show()
// End of ShowDemoWindow()
imgui.End()
}
func showUserGuide() {
bulletText("Double-click on title bar to collapse window.")
bulletText("Click and drag on lower corner to resize window\n(double-click to auto fit window to its contents).")
bulletText("CTRL+Click on a slider or drag box to input value as text.")
bulletText("TAB/SHIFT+TAB to cycle through keyboard editable fields.")
// MISSING: Allow FontUserScaling
bulletText("While inputing text:\n")
imgui.Indent()
bulletText("CTRL+Left/Right to word jump.")
bulletText("CTRL+A or double-click to select all.")
bulletText("CTRL+X/C/V to use clipboard cut/copy/paste.")
bulletText("CTRL+Z,CTRL+Y to undo/redo.")
bulletText("ESCAPE to revert.")
bulletText("You can apply arithmetic operators +,*,/ on numerical values.\nUse +- to subtract.")
imgui.Unindent()
bulletText("With keyboard navigation enabled:")
imgui.Indent()
bulletText("Arrow keys to navigate.")
bulletText("Space to activate a widget.")
bulletText("Return to input text into a widget.")
bulletText("Escape to deactivate a widget, close popup, exit child window.")
bulletText("Alt to jump to the menu layer of a window.")
bulletText("CTRL+Tab to select a window.")
imgui.Unindent()
}
type widgets struct {
buttonClicked int
check bool
radio int32
}
// nolint: nestif
func (widgets *widgets) show() {
if !imgui.CollapsingHeaderTreeNodeFlags("Widgets") {
return
}
if imgui.TreeNodeStr("Basic") {
if imgui.Button("Button") {
widgets.buttonClicked++
}
if widgets.buttonClicked&1 != 0 {
imgui.SameLine()
imgui.Text("Thanks for clicking me!")
}
imgui.Checkbox("checkbox", &widgets.check)
if imgui.RadioButtonBool("radio a", widgets.radio == 0) {
widgets.radio = 0
}
imgui.SameLine()
if imgui.RadioButtonBool("radio b", widgets.radio == 1) {
widgets.radio = 1
}
imgui.SameLine()
if imgui.RadioButtonBool("radio c", widgets.radio == 2) {
widgets.radio = 2
}
str := strings.Join([]string{
"one item",
"two items",
"three items",
}, "\x00") + "\x00"
imgui.ComboStrV("combo", &widgets.radio, str, -1)
imgui.TreePop()
}
}
type tables struct {
background bool
borders bool
noInnerBorders bool
header bool
}
var demoTableHeader = []string{
"Name", "Favourite Food", "Favourite Colour",
}
var demoTable = [][]string{
{"Eric", "Bannana", "Yellow"},
{"Peter", "Apple", "Red"},
{"Bruce", "Liquorice", "Black"},
{"Aaron", "Chocolates", "Blue"},
}
func (tables *tables) show() {
if !imgui.CollapsingHeaderTreeNodeFlags("Tables") {
return
}
if imgui.TreeNodeStr("Rows & Columns") {
if imgui.BeginTable("tableRowsAndColumns", 3) {
for row := 0; row < 4; row++ {
imgui.TableNextRow()
for column := int32(0); column < 3; column++ {
imgui.TableSetColumnIndex(column)
imgui.Text(fmt.Sprintf("Row %d Column %d", row, column))
}
}
imgui.EndTable()
}
imgui.TreePop()
}
if imgui.TreeNodeStr("Options") {
// tables are useful for more than tabulated data. we use tables here
// to facilitate layout of the option checkboxes
if imgui.BeginTable("tableOptions", 2) {
imgui.TableNextRow()
if imgui.TableNextColumn() {
imgui.Checkbox("Background", &tables.background)
}
if imgui.TableNextColumn() {
imgui.Checkbox("Header Row", &tables.header)
}
imgui.TableNextRow()
if imgui.TableNextColumn() {
imgui.Checkbox("Borders", &tables.borders)
}
if tables.borders {
if imgui.TableNextColumn() {
imgui.Checkbox("No Inner Borders", &tables.noInnerBorders)
}
}
imgui.EndTable()
}
// set flags according to the options that have been selected
flgs := imgui.TableFlagsNone
if tables.background {
flgs |= imgui.TableFlagsRowBg
}
if tables.borders {
flgs |= imgui.TableFlagsBorders
if tables.noInnerBorders {
flgs |= imgui.TableFlagsNoBordersInBody
}
}
if imgui.BeginTableV("tableRowsAndColumns", int32(len(demoTableHeader)), imgui.TableFlags(flgs), imgui.Vec2{}, 0.0) {
if tables.header {
imgui.TableHeadersRow()
for column := 0; column < len(demoTableHeader); column++ {
imgui.TableSetColumnIndex(int32(column))
imgui.Text(demoTableHeader[column])
}
}
for row := 0; row < len(demoTable); row++ {
imgui.TableNextRow()
for column := 0; column < len(demoTableHeader); column++ {
imgui.TableSetColumnIndex(int32(column))
imgui.Text(demoTable[row][column])
}
}
imgui.EndTable()
}
imgui.TreePop()
}
}
type layout struct {
}
func (layout *layout) show() {
}
type popups struct {
}
func (popups *popups) show() {
}
type columns struct {
}
func (columns *columns) show() {
}
type misc struct {
}
func (misc *misc) show() {
}