This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
/
Window.go
471 lines (408 loc) · 17.1 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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
package imgui
// #include "wrapper/Window.h"
import "C"
// ShowDemoWindow creates a demo/test window. Demonstrates most ImGui features.
// Call this to learn about the library! Try to make it always available in your application!
func ShowDemoWindow(open *bool) {
openArg, openFin := wrapBool(open)
defer openFin()
C.iggShowDemoWindow(openArg)
}
// ShowUserGuide adds basic help/info block (not a window): how to manipulate ImGui as a end-user (mouse/keyboard controls).
func ShowUserGuide() {
C.iggShowUserGuide()
}
// WindowFlags for BeginV(), etc.
type WindowFlags int
const (
// WindowFlagsNone default = 0.
WindowFlagsNone WindowFlags = 0
// WindowFlagsNoTitleBar disables title-bar.
WindowFlagsNoTitleBar WindowFlags = 1 << 0
// WindowFlagsNoResize disables user resizing with the lower-right grip.
WindowFlagsNoResize WindowFlags = 1 << 1
// WindowFlagsNoMove disables user moving the window.
WindowFlagsNoMove WindowFlags = 1 << 2
// WindowFlagsNoScrollbar disables scrollbars. Window can still scroll with mouse or programmatically.
WindowFlagsNoScrollbar WindowFlags = 1 << 3
// WindowFlagsNoScrollWithMouse disables user vertically scrolling with mouse wheel. On child window, mouse wheel
// will be forwarded to the parent unless NoScrollbar is also set.
WindowFlagsNoScrollWithMouse WindowFlags = 1 << 4
// WindowFlagsNoCollapse disables user collapsing window by double-clicking on it.
WindowFlagsNoCollapse WindowFlags = 1 << 5
// WindowFlagsAlwaysAutoResize resizes every window to its content every frame.
WindowFlagsAlwaysAutoResize WindowFlags = 1 << 6
// WindowFlagsNoBackground disables drawing background color (WindowBg, etc.) and outside border. Similar as using
// SetNextWindowBgAlpha(0.0f).
WindowFlagsNoBackground WindowFlags = 1 << 7
// WindowFlagsNoSavedSettings will never load/save settings in .ini file.
WindowFlagsNoSavedSettings WindowFlags = 1 << 8
// WindowFlagsNoMouseInputs disables catching mouse, hovering test with pass through.
WindowFlagsNoMouseInputs WindowFlags = 1 << 9
// WindowFlagsMenuBar has a menu-bar.
WindowFlagsMenuBar WindowFlags = 1 << 10
// WindowFlagsHorizontalScrollbar allows horizontal scrollbar to appear (off by default). You may use
// SetNextWindowContentSize(ImVec2(width,0.0f)); prior to calling Begin() to specify width. Read code in imgui_demo
// in the "Horizontal Scrolling" section.
WindowFlagsHorizontalScrollbar WindowFlags = 1 << 11
// WindowFlagsNoFocusOnAppearing disables taking focus when transitioning from hidden to visible state.
WindowFlagsNoFocusOnAppearing WindowFlags = 1 << 12
// WindowFlagsNoBringToFrontOnFocus disables bringing window to front when taking focus. e.g. clicking on it or
// programmatically giving it focus.
WindowFlagsNoBringToFrontOnFocus WindowFlags = 1 << 13
// WindowFlagsAlwaysVerticalScrollbar always shows vertical scrollbar, even if ContentSize.y < Size.y .
WindowFlagsAlwaysVerticalScrollbar WindowFlags = 1 << 14
// WindowFlagsAlwaysHorizontalScrollbar always shows horizontal scrollbar, even if ContentSize.x < Size.x .
WindowFlagsAlwaysHorizontalScrollbar WindowFlags = 1 << 15
// WindowFlagsAlwaysUseWindowPadding ensures child windows without border uses style.WindowPadding (ignored by
// default for non-bordered child windows, because more convenient).
WindowFlagsAlwaysUseWindowPadding WindowFlags = 1 << 16
// WindowFlagsNoNavInputs has no gamepad/keyboard navigation within the window.
WindowFlagsNoNavInputs WindowFlags = 1 << 18
// WindowFlagsNoNavFocus has no focusing toward this window with gamepad/keyboard navigation
// (e.g. skipped by CTRL+TAB).
WindowFlagsNoNavFocus WindowFlags = 1 << 19
// WindowFlagsUnsavedDocument appends '*' to title without affecting the ID, as a convenience to avoid using the
// ### operator. When used in a tab/docking context, tab is selected on closure and closure is deferred by one
// frame to allow code to cancel the closure (with a confirmation popup, etc.) without flicker.
WindowFlagsUnsavedDocument WindowFlags = 1 << 20
// WindowFlagsNoNav combines WindowFlagsNoNavInputs and WindowFlagsNoNavFocus.
WindowFlagsNoNav = WindowFlagsNoNavInputs | WindowFlagsNoNavFocus
// WindowFlagsNoDecoration combines WindowFlagsNoTitleBar, WindowFlagsNoResize, WindowFlagsNoScrollbar and
// WindowFlagsNoCollapse.
WindowFlagsNoDecoration = WindowFlagsNoTitleBar | WindowFlagsNoResize | WindowFlagsNoScrollbar | WindowFlagsNoCollapse
// WindowFlagsNoInputs combines WindowFlagsNoMouseInputs, WindowFlagsNoNavInputs and WindowFlagsNoNavFocus.
WindowFlagsNoInputs = WindowFlagsNoMouseInputs | WindowFlagsNoNavInputs | WindowFlagsNoNavFocus
)
// BeginV pushes a new window to the stack and start appending to it.
// You may append multiple times to the same window during the same frame.
// If the open argument is provided, the window can be closed, in which case the value will be false after the call.
//
// Returns false if the window is currently not visible.
// Regardless of the return value, End() must be called for each call to Begin().
func BeginV(id string, open *bool, flags WindowFlags) bool {
idArg, idFin := wrapString(id)
defer idFin()
openArg, openFin := wrapBool(open)
defer openFin()
return C.iggBegin(idArg, openArg, C.int(flags)) != 0
}
// Begin calls BeginV(id, nil, 0).
func Begin(id string) bool {
return BeginV(id, nil, 0)
}
// End closes the scope for the previously opened window.
// Every call to Begin() must be matched with a call to End().
func End() {
C.iggEnd()
}
// BeginChildV pushes a new child to the stack and starts appending to it.
// flags are the WindowFlags to apply.
func BeginChildV(id string, size Vec2, border bool, flags WindowFlags) bool {
idArg, idFin := wrapString(id)
defer idFin()
sizeArg, _ := size.wrapped()
return C.iggBeginChild(idArg, sizeArg, castBool(border), C.int(flags)) != 0
}
// BeginChild calls BeginChildV(id, Vec2{0,0}, false, 0).
func BeginChild(id string) bool {
return BeginChildV(id, Vec2{}, false, 0)
}
// EndChild closes the scope for the previously opened child.
// Every call to BeginChild() must be matched with a call to EndChild().
func EndChild() {
C.iggEndChild()
}
// WindowPos returns the current window position in screen space.
// This is useful if you want to do your own drawing via the DrawList API.
func WindowPos() Vec2 {
var value Vec2
valueArg, valueFin := value.wrapped()
C.iggWindowPos(valueArg)
valueFin()
return value
}
// WindowSize returns the size of the current window.
func WindowSize() Vec2 {
var value Vec2
valueArg, valueFin := value.wrapped()
C.iggWindowSize(valueArg)
valueFin()
return value
}
// WindowWidth returns the width of the current window.
func WindowWidth() float32 {
return float32(C.iggWindowWidth())
}
// WindowHeight returns the height of the current window.
func WindowHeight() float32 {
return float32(C.iggWindowHeight())
}
// ContentRegionAvail returns the size of the content region that is available (based on the current cursor position).
func ContentRegionAvail() Vec2 {
var value Vec2
valueArg, valueFin := value.wrapped()
C.iggContentRegionAvail(valueArg)
valueFin()
return value
}
// ContentRegionMax returns current content boundaries (typically window boundaries including scrolling,
// or current column boundaries), in windows coordinates.
func ContentRegionMax() Vec2 {
out := Vec2{}
outArg, outFin := out.wrapped()
C.iggGetContentRegionMax(outArg)
outFin()
return out
}
// WindowContentRegionMin returns the content boundaries min (roughly (0,0)-Scroll), in window coordinates.
func WindowContentRegionMin() Vec2 {
out := Vec2{}
outArg, outFin := out.wrapped()
C.iggGetWindowContentRegionMin(outArg)
outFin()
return out
}
// WindowContentRegionMax returns the content boundaries max (roughly (0,0)+Size-Scroll) where Size can be overridden
// with SetNextWindowContentSize(), in window coordinates.
func WindowContentRegionMax() Vec2 {
out := Vec2{}
outArg, outFin := out.wrapped()
C.iggGetWindowContentRegionMax(outArg)
outFin()
return out
}
// WindowContentRegionWidth returns the width of the content boundary, in window coordinates.
//
// DEPRECATED: in v1.85, GetWindowContentRegionWidth() function has been removed.
// This function now returns GetWindowContentRegionMax().x - GetWindowContentRegionMin().x,
// as per v1.85 release notes. Please note it's not very useful in practice, and
// using GetContentRegionAvail().x is generally a better choice.
func WindowContentRegionWidth() float32 {
return WindowContentRegionMax().X - WindowContentRegionMin().X
}
// SetNextWindowPosV sets next window position.
// Call before Begin(). Use pivot=(0.5,0.5) to center on given point, etc.
func SetNextWindowPosV(pos Vec2, cond Condition, pivot Vec2) {
posArg, _ := pos.wrapped()
pivotArg, _ := pivot.wrapped()
C.iggSetNextWindowPos(posArg, C.int(cond), pivotArg)
}
// SetNextWindowPos calls SetNextWindowPosV(pos, 0, Vec{0,0}).
func SetNextWindowPos(pos Vec2) {
SetNextWindowPosV(pos, 0, Vec2{})
}
// SetNextWindowCollapsed sets the next window collapsed state.
func SetNextWindowCollapsed(collapsed bool, cond Condition) {
C.iggSetNextWindowCollapsed(castBool(collapsed), C.int(cond))
}
// SetNextWindowSizeV sets next window size.
// Set axis to 0.0 to force an auto-fit on this axis. Call before Begin().
func SetNextWindowSizeV(size Vec2, cond Condition) {
sizeArg, _ := size.wrapped()
C.iggSetNextWindowSize(sizeArg, C.int(cond))
}
// SetNextWindowSize calls SetNextWindowSizeV(size, 0).
func SetNextWindowSize(size Vec2) {
SetNextWindowSizeV(size, 0)
}
// SetNextWindowSizeConstraints set next window size limits.
// Use -1,-1 on either X/Y axis to preserve the current size.
// Use callback to apply non-trivial programmatic constraints.
func SetNextWindowSizeConstraints(sizeMin Vec2, sizeMax Vec2) {
sizeMinArg, _ := sizeMin.wrapped()
sizeMaxArg, _ := sizeMax.wrapped()
C.iggSetNextWindowSizeConstraints(sizeMinArg, sizeMaxArg)
}
// SetNextWindowContentSize sets next window content size (~ enforce the range of scrollbars).
// Does not include window decorations (title bar, menu bar, etc.).
// Set one axis to 0.0 to leave it automatic. This function must be called before Begin() to take effect.
func SetNextWindowContentSize(size Vec2) {
sizeArg, _ := size.wrapped()
C.iggSetNextWindowContentSize(sizeArg)
}
// SetNextWindowFocus sets next window to be focused / front-most. Call before Begin().
func SetNextWindowFocus() {
C.iggSetNextWindowFocus()
}
// SetNextWindowBgAlpha sets next window background color alpha.
// Helper to easily modify ImGuiCol_WindowBg/ChildBg/PopupBg.
func SetNextWindowBgAlpha(value float32) {
C.iggSetNextWindowBgAlpha(C.float(value))
}
// PushItemWidth pushes width of items for common large "item+label" widgets.
// >0.0f: width in pixels, <0.0f align xx pixels to the right of window (so -math.SmallestNonzeroFloat32 always align width to the right side).
func PushItemWidth(width float32) {
C.iggPushItemWidth(C.float(width))
}
// PopItemWidth must be called for each call to PushItemWidth().
func PopItemWidth() {
C.iggPopItemWidth()
}
// SetNextItemWidth sets width of the _next_ common large "item+label" widget.
// >0.0f: width in pixels, <0.0f align xx pixels to the right of window (so -math.SmallestNonzeroFloat32 always align width to the right side).
func SetNextItemWidth(width float32) {
C.iggSetNextItemWidth(C.float(width))
}
// ItemFlags for PushItemFlag().
type ItemFlags int
const (
// ItemFlagsNone default = 0.
ItemFlagsNone ItemFlags = 0
// ItemFlagsNoTabStop has no tab stop.
ItemFlagsNoTabStop ItemFlags = 1 << 0
// ItemFlagsButtonRepeat will return true multiple times based on io.KeyRepeatDelay and io.KeyRepeatRate settings.
ItemFlagsButtonRepeat ItemFlags = 1 << 1
// ItemFlagsDisabled [BETA] disable interactions but doesn't affect visuals yet. See github.com/ocornut/imgui/issues/211.
ItemFlagsDisabled ItemFlags = 1 << 2
// ItemFlagsNoNav has no nav.
ItemFlagsNoNav ItemFlags = 1 << 3
// ItemFlagsNoNavDefaultFocus has no nav default focus.
ItemFlagsNoNavDefaultFocus ItemFlags = 1 << 4
// ItemFlagsSelectableDontClosePopup automatically closes current Popup window.
ItemFlagsSelectableDontClosePopup ItemFlags = 1 << 5
// ItemFlagsMixedValue [BETA] represent a mixed/indeterminate value, generally multi-selection where values differ.
// Currently only supported by Checkbox() (later should support all sorts of widgets).
ItemFlagsMixedValue ItemFlags = 1 << 6
// ItemFlagsDefault default = 0.
ItemFlagsDefault ItemFlags = 0
)
// PushItemFlag changes flags in the existing options for the next items until PopItemFlag() is called.
func PushItemFlag(options ItemFlags, enabled bool) {
C.iggPushItemFlag(C.int(options), castBool(enabled))
}
// PopItemFlag restores flags that were changed by the previous call to PushItemFlag().
func PopItemFlag() {
C.iggPopItemFlag()
}
// CalcItemWidth returns the width of items given pushed settings and current cursor position.
func CalcItemWidth() float32 {
return float32(C.iggCalcItemWidth())
}
// PushTextWrapPosV defines word-wrapping for Text() commands.
// < 0.0f: no wrapping; 0.0f: wrap to end of window (or column); > 0.0f: wrap at 'wrapPosX' position in window local space.
// Requires a matching call to PopTextWrapPos().
func PushTextWrapPosV(wrapPosX float32) {
C.iggPushTextWrapPos(C.float(wrapPosX))
}
// PushTextWrapPos calls PushTextWrapPosV(0).
func PushTextWrapPos() {
PushTextWrapPosV(0)
}
// PopTextWrapPos resets the last pushed position.
func PopTextWrapPos() {
C.iggPopTextWrapPos()
}
// PushAllowKeyboardFocus allow the next window to take focus of the keyboard.
func PushAllowKeyboardFocus(allow bool) {
C.iggPushAllowKeyboardFocus(castBool(allow))
}
//PopAllowKeyboardFocus pops most recent allow keyboard focus setting.
func PopAllowKeyboardFocus() {
C.iggPopAllowKeyboardFocus()
}
// PushButtonRepeat enables button to repeat press if held.
func PushButtonRepeat(repeat bool) {
C.iggPushButtonRepeat(castBool(repeat))
}
// PopButtonRepeat pops most recent button repeat setting.
func PopButtonRepeat() {
C.iggPopButtonRepeat()
}
// Viewport A Platform Window (always only one in 'master' branch), in the future may represent Platform Monitor.
type Viewport uintptr
// ViewportFlags flags for viewport.
type ViewportFlags int
const (
// ViewportFlagsNone default = 0.
ViewportFlagsNone ViewportFlags = 0
// ViewportFlagsIsPlatformWindow represents a Platform Window.
ViewportFlagsIsPlatformWindow ViewportFlags = 1 << 0
// ViewportFlagsIsPlatformMonitor represents a Platform Monitor (unused yet).
ViewportFlagsIsPlatformMonitor ViewportFlags = 1 << 1
// ViewportFlagsOwnedByApp Platform Window: is created/managed by the application (rather than a dear imgui backend).
ViewportFlagsOwnedByApp ViewportFlags = 1 << 2
)
// MainViewport returns primary/default viewport.
// - Currently represents the Platform Window created by the application which is hosting our Dear ImGui windows.
// - In 'docking' branch with multi-viewport enabled, we extend this concept to have multiple active viewports.
// - In the future we will extend this concept further to also represent Platform Monitor and support a "no main platform window" operation mode.
func MainViewport() Viewport {
return Viewport(C.iggGetMainViewport())
}
func (viewport Viewport) handle() C.IggViewport {
return C.IggViewport(viewport)
}
// Flags returns viewports flags value.
func (viewport Viewport) Flags() ViewportFlags {
if viewport == 0 {
return ViewportFlagsNone
}
return ViewportFlags(C.iggViewportGetFlags(viewport.handle()))
}
// Pos returns viewports Main Area: Position of the viewport (Dear Imgui coordinates are the same as OS desktop/native coordinates).
func (viewport Viewport) Pos() Vec2 {
if viewport == 0 {
return Vec2{}
}
var value Vec2
valueArg, valueFin := value.wrapped()
C.iggViewportGetPos(viewport.handle(), valueArg)
valueFin()
return value
}
// Size returns viewports Main Area: Size of the viewport.
func (viewport Viewport) Size() Vec2 {
if viewport == 0 {
return Vec2{}
}
var value Vec2
valueArg, valueFin := value.wrapped()
C.iggViewportGetSize(viewport.handle(), valueArg)
valueFin()
return value
}
// WorkPos returns viewports Work Area: Position of the viewport minus task bars, menus bars, status bars (>= Pos).
func (viewport Viewport) WorkPos() Vec2 {
if viewport == 0 {
return Vec2{}
}
var value Vec2
valueArg, valueFin := value.wrapped()
C.iggViewportGetWorkPos(viewport.handle(), valueArg)
valueFin()
return value
}
// WorkSize returns viewports Work Area: Size of the viewport minus task bars, menu bars, status bars (<= Size).
func (viewport Viewport) WorkSize() Vec2 {
if viewport == 0 {
return Vec2{}
}
var value Vec2
valueArg, valueFin := value.wrapped()
C.iggViewportGetWorkSize(viewport.handle(), valueArg)
valueFin()
return value
}
// Center returns center of the viewport.
func (viewport Viewport) Center() Vec2 {
if viewport == 0 {
return Vec2{}
}
var value Vec2
valueArg, valueFin := value.wrapped()
C.iggViewportGetCenter(viewport.handle(), valueArg)
valueFin()
return value
}
// WorkCenter returns center of the viewport minus task bars, menu bars, status bars.
func (viewport Viewport) WorkCenter() Vec2 {
if viewport == 0 {
return Vec2{}
}
var value Vec2
valueArg, valueFin := value.wrapped()
C.iggViewportGetWorkCenter(viewport.handle(), valueArg)
valueFin()
return value
}