-
Notifications
You must be signed in to change notification settings - Fork 25
/
wrapper.jl
3263 lines (2759 loc) · 124 KB
/
wrapper.jl
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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
########################################## context #########################################
"""
CreateContext() -> Ptr{ImGuiContext}
CreateContext(shared_font_atlas::Ptr{ImFontAtlas}) -> Ptr{ImGuiContext}
Return a handle of `ImGuiContext`.
"""
CreateContext() = igCreateContext(C_NULL)
CreateContext(shared_font_atlas::Ptr{ImFontAtlas}) = igCreateContext(shared_font_atlas)
"""
DestroyContext()
DestroyContext(ctx::Ptr{ImGuiContext})
Destroy `ImGuiContext`. `DestroyContext()` will destroy current context.
"""
DestroyContext() = igDestroyContext(C_NULL)
DestroyContext(ctx::Ptr{ImGuiContext}) = igDestroyContext(ctx)
"""
GetCurrentContext() -> Ptr{ImGuiContext}
Return a handle of the current context.
"""
GetCurrentContext() = igGetCurrentContext()
"""
SetCurrentContext(ctx::Ptr{ImGuiContext})
Set current context to `ctx`.
"""
SetCurrentContext(ctx::Ptr{ImGuiContext}) = igSetCurrentContext(ctx)
########################################### Main ###########################################
"""
GetIO() -> Ptr{ImGuiIO}
Return a handle of `ImGuiIO` which is for accessing the `IO` structure:
- mouse/keyboard/gamepad inputs
- time
- various configuration options/flags
"""
GetIO() = igGetIO()
"""
GetStyle() -> Ptr{ImGuiStyle}
Return a handle of `ImGuiStyle` which is for accessing the `Style` structure (colors, sizes).
!!! note
Always use [`PushStyleColor`](@ref), [`PushStyleVar`](@ref) to modify style mid-frame.
"""
GetStyle() = igGetStyle()
"""
NewFrame()
Start a new ImGui frame. You can submit any command from this point until [`Render`](@ref)
or [`EndFrame`](@ref).
"""
NewFrame() = igNewFrame()
"""
EndFrame()
Calling this function ends the ImGui frame. This function is automatically called by [`Render`](@ref),
so you likely don't need to call it yourself directly. If you don't need to render data (skipping rendering),
you may call [`EndFrame`](@ref) but you'll have wasted CPU already! If you don't need to render,
better to not create any imgui windows and not call [`NewFrame`](@ref) at all!
"""
EndFrame() = igEndFrame()
"""
Render()
Calling this function ends the ImGui frame. This function finalizes the draw data.
!!! warning "Obsolete"
Optionally call `ImGuiIO.RenderDrawListsFn` if set. Nowadays, prefer calling your render
function yourself.
"""
Render() = igRender()
"""
GetDrawData() -> Ptr{ImDrawData}
Return a handle of `ImDrawData` which is valid after [`Render`](@ref) and until the next call
to [`NewFrame`](@ref). This is what you have to render.
!!! warning "Obsolete"
This used to be passed to your `ImGuiIO.RenderDrawListsFn` function.
"""
GetDrawData() = igGetDrawData()
################################# Demo, Debug, Information #################################
"""
ShowDemoWindow()
ShowDemoWindow(p_open=C_NULL)
Create demo/test window. Demonstrate most ImGui features.
"""
ShowDemoWindow(p_open=C_NULL) = igShowDemoWindow(p_open)
"""
ShowAboutWindow()
ShowAboutWindow(p_open=C_NULL)
Create about window. Display Dear ImGui version, credits and build/system information.
"""
ShowAboutWindow(p_open=C_NULL) = igShowAboutWindow(p_open)
"""
ShowMetricsWindow()
ShowMetricsWindow(p_open=C_NULL)
Create metrics window. Display Dear ImGui internals: draw commands (with individual draw calls
and vertices), window list, basic internal state, etc.
"""
ShowMetricsWindow(p_open=C_NULL) = igShowMetricsWindow(p_open)
"""
ShowStyleEditor()
ShowStyleEditor(ref=C_NULL)
Add style editor block (not a window). You can pass in a reference `ImGuiStyle` structure to
compare to, revert to and save to (else it uses the default style).
"""
ShowStyleEditor(ref=C_NULL) = igShowStyleEditor(ref)
"""
ShowStyleSelector()
ShowStyleSelector(label)
Add style selector block (not a window), essentially a combo listing the default styles.
"""
ShowStyleSelector(label) = igShowStyleSelector(label)
"""
ShowFontSelector(label)
Add font selector block (not a window), essentially a combo listing the loaded fonts.
"""
ShowFontSelector(label) = igShowFontSelector(label)
"""
ShowUserGuide()
Add basic help/info block (not a window): how to manipulate ImGui as a end-user (mouse/keyboard controls).
"""
ShowUserGuide() = igShowUserGuide()
"""
GetVersion() -> Cstring
Get the compiled version string e.g. "1.23"
"""
GetVersion() = igGetVersion()
########################################## Styles ##########################################
"""
StyleColorsDark()
Use the new, recommended style. This is also the default style.
"""
StyleColorsDark() = igStyleColorsDark(C_NULL)
"""
StyleColorsClassic()
Use the classic imgui style.
"""
StyleColorsClassic() = igStyleColorsClassic(C_NULL)
"""
StyleColorsLight()
This style is best used with borders and a custom, thicker font.
"""
StyleColorsLight() = igStyleColorsLight(C_NULL)
########################################## Windows #########################################
"""
Begin(name, p_open=C_NULL, flags=0) -> Bool
Push window to the stack and start appending to it.
### Usage
- you may **append multiple times to the same window** during **the same frame**.
- passing `p_open != C_NULL` shows a window-closing widget in the upper-right corner of the window,
which clicking will set the boolean to false when clicked.
- [`Begin`](@ref) return false to indicate the window is collapsed or fully clipped, so you
may early out and omit submitting anything to the window.
!!! note
Always call a matching [`End`](@ref) for each [`Begin`](@ref) call, regardless of its return value.
This is due to legacy reason and is inconsistent with most other functions (such as
[`BeginMenu`](@ref)/[`EndMenu`](@ref), [`BeginPopup`](@ref)/[`EndPopup`](@ref), etc.)
where the `EndXXX` call should only be called if the corresponding `BeginXXX` function returned true.
"""
Begin(name, p_open=C_NULL, flags=0) = igBegin(name, p_open, flags)
"""
End()
Pop window from the stack. See also [`Begin`](@ref).
"""
End() = igEnd()
####################################### Child Windows ######################################
"""
BeginChild(str_id, size=(0,0), border=false, flags=0) -> Bool
BeginChild(id::Integer, size=(0,0), border=false, flags=0) -> Bool
Use child windows to begin into a self-contained independent scrolling/clipping regions within
a host window. Child windows can embed their own child.
Return false to indicate the window is collapsed or fully clipped, so you may early out and
omit submitting anything to the window.
For each independent axis of `size`:
- `x == 0.0`: use remaining host window size
- `x > 0.0`: fixed size
- `x < 0.0`: use remaining window size minus abs(size)
Each axis can use a different mode, e.g. `ImVec2(0,400)`.
!!! note
Always call a matching [`EndChild`](@ref) for each [`BeginChild`](@ref) call, regardless
of its return value. This is due to legacy reason and is inconsistent with most other
functions (such as [`BeginMenu`](@ref)/[`EndMenu`](@ref), [`BeginPopup`](@ref)/[`EndPopup`](@ref), etc.)
where the `EndXXX` call should only be called if the corresponding `BeginXXX` function returned true.
"""
BeginChild(str_id, size=(0,0), border=false, flags=0) = igBeginChild_Str(str_id, size, border, flags)
BeginChild(id::Integer, size=(0,0), border=false, flags=0) = igBeginChild_ID(id, size, border, flags)
"""
EndChild()
See also [`BeginChild`](@ref).
"""
EndChild() = igEndChild()
##################################### Windows Utilities ####################################
"""
IsWindowAppearing() -> Bool
"""
IsWindowAppearing() = igIsWindowAppearing()
"""
IsWindowCollapsed() -> Bool
"""
IsWindowCollapsed() = igIsWindowCollapsed()
"""
IsWindowFocused(flags=0) -> Bool
Is current window focused? or its root/child, depending on flags.
See the output of `CImGui.GetFlags(CImGui.ImGuiFocusedFlags_)` for options:
```@eval
using CImGui, Markdown
CImGui.ShowFlags(CImGui.ImGuiFocusedFlags_) |> Markdown.parse
```
"""
IsWindowFocused(flags=0) = igIsWindowFocused(flags)
@deprecate IsAnyWindowFocused() IsWindowFocused(ImGuiFocusedFlags_AnyWindow)
"""
IsWindowHovered(flags=0) -> Bool
Is current window hovered (and typically: not blocked by a popup/modal)?
See the output of `CImGui.GetFlags(CImGui.ImGuiHoveredFlags_)` for options:
```@eval
using CImGui, Markdown
CImGui.ShowFlags(CImGui.ImGuiHoveredFlags_) |> Markdown.parse
```
!!! note
If you are trying to check whether your mouse should be dispatched to imgui or to your app,
you should use the `ImGuiIO.WantCaptureMouse` boolean for that! Please read the FAQ!
!!! tip "FAQ"
Q: How can I tell whether to dispatch mouse/keyboard to imgui or to my application?
A: You can read the `ImGuiIO.WantCaptureMouse`, `ImGuiIO.WantCaptureKeyboard` and
`ImGuiIO.WantTextInput` flags from the ImGuiIO structure, for example:
```
if CImGui.Get_WantCaptureMouse(CImGui.GetIO())
# ...
end
```
- When `ImGuiIO.WantCaptureMouse` is set, imgui wants to use your mouse state, and you
may want to discard/hide the inputs from the rest of your application.
- When `ImGuiIO.WantCaptureKeyboard` is set, imgui wants to use your keyboard state,
and you may want to discard/hide the inputs from the rest of your application.
- When `ImGuiIO.WantTextInput` is set to may want to notify your OS to popup an on-screen
keyboard, if available (e.g. on a mobile phone, or console OS).
!!! note
1. You should always pass your mouse/keyboard inputs to imgui, even when the
`ImGuiIO.WantCaptureXXX` flag are set false. This is because imgui needs to detect that you
clicked in the void to unfocus its own windows.
2. The `ImGuiIO.WantCaptureMouse` is more accurate that any attempt to "check if the mouse
is hovering a window" (don't do that!). It handle mouse dragging correctly (both dragging
that started over your application or over an imgui window) and handle e.g. modal windows
blocking inputs. Those flags are updated by [`NewFrame`](@ref). Preferably read the flags
after calling [`NewFrame`](@ref) if you can afford it, but reading them before is also
perfectly fine, as the bool toggle fairly rarely. If you have on a touch device, you
might find use for an early call to `UpdateHoveredWindowAndCaptureFlags()`.
3. Text input widget releases focus on "Return KeyDown", so the subsequent "Return KeyUp"
event that your application receive will typically have `ImGuiIO.WantCaptureKeyboard=false`.
Depending on your application logic it may or not be inconvenient. You might want to
track which key-downs were targeted for Dear ImGui, e.g. with an array of bool, and
filter out the corresponding key-ups.)
"""
IsWindowHovered(flags=0) = igIsWindowHovered(flags)
@deprecate IsAnyWindowHovered() IsWindowHovered(ImGuiHoveredFlags_AnyWindow)
"""
GetWindowDrawList() -> Ptr{ImDrawList}
Return draw list associated to the window, to append your own drawing primitives.
"""
GetWindowDrawList() = igGetWindowDrawList()
"""
GetWindowPos() -> ImVec2
Return current window position in screen space (useful if you want to do your own drawing
via the `ImDrawList` API.
"""
function GetWindowPos()
x = Ref{ImVec2}()
igGetWindowPos(x)
return x[]
end
"""
GetWindowSize() -> ImVec2
Return current window size.
"""
function GetWindowSize()
x = Ref{ImVec2}()
igGetWindowSize(x)
return x[]
end
"""
GetWindowWidth() -> Cfloat
Return current window width (shortcut for GetWindowSize().x).
"""
GetWindowWidth() = igGetWindowWidth()
"""
GetWindowHeight() -> Cfloat
Return current window height (shortcut for GetWindowSize().y).
"""
GetWindowHeight() = igGetWindowHeight()
"""
GetContentRegionMax() -> ImVec2
Return current content boundaries (typically window boundaries including scrolling,
or current column boundaries), in windows coordinates.
"""
function GetContentRegionMax()
x = Ref{ImVec2}()
igGetContentRegionMax(x)
return x[]
end
"""
GetContentRegionAvail() -> ImVec2
Return [`GetContentRegionMax`](@ref) - [`GetCursorPos`](@ref).
"""
function GetContentRegionAvail()
x = Ref{ImVec2}()
igGetContentRegionAvail(x)
return x[]
end
@deprecate GetContentRegionAvailWidth() GetContentRegionAvail().x
"""
GetWindowContentRegionMin() -> ImVec2
Return content boundaries min (roughly (0,0)-Scroll), in window coordinates.
"""
function GetWindowContentRegionMin()
x = Ref{ImVec2}()
igGetWindowContentRegionMin(x)
return x[]
end
"""
GetWindowContentRegionMax() -> ImVec2
Return content boundaries max (roughly (0,0)+Size-Scroll) where Size can be
override with [`SetNextWindowContentSize`](@ref), in window coordinates.
"""
function GetWindowContentRegionMax()
x = Ref{ImVec2}()
igGetWindowContentRegionMax(x)
return x[]
end
"""
GetWindowContentRegionWidth() -> ImVec2
"""
GetWindowContentRegionWidth() = GetWindowContentRegionMax().x - GetWindowContentRegionMin().x
"""
SetNextWindowPos(pos, cond=0, pivot=(0,0))
Set next window position. Call before [`Begin`](@ref). use `pivot=(0.5,0.5)` to center on given point, etc.
"""
SetNextWindowPos(pos, cond=0, pivot=ImVec2(0,0)) = igSetNextWindowPos(pos, cond, pivot)
"""
SetNextWindowSize(size, cond=0)
Set next window size. Set axis to 0.0 to force an auto-fit on this axis. Call before [`Begin`](@ref).
"""
SetNextWindowSize(size, cond=0) = igSetNextWindowSize(size, cond)
"""
SetNextWindowSizeConstraints(size_min, size_max, custom_callback=C_NULL, custom_callback_data=C_NULL)
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.
"""
SetNextWindowSizeConstraints(size_min, size_max, custom_callback=C_NULL, custom_callback_data=C_NULL) = igSetNextWindowSizeConstraints(size_min, size_max, custom_callback, custom_callback_data)
"""
SetNextWindowContentSize(size)
SetNextWindowContentSize(x, y)
Set next window content size (~ enforce the range of scrollbars). Not including window decorations
(title bar, menu bar, etc.). Set an axis to `0.0` to leave it automatic. Call before [`Begin`](@ref).
"""
SetNextWindowContentSize(size) = igSetNextWindowContentSize(size)
SetNextWindowContentSize(x, y) = SetNextWindowContentSize(ImVec2(x,y))
"""
SetNextWindowCollapsed(collapsed, cond=0)
Set next window collapsed state. Call before [`Begin`](@ref).
"""
SetNextWindowCollapsed(collapsed, cond=0) = igSetNextWindowCollapsed(collapsed, cond)
"""
SetNextWindowFocus()
Set next window to be focused / front-most. Call before [`Begin`](@ref).
"""
SetNextWindowFocus() = igSetNextWindowFocus()
"""
SetNextWindowBgAlpha(alpha)
Set next window background color alpha. Helper to easily modify `ImGuiCol_WindowBg/ChildBg/PopupBg`.
You may also use `ImGuiWindowFlags_NoBackground`.
"""
SetNextWindowBgAlpha(alpha) = igSetNextWindowBgAlpha(alpha)
"""
SetWindowPos(pos, cond=0)
Set current window position - call within [`Begin`](@ref)/[`End`](@ref).
!!! warning "Not recommended!"
This function is not recommended! Prefer using [`SetNextWindowPos`](@ref), as this may
incur tearing and side-effects.
"""
SetWindowPos(pos, cond=0) = igSetWindowPos_Vec2(pos, cond)
"""
SetWindowSize(size, cond=0)
Set current window size - call within [`Begin`](@ref)/[`End`](@ref). Set to `(0,0)` to force
an auto-fit.
!!! warning "Not recommended!"
This function is not recommended! Prefer using [`SetNextWindowSize`](@ref), as this may
incur tearing and minor side-effects.
"""
SetWindowSize(size, cond=0) = igSetWindowSize_Vec2(size, cond)
"""
SetWindowCollapsedBool(collapsed, cond=0)
Set current window collapsed state.
!!! warning "Not recommended!"
This function is not recommended! Prefer using [`SetNextWindowCollapsed`](@ref).
"""
SetWindowCollapsed(collapsed, cond=0) = igSetWindowCollapsed_Bool(collapsed, cond)
"""
SetWindowFocus()
Set current window to be focused / top-most.
!!! warning "Not recommended!"
This function is not recommended! Prefer using [`SetNextWindowFocus`](@ref).
"""
SetWindowFocus() = igSetWindowFocus_Nil()
"""
SetWindowFontScale(scale)
Set font scale. Adjust `ImGuiIO.FontGlobalScale` if you want to scale all windows.
"""
SetWindowFontScale(scale) = igSetWindowFontScale(scale)
"""
SetWindowPosStr(name::AbstractString, pos, cond=0)
Set named window position.
"""
SetWindowPos(name::AbstractString, pos, cond=0) = igSetWindowPos_Str(name, pos, cond)
"""
SetWindowSizeStr(name::AbstractString, size, cond=0)
Set named window size. Set axis to `0.0` to force an auto-fit on this axis.
"""
SetWindowSize(name::AbstractString, size, cond=0) = igSetWindowSize_Str(name, size, cond)
"""
SetWindowCollapsed(name::AbstractString, collapsed, cond=0)
Set named window collapsed state.
"""
SetWindowCollapsed(name::AbstractString, collapsed, cond=0) = igSetWindowCollapsed_Str(name, collapsed, cond)
"""
SetWindowFocus(name::Ptr{Cvoid})
SetWindowFocus(name::AbstractString)
Set named window to be focused / front-most. Use `C_NULL` to remove focus.
"""
SetWindowFocus(name::Ptr{Cvoid}) = igSetWindowFocus_Str(name)
SetWindowFocus(name::AbstractString) = igSetWindowFocus_Str(name)
##################################### Windows Scrolling ####################################
"""
GetScrollX() -> Cfloat
Return scrolling amount [0..GetScrollMaxX()]. See also [`GetScrollMaxX`](@ref).
"""
GetScrollX() = igGetScrollX()
"""
GetScrollY() -> Cfloat
Return scrolling amount [0..GetScrollMaxY()].
"""
GetScrollY() = igGetScrollY()
"""
GetScrollMaxX() -> Cfloat
Return maximum scrolling amount ~~ ContentSize.X - WindowSize.X.
"""
GetScrollMaxX() = igGetScrollMaxX()
"""
GetScrollMaxY() -> Cfloat
Return maximum scrolling amount ~~ ContentSize.Y - WindowSize.Y.
"""
GetScrollMaxY() = igGetScrollMaxY()
"""
SetScrollX(scroll_x)
Set scrolling amount [0..[GetScrollMaxX()](@ref)].
"""
SetScrollX(scroll_x) = igSetScrollX_Float(scroll_x)
"""
SetScrollY(scroll_y)
Set scrolling amount [0..[GetScrollMaxY()](@ref)].
"""
SetScrollY(scroll_y) = igSetScrollY_Float(scroll_y)
"""
SetScrollHereY(center_y_ratio=0.5)
Adjust scrolling amount to make current cursor position visible.
- `center_y_ratio == 0.0`: top
- `center_y_ratio == 0.5`: center
- `center_y_ratio == 1.0`: bottom
When using to make a "default/current item" visible, consider using [`SetItemDefaultFocus`](@ref) instead.
"""
SetScrollHereY(center_y_ratio=0.5) = igSetScrollHereY(center_y_ratio)
@deprecate SetScrollHere(center_ratio) SetScrollHereY(center_ratio)
"""
SetScrollFromPosX(local_y, center_y_ratio=0.5)
Adjust scrolling amount to make given position visible.
Generally [`GetCursorStartPos`](@ref) + offset to compute a valid position.
"""
SetScrollFromPosX(local_y, center_y_ratio=0.5) = igSetScrollFromPosX_Float(local_y, center_y_ratio)
"""
SetScrollFromPosY(local_y, center_y_ratio=0.5)
Adjust scrolling amount to make given position visible.
Generally [`GetCursorStartPos`](@ref) + offset to compute a valid position.
"""
SetScrollFromPosY(local_y, center_y_ratio=0.5) = igSetScrollFromPosY_Float(local_y, center_y_ratio)
################################ Parameters stacks (shared) ################################
"""
PushFont(font)
Use C_NULL as a shortcut to push default font.
"""
PushFont(font) = igPushFont(font)
"""
PopFont()
See [`PushFont`](@ref).
"""
PopFont() = igPopFont()
"""
PushStyleColor(idx, col)
PushStyleColor(idx, col::Integer)
See also [`GetStyleColorVec4`](@ref), [`TextColored`](@ref), [`TextDisabled`](@ref).
"""
PushStyleColor(idx, col) = igPushStyleColor_Vec4(idx, col)
PushStyleColor(idx, col::Integer) = igPushStyleColor_U32(idx, col)
"""
PopStyleColor(count=1)
See [`PushStyleColor`](@ref).
"""
PopStyleColor(count=1) = igPopStyleColor(count)
"""
PushStyleVar(idx, val)
PushStyleVar(idx, val::Real)
See also [`GetStyle`](@ref).
"""
PushStyleVar(idx, val) = igPushStyleVar_Vec2(idx, val)
PushStyleVar(idx, val::Real) = igPushStyleVar_Float(idx, val)
"""
PopStyleVar(count=1)
See [`PushStyleVar`](@ref).
"""
PopStyleVar(count=1) = igPopStyleVar(count)
"""
GetStyleColorVec4(idx) -> ImVec4
Retrieve style color as stored in [`ImGuiStyle`] structure. Use to feed back into [`PushStyleColor`](@ref),
otherwise use [`GetColorU32`](@ref) to get style color with style alpha baked in.
"""
GetStyleColorVec4(idx) = igGetStyleColorVec4(idx)
"""
GetFont() -> Ptr{ImFont}
Get current font.
"""
GetFont() = igGetFont()
"""
GetFontSize() -> Cfloat
Get current font size (= height in pixels) of current font with current scale applied.
"""
GetFontSize() = igGetFontSize()
"""
GetFontTexUvWhitePixel() -> ImVec2
Get UV coordinate for a while pixel, useful to draw custom shapes via the `ImDrawList` API.
"""
function GetFontTexUvWhitePixel()
x = Ref{ImVec2}()
igGetFontTexUvWhitePixel(x)
return x[]
end
"""
GetColorU32(r, g, b, a) -> ImU32
GetColorU32(col::ImVec4) -> ImU32
GetColorU32(col::ImU32) -> ImU32
GetColorU32(idx::Integer, alpha_mul=1.0) -> ImU32
Retrieve given style color with style alpha applied and optional extra alpha multiplier.
"""
GetColorU32(idx::Integer, alpha_mul=1.0) = igGetColorU32_Col(idx, alpha_mul)
GetColorU32(col::ImVec4) = igGetColorU32_Vec4(col)
GetColorU32(r, g, b, a) = GetColorU32(ImVec4(r,g,b,a))
GetColorU32(col::ImU32) = igGetColorU32_U32(col)
GetColorU32(col::Cenum) = GetColorU32(Int(col))
############################ Parameters stacks (current window) ############################
"""
PushItemWidth(item_width)
Push width of items for the common item+label case, pixels:
- `item_width == 0`: default to ~2/3 of windows width
- `item_width > 0`: width in pixels
- `item_width < 0`: align xx pixels to the right of window (so `-1.0` always align width to the right side)
"""
PushItemWidth(item_width) = igPushItemWidth(item_width)
"""
PopItemWidth()
See [`PushItemWidth`](@ref).
"""
PopItemWidth() = igPopItemWidth()
"""
SetNextItemWidth(item_width)
Set width of the _next_ common large "item+label" widget.
- `item_width > 0.0`: width in pixels
- `item_width < 0.0`: align xx pixels to the right of window (so `-1.0` always align width to the right side)
"""
SetNextItemWidth(item_width) = igSetNextItemWidth(item_width)
"""
CalcItemWidth() -> Cfloat
Return width of item given pushed settings and current cursor position.
"""
CalcItemWidth() = igCalcItemWidth()
"""
PushTextWrapPos(wrap_pos_x=0.0)
Word-wrapping for `Text*()` commands:
- `wrap_pos_x < 0`: no wrapping
- `wrap_pos_x == 0`: wrap to end of window (or column)
- `wrap_pos_x > 0`: wrap at `wrap_pos_x` position in window local space
"""
PushTextWrapPos(wrap_local_pos_x=0.0) = igPushTextWrapPos(wrap_local_pos_x)
"""
PopTextWrapPos()
See [`PushTextWrapPos`](@ref).
"""
PopTextWrapPos() = igPopTextWrapPos()
"""
PushTabStop(allow_keyboard_focus)
Allow focusing using `TAB`/`Shift-TAB`, enabled by default but you can disable it for certain widgets.
"""
PushTabStop(allow_keyboard_focus) = igPushTabStop(allow_keyboard_focus)
@deprecate PushAllowKeyboardFocus(focus) PushTabStop(focus)
"""
PopTabStop()
"""
PopTabStop() = igPopTabStop()
@deprecate PopAllowKeyboardFocus() PopTabStop()
"""
PushButtonRepeat(repeat)
In "repeat" mode, `Button*()` functions return repeated true in a typematic manner (using
`ImGuiIO.KeyRepeatDelay/ImGuiIO.KeyRepeatRate setting`). Note that you can call [`IsItemActive`](@ref)
after any `Button()` to tell if the button is held in the current frame.
"""
PushButtonRepeat(repeat) = igPushButtonRepeat(repeat)
"""
PopButtonRepeat()
See [`PushButtonRepeat`](@ref).
"""
PopButtonRepeat() = igPopButtonRepeat()
###################################### Cursor / Layout #####################################
"""
Separator()
Separator, generally horizontal. But inside a menu bar or in horizontal layout mode,
it becomes a vertical separator.
"""
Separator() = igSeparator()
"""
SameLine(local_pos_x=0.0, spacing_w=-1.0)
Call this function between widgets or groups to layout them horizontally.
"""
SameLine(local_pos_x=0.0, spacing_w=-1.0) = igSameLine(local_pos_x, spacing_w)
"""
NewLine()
Undo a [`SameLine`](@ref).
"""
NewLine() = igNewLine()
"""
Spacing()
Add vertical spacing.
"""
Spacing() = igSpacing()
"""
Dummy(size)
Dummy(x, y)
Add a dummy item of given size.
"""
Dummy(size) = igDummy(size)
Dummy(x, y) = Dummy(ImVec2(x,y))
"""
Indent()
Indent(indent_w)
Move content position toward the right, by `ImGuiStyle.IndentSpacing` or `indent_w` if `indent_w != 0`.
"""
Indent(indent_w=Cfloat(0.0)) = igIndent(indent_w)
"""
Unindent()
Unindent(indent_w)
Move content position back to the left, by `ImGuiStyle.IndentSpacing` or `indent_w` if `indent_w != 0`.
"""
Unindent(indent_w=Cfloat(0.0)) = igUnindent(indent_w)
"""
BeginGroup()
Lock horizontal starting position + capture group bounding box into one "item", so you can
use [`IsItemHovered`](@ref) or layout primitives such as [`SameLine`](@ref) on whole group, etc.
"""
BeginGroup() = igBeginGroup()
"""
EndGroup()
See [`BeginGroup`](@ref).
"""
EndGroup() = igEndGroup()
"""
GetCursorPos() -> ImVec2
Return cursor position which is relative to window position.
"""
function GetCursorPos()
x = Ref{ImVec2}()
igGetCursorPos(x)
return x[]
end
"""
GetCursorPosX() -> Cfloat
"""
GetCursorPosX() = igGetCursorPosX()
"""
GetCursorPosY() -> Cfloat
"""
GetCursorPosY() = igGetCursorPosY()
"""
SetCursorPos(x, y)
SetCursorPos(local_pos)
"""
SetCursorPos(local_pos) = igSetCursorPos(local_pos)
SetCursorPos(x, y) = SetCursorPos(ImVec2(x,y))
"""
SetCursorPosX(local_x)
"""
SetCursorPosX(local_x) = igSetCursorPosX(local_x)
"""
SetCursorPosX(local_y)
"""
SetCursorPosY(local_y) = igSetCursorPosY(local_y)
"""
GetCursorStartPos() -> ImVec2
Return initial cursor position in window coordinates.
"""
function GetCursorStartPos()
x = Ref{ImVec2}()
igGetCursorStartPos(x)
return x[]
end
"""
GetCursorScreenPos() -> ImVec2
Return cursor position in absolute screen coordinates [0..io.DisplaySize].
This is useful to work with `ImDrawList` API.
"""
function GetCursorScreenPos()
x = Ref{ImVec2}()
igGetCursorScreenPos(x)
return x[]
end
"""
SetCursorScreenPos(pos)
SetCursorScreenPos(x, y)
Set cursor position in absolute screen coordinates [0..io.DisplaySize].
"""
SetCursorScreenPos(pos) = igSetCursorScreenPos(pos)
SetCursorScreenPos(x, y) = SetCursorScreenPos(ImVec2(x,y))
"""
AlignTextToFramePadding()
Vertically align upcoming text baseline to `FramePadding.y` so that it will align properly to
regularly framed items (call if you have text on a line before a framed item).
"""
AlignTextToFramePadding() = igAlignTextToFramePadding()
"""
GetTextLineHeight() -> Cfloat
Return `FontSize`.
"""
GetTextLineHeight() = igGetTextLineHeight()
"""
GetTextLineHeightWithSpacing() -> Cfloat
Return `FontSize + ImGuiStyle.ItemSpacing.y` (distance in pixels between 2 consecutive lines of text).
"""
GetTextLineHeightWithSpacing() = igGetTextLineHeightWithSpacing()
"""
GetFrameHeight() -> Cfloat
Return `FontSize + ImGuiStyle.FramePadding.y * 2`.
"""
GetFrameHeight() = igGetFrameHeight()
"""
GetFrameHeightWithSpacing() -> Cfloat
Return `FontSize + ImGuiStyle.FramePadding.y * 2 + ImGuiStyle.ItemSpacing.y` (distance
in pixels between 2 consecutive lines of framed widgets).
"""
GetFrameHeightWithSpacing() = igGetFrameHeightWithSpacing()
###################################### ID stack/scopes #####################################
"""
PushID(ptr_id::Ptr)
PushID(int_id::Integer)
PushID(str_id::AbstractString)
PushID(str_id_begin::AbstractString, str_id_end::AbstractString)
Push identifier into the ID stack. IDs are hash of the entire stack!
!!! note
Read the FAQ for more details about how ID are handled in dear imgui. If you are creating
widgets in a loop you most likely want to push a unique identifier (e.g. object pointer, loop index)
to uniquely differentiate them. You can also use the "##foobar" syntax within widget label
to distinguish them from each others.
!!! tip "FAQ"
Q: How can I have multiple widgets with the same label or without a label?
Q: I have multiple widgets with the same label, and only the first one works. Why is that?
A: A primer on labels and the ID Stack...
Dear ImGui internally need to uniquely identify UI elements.
Elements that are typically not clickable (such as calls to the Text functions) don't need an ID.
Interactive widgets (such as calls to Button buttons) need a unique ID.
Unique ID are used internally to track active widgets and occasionally associate state to widgets.
Unique ID are implicitly built from the hash of multiple elements that identify the "path" to the UI element.
- Unique ID are often derived from a string label:
```
CImGui.Button("OK") # Label = "OK", ID = hash of (..., "OK")
CImGui.Button("Cancel") # Label = "Cancel", ID = hash of (..., "Cancel")
```
- ID are uniquely scoped within windows, tree nodes, etc. which all pushes to the ID stack.
Having two buttons labeled "OK" in different windows or different tree locations is fine.
We used "..." above to signify whatever was already pushed to the ID stack previously:
```
CImGui.Begin("MyWindow")
CImGui.Button("OK") # Label = "OK", ID = hash of ("MyWindow", "OK")
CImGui.End()
```
- If you have a same ID twice in the same location, you'll have a conflict:
```
CImGui.Button("OK")
CImGui.Button("OK") # ID collision! Interacting with either button will trigger the first one.
```
Fear not! this is easy to solve and there are many ways to solve it!
- Solving ID conflict in a simple/local context:
When passing a label you can optionally specify extra ID information within string itself.
Use `##` to pass a complement to the ID that won't be visible to the end-user.
This helps solving the simple collision cases when you know e.g. at compilation time which items
are going to be created:
```
CImGui.Begin("MyWindow")
CImGui.Button("Play") # Label = "Play", ID = hash of ("MyWindow", "Play")
CImGui.Button("Play##foo1") # Label = "Play", ID = hash of ("MyWindow", "Play##foo1") # Different from above
CImGui.Button("Play##foo2") # Label = "Play", ID = hash of ("MyWindow", "Play##foo2") # Different from above
CImGui.End()
```
- If you want to completely hide the label, but still need an ID:
```
CImGui.Checkbox("##On", &b) # Label = "", ID = hash of (..., "##On") # No visible label, just a checkbox!
```
- Occasionally/rarely you might want change a label while preserving a constant ID. This allows
you to animate labels. For example you may want to include varying information in a window title bar,
but windows are uniquely identified by their ID. Use `###` to pass a label that isn't part of ID:
```
CImGui.Button("Hello###ID") # Label = "Hello", ID = hash of (..., "ID")
CImGui.Button("World###ID") # Label = "World", ID = hash of (..., "ID") # Same as above, even though the label looks different
buf = @sprintf("My game (%f FPS)###MyGame", fps)
CImGui.Begin(buf) # Variable title, ID = hash of "MyGame"
```
- Solving ID conflict in a more general manner:
Use `PushID()` / `PopID()` to create scopes and manipulate the ID stack, as to avoid ID conflicts
within the same window. This is the most convenient way of distinguishing ID when iterating and
creating many UI elements programmatically.
You can push a pointer, a string or an integer value into the ID stack.
Remember that ID are formed from the concatenation of _everything_ in the ID stack!
```
CImGui.Begin("Window")
for i = 0:100-1
CImGui.PushID(i) # Push i to the id tack
CImGui.Button("Click") # Label = "Click", ID = Hash of ("Window", i, "Click")
CImGui.PopID()
end
End()
```
- More example showing that you can stack multiple prefixes into the ID stack:
```
CImGui.Button("Click") # Label = "Click", ID = hash of (..., "Click")
CImGui.PushID("node")
CImGui.Button("Click") # Label = "Click", ID = hash of (..., "node", "Click")
CImGui.PushID(my_ptr)
CImGui.Button("Click") # Label = "Click", ID = hash of (..., "node", my_ptr, "Click")
CImGui.PopID()
CImGui.PopID()
```
- Tree nodes implicitly creates a scope for you by calling `PushID()`.
```
CImGui.Button("Click") # Label = "Click", ID = hash of (..., "Click")
if CImGui.TreeNode("node")
CImGui.Button("Click") # Label = "Click", ID = hash of (..., "node", "Click")
CImGui.TreePop()
end
```
- When working with trees, ID are used to preserve the open/close state of each tree node.
Depending on your use cases you may want to use strings, indices or pointers as ID.
* e.g. when following a single pointer that may change over time, using a static string as ID
will preserve your node open/closed state when the targeted object change.
* e.g. when displaying a list of objects, using indices or pointers as ID will preserve the
node open/closed state differently. See what makes more sense in your situation!
"""
PushID(str_id::AbstractString) = igPushID_Str(str_id)
PushID(str_id_begin::AbstractString, str_id_end::AbstractString) = igPushID_StrStr(str_id_begin, str_id_end)
PushID(ptr_id::Ptr) = igPushID_Ptr(ptr_id)
PushID(int_id::Integer) = igPushID_Int(int_id)
"""
PopID()
See [`PushID`](@ref).