-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdemo.go
More file actions
2101 lines (1883 loc) · 70 KB
/
Copy pathdemo.go
File metadata and controls
2101 lines (1883 loc) · 70 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
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
package imgui
import (
"fmt"
"math"
)
// HelpMarker Helper to display a little (?) mark which shows a tooltip when hovered.
// In your own code you may want to display an actual icon if you are using a merged icon fonts (see docs/FONTS.md)
func HelpMarker(desc string) {
TextDisabled(" (?)")
// TODO: this is never true for some reason
if IsItemHovered(0) {
BeginTooltip()
PushTextWrapPos(GetFontSize() * 35.0)
TextUnformatted(desc)
PopTextWrapPos()
EndTooltip()
}
}
// ShowUserGuide Helper to display basic user controls.
func ShowUserGuide() {
var io = GetIO()
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.")
if io.FontAllowUserScaling {
BulletText("CTRL+Mouse Wheel to zoom window contents.")
}
BulletText("While inputing text:\n")
Indent(0)
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.")
Unindent(0)
BulletText("With keyboard navigation enabled:")
Indent(0)
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.")
Unindent(0)
}
var demoState struct {
// Examples Apps (accessible from the "Examples" menu)
show_app_main_menu_bar, show_app_documents,
show_app_console, show_app_log, show_app_layout,
show_app_property_editor, show_app_long_text,
show_app_auto_resize, show_app_constrained_resize,
show_app_simple_overlay, show_app_fullscreen,
show_app_window_titles, show_app_custom_rendering bool
// Dear ImGui Apps (accessible from the "Tools" menu)
show_app_metrics, show_app_style_editor, show_app_about bool
// Demonstrate the various window flags. Typically you would just use the default!
no_titlebar, no_scrollbar, no_menu, no_move, no_resize,
no_collapse, no_close, no_nav, no_background,
no_bring_to_front, unsaved_document bool
// Layout & Scrolling
show_scrolling_decoration bool
show_scrolling_track bool
scrolling_track_item int
}
// ShowDemoWindow Demonstrate most Dear ImGui features (this is big function!)
// You may execute this function to experiment with the UI and understand what it does.
// You may then search for keywords in the code when you are interested by a specific feature.
// create Demo window. demonstrate most ImGui features. call this to learn about the library! try to make it always available in your application!
func ShowDemoWindow(p_open *bool) {
// Exceptionally add an extra assert here for people confused about initial Dear ImGui setup
// Most ImGui functions would normally just crash if the context is missing.
IM_ASSERT_USER_ERROR(GetCurrentContext() != nil, "Missing dear imgui context. Refer to examples app!")
if demoState.show_app_main_menu_bar {
//ShowExampleAppMainMenuBar();
}
if demoState.show_app_documents {
//ShowExampleAppDocuments(&state.show_app_documents);
}
if demoState.show_app_console {
//ShowExampleAppConsole(&show_app_console);
}
if demoState.show_app_log {
//ShowExampleAppLog(&show_app_log);
}
if demoState.show_app_layout {
//ShowExampleAppLayout(&show_app_layout);
}
if demoState.show_app_property_editor {
//ShowExampleAppPropertyEditor(&show_app_property_editor);
}
if demoState.show_app_long_text {
//ShowExampleAppLongText(&show_app_long_text);
}
if demoState.show_app_auto_resize {
//ShowExampleAppAutoResize(&show_app_auto_resize);
}
if demoState.show_app_constrained_resize {
//ShowExampleAppConstrainedResize(&show_app_constrained_resize);
}
if demoState.show_app_simple_overlay {
//ShowExampleAppSimpleOverlay(&show_app_simple_overlay);
}
if demoState.show_app_fullscreen {
//ShowExampleAppFullscreen(&show_app_fullscreen);
}
if demoState.show_app_window_titles {
//ShowExampleAppWindowTitles(&show_app_window_titles);
}
if demoState.show_app_custom_rendering {
//ShowExampleAppCustomRendering(&show_app_custom_rendering);
}
if demoState.show_app_metrics {
ShowMetricsWindow(&demoState.show_app_metrics)
}
if demoState.show_app_about {
ShowAboutWindow(&demoState.show_app_about)
}
if demoState.show_app_style_editor {
Begin("Dear ImGui Style Editor", &demoState.show_app_style_editor, 0)
ShowStyleEditor(nil)
End()
}
var window_flags ImGuiWindowFlags = 0
if demoState.no_titlebar {
window_flags |= ImGuiWindowFlags_NoTitleBar
}
if demoState.no_scrollbar {
window_flags |= ImGuiWindowFlags_NoScrollbar
}
if !demoState.no_menu {
window_flags |= ImGuiWindowFlags_MenuBar
}
if demoState.no_move {
window_flags |= ImGuiWindowFlags_NoMove
}
if demoState.no_resize {
window_flags |= ImGuiWindowFlags_NoResize
}
if demoState.no_collapse {
window_flags |= ImGuiWindowFlags_NoCollapse
}
if demoState.no_nav {
window_flags |= ImGuiWindowFlags_NoNav
}
if demoState.no_background {
window_flags |= ImGuiWindowFlags_NoBackground
}
if demoState.no_bring_to_front {
window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus
}
if demoState.unsaved_document {
window_flags |= ImGuiWindowFlags_UnsavedDocument
}
if demoState.no_close {
p_open = nil // Don't pass our bool* to Begin
}
// We specify a default position/size in case there's no data in the .ini file.
// We only do it to make the demo applications a little more welcoming, but typically this isn't required.
var main_viewport = GetMainViewport()
SetNextWindowPos(NewImVec2(main_viewport.WorkPos.X()+650, main_viewport.WorkPos.Y()+20), ImGuiCond_FirstUseEver, ImVec2{})
SetNextWindowSize(NewImVec2(550, 680), ImGuiCond_FirstUseEver)
// Main body of the Demo window starts here.
if !Begin("Dear ImGui Demo", p_open, window_flags) {
// Early out if the window is collapsed, as an optimization.
End()
return
}
// Most "big" widgets share a common width settings by default. See 'Demo->Layout->Widgets Width' for details.
// e.g. Use 2/3 of the space for widgets and 1/3 for labels (right align)
//PushItemWidth(-GetWindowWidth() * 0.35f);
// e.g. Leave a fixed amount of width for labels (by passing a negative value), the rest goes to widgets.
PushItemWidth(GetFontSize() * -12)
// Menu Bar
if BeginMenuBar() {
if BeginMenu("Menu", true) {
//ShowExampleMenuFile()
EndMenu()
}
if BeginMenu("Examples", true) {
MenuItem("Main menu bar", "", &demoState.show_app_main_menu_bar, true)
MenuItem("Console", "", &demoState.show_app_console, true)
MenuItem("Log", "", &demoState.show_app_log, true)
MenuItem("Simple layout", "", &demoState.show_app_layout, true)
MenuItem("Property editor", "", &demoState.show_app_property_editor, true)
MenuItem("Long text display", "", &demoState.show_app_long_text, true)
MenuItem("Auto-resizing window", "", &demoState.show_app_auto_resize, true)
MenuItem("Constrained-resizing window", "", &demoState.show_app_constrained_resize, true)
MenuItem("Simple overlay", "", &demoState.show_app_simple_overlay, true)
MenuItem("Fullscreen window", "", &demoState.show_app_fullscreen, true)
MenuItem("Manipulating window titles", "", &demoState.show_app_window_titles, true)
MenuItem("Custom rendering", "", &demoState.show_app_custom_rendering, true)
MenuItem("Documents", "", &demoState.show_app_documents, true)
EndMenu()
}
if BeginMenu("Tools", true) {
MenuItem("Metrics/Debugger", "", &demoState.show_app_metrics, true)
MenuItem("Style Editor", "", &demoState.show_app_style_editor, true)
MenuItem("About Dear ImGui", "", &demoState.show_app_about, true)
EndMenu()
}
EndMenuBar()
}
Text("dear imgui says hello. (%s)", IMGUI_VERSION)
Spacing()
if CollapsingHeader("Help", 0) {
Text("ABOUT THIS DEMO:")
BulletText("Sections below are demonstrating many aspects of the library.")
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/Debugger (general purpose Dear ImGui debugging tool).")
Separator()
Text("PROGRAMMER GUIDE:")
BulletText("See the ShowDemoWindow() code in imgui_demo.cpp. <- you are here!")
BulletText("See comments in cpp.")
BulletText("See example applications in the examples/ folder.")
BulletText("Read the FAQ at http://www.dearorg/faq/")
BulletText("Set 'io.ConfigFlags |= NavEnableKeyboard' for keyboard controls.")
BulletText("Set 'io.ConfigFlags |= NavEnableGamepad' for gamepad controls.")
Separator()
Text("USER GUIDE:")
ShowUserGuide()
}
if CollapsingHeader("Configuration", 0) {
var io = GetIO()
if TreeNode("Configuration##2") {
CheckboxFlagsInt("io.ConfigFlags: NavEnableKeyboard", (*int32)(&io.ConfigFlags), int32(ImGuiConfigFlags_NavEnableKeyboard))
SameLine(0, 0)
HelpMarker("Enable keyboard controls.")
CheckboxFlagsInt("io.ConfigFlags: NavEnableGamepad", (*int32)(&io.ConfigFlags), int32(ImGuiConfigFlags_NavEnableGamepad))
SameLine(0, 0)
HelpMarker("Enable gamepad controls. Require backend to set io.BackendFlags |= ImGuiBackendFlags_HasGamepad.\n\nRead instructions in cpp for details.")
CheckboxFlagsInt("io.ConfigFlags: NavEnableSetMousePos", (*int32)(&io.ConfigFlags), int32(ImGuiConfigFlags_NavEnableSetMousePos))
SameLine(0, 0)
HelpMarker("Instruct navigation to move the mouse cursor. See comment for ImGuiConfigFlags_NavEnableSetMousePos.")
CheckboxFlagsInt("io.ConfigFlags: NoMouse", (*int32)(&io.ConfigFlags), int32(ImGuiConfigFlags_NoMouse))
if io.ConfigFlags&ImGuiConfigFlags_NoMouse != 0 {
// The "NoMouse" option can get us stuck with a disabled mouse! Let's provide an alternative way to fix it:
if math.Mod((float64)(GetTime()), 0.40) < 0.20 {
SameLine(0, 0)
Text("<<PRESS SPACE TO DISABLE>>")
}
if IsKeyPressed(GetKeyIndex(ImGuiKey_Space), true) {
io.ConfigFlags &= ^ImGuiConfigFlags_NoMouse
}
}
CheckboxFlagsInt("io.ConfigFlags: NoMouseCursorChange", (*int32)(&io.ConfigFlags), int32(ImGuiConfigFlags_NoMouseCursorChange))
SameLine(0, 0)
HelpMarker("Instruct backend to not alter mouse cursor shape and visibility.")
Checkbox("io.ConfigInputTextCursorBlink", &io.ConfigInputTextCursorBlink)
SameLine(0, 0)
HelpMarker("Enable blinking cursor (optional as some users consider it to be distracting)")
Checkbox("io.ConfigDragClickToInputText", &io.ConfigDragClickToInputText)
SameLine(0, 0)
HelpMarker("Enable turning DragXXX widgets into text input with a simple mouse click-release (without moving).")
Checkbox("io.ConfigWindowsResizeFromEdges", &io.ConfigWindowsResizeFromEdges)
SameLine(0, 0)
HelpMarker("Enable resizing of windows from their edges and from the lower-left corner.\nThis requires (io.BackendFlags & ImGuiBackendFlags_HasMouseCursors) because it needs mouse cursor feedback.")
Checkbox("io.ConfigWindowsMoveFromTitleBarOnly", &io.ConfigWindowsMoveFromTitleBarOnly)
Checkbox("io.MouseDrawCursor", &io.MouseDrawCursor)
SameLine(0, 0)
HelpMarker("Instruct Dear ImGui to render a mouse cursor itself. Note that a mouse cursor rendered via your application GPU rendering path will feel more laggy than hardware cursor, but will be more in sync with your other visuals.\n\nSome desktop applications may use both kinds of cursors (e.g. enable software cursor only when resizing/dragging something).")
Text("Also see Style->Rendering for rendering options.")
TreePop()
Separator()
}
if TreeNode("Backend Flags") {
HelpMarker(
"Those flags are set by the backends (imgui_impl_xxx files) to specify their capabilities.\n" +
"Here we expose them as read-only fields to avoid breaking interactions with your backend.")
// Make a local copy to avoid modifying actual backend flags.
var backend_flags = io.BackendFlags
CheckboxFlagsInt("io.BackendFlags: HasGamepad", (*int32)(&backend_flags), int32(ImGuiBackendFlags_HasGamepad))
CheckboxFlagsInt("io.BackendFlags: HasMouseCursors", (*int32)(&backend_flags), int32(ImGuiBackendFlags_HasMouseCursors))
CheckboxFlagsInt("io.BackendFlags: HasSetMousePos", (*int32)(&backend_flags), int32(ImGuiBackendFlags_HasSetMousePos))
CheckboxFlagsInt("io.BackendFlags: RendererHasVtxOffset", (*int32)(&backend_flags), int32(ImGuiBackendFlags_RendererHasVtxOffset))
TreePop()
Separator()
}
if TreeNode("Style") {
HelpMarker("The same contents can be accessed in 'Tools->Style Editor' or by calling the ShowStyleEditor() function.")
ShowStyleEditor(nil)
TreePop()
Separator()
}
if TreeNode("Capture/Logging") {
HelpMarker(
"The logging API redirects all text output so you can easily capture the content of " +
"a window or a block. Tree nodes can be automatically expanded.\n" +
"Try opening any of the contents below in this window and then click one of the \"Log To\" button.")
LogButtons()
HelpMarker("You can also call LogText() to output directly to the log without a visual output.")
if Button("Copy \"Hello, world!\" to clipboard") {
LogToClipboard(-1)
LogText("Hello, world!")
LogFinish()
}
TreePop()
}
}
if CollapsingHeader("Window options", 0) {
if BeginTable("split", 3, 0, ImVec2{}, 0) {
TableNextColumn()
Checkbox("No titlebar", &demoState.no_titlebar)
TableNextColumn()
Checkbox("No scrollbar", &demoState.no_scrollbar)
TableNextColumn()
Checkbox("No menu", &demoState.no_menu)
TableNextColumn()
Checkbox("No move", &demoState.no_move)
TableNextColumn()
Checkbox("No resize", &demoState.no_resize)
TableNextColumn()
Checkbox("No collapse", &demoState.no_collapse)
TableNextColumn()
Checkbox("No close", &demoState.no_close)
TableNextColumn()
Checkbox("No nav", &demoState.no_nav)
TableNextColumn()
Checkbox("No background", &demoState.no_background)
TableNextColumn()
Checkbox("No bring to front", &demoState.no_bring_to_front)
TableNextColumn()
Checkbox("Unsaved document", &demoState.unsaved_document)
EndTable()
}
}
// All demo contents
ShowDemoWindowWidgets()
ShowDemoWindowLayout()
ShowDemoWindowPopups()
//ShowDemoWindowTables()
ShowDemoWindowMisc()
// End of ShowDemoWindow()
PopItemWidth()
End()
}
// ImVec4FromHSV converts HSV values to an ImVec4 color
func ImVec4FromHSV(h, s, v float) ImVec4 {
var r, g, b float
ColorConvertHSVtoRGB(h, s, v, &r, &g, &b)
return ImVec4{r, g, b, 1.0}
}
// State for ShowDemoWindowWidgets
var widgetsState struct {
// Basic
clicked int
check bool
e int
counter int
str0 []byte
str1 []byte
i0 int
f0 float
f1 float
vec4a [4]float
i1, i2 int
f1drag, f2drag float
i1slider int
f1slider float
f2slider float
angle float
elem int
col1 [3]float
col2 [4]float
item_current_combo int
item_current_list int
// Trees
base_flags ImGuiTreeNodeFlags
align_label_with_current_x_position bool
test_drag_and_drop bool
selection_mask int
// Collapsing Headers
closable_group bool
// Text
wrap_width float
// Images
pressed_count int
// Combo (advanced)
combo_flags ImGuiComboFlags
combo_item_current_idx int
// List boxes
listbox_item_current_idx int
// Selectables
selectable_basic [5]bool
selectable_single int
selectable_multiple [5]bool
selectable_render [3]bool
selectable_columns [10]bool
selectable_grid [4][4]bool
// Tabs
tab_bar_flags ImGuiTabBarFlags
tabs_opened [4]bool
// Plots
plots_animate bool
plots_values [90]float
plots_offset int
plots_refresh float64
plots_phase float
plots_progress float
plots_progress_dir float
// Color/Picker Widgets
color_picker_color ImVec4
color_alpha_preview bool
color_alpha_half_preview bool
color_drag_and_drop bool
color_options_menu bool
color_hdr bool
color_no_border bool
color_alpha bool
color_alpha_bar bool
color_side_preview bool
color_ref_color bool
color_ref_color_v ImVec4
color_display_mode int
color_picker_mode int
color_hsv ImVec4
// Drag/Slider Flags
slider_flags ImGuiSliderFlags
drag_f float
drag_i int
slider_f float
slider_i int
// Range Widgets
range_begin float
range_end float
range_begin_i int
range_end_i int
// Disable all
disable_all bool
}
func init() {
// Initialize default values
widgetsState.check = true
widgetsState.str0 = []byte("Hello, world!")
widgetsState.str1 = []byte{}
widgetsState.i0 = 123
widgetsState.f0 = 0.001
widgetsState.f1 = 1.0e10
widgetsState.vec4a = [4]float{0.10, 0.20, 0.30, 0.44}
widgetsState.i1 = 50
widgetsState.i2 = 42
widgetsState.f1drag = 1.00
widgetsState.f2drag = 0.0067
widgetsState.f1slider = 0.123
widgetsState.col1 = [3]float{1.0, 0.0, 0.2}
widgetsState.col2 = [4]float{0.4, 0.7, 0.0, 0.5}
widgetsState.item_current_list = 1
widgetsState.base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth
widgetsState.selection_mask = 1 << 2
widgetsState.closable_group = true
widgetsState.wrap_width = 200.0
// Selectables
widgetsState.selectable_basic[1] = true
widgetsState.selectable_single = -1
// Tabs
widgetsState.tab_bar_flags = ImGuiTabBarFlags_Reorderable
widgetsState.tabs_opened = [4]bool{true, true, true, true}
// Plots
widgetsState.plots_animate = true
widgetsState.plots_progress_dir = 1.0
// Color/Picker Widgets
widgetsState.color_picker_color = ImVec4{114.0 / 255.0, 144.0 / 255.0, 154.0 / 255.0, 200.0 / 255.0}
widgetsState.color_alpha_preview = true
widgetsState.color_drag_and_drop = true
widgetsState.color_options_menu = true
widgetsState.color_alpha = true
widgetsState.color_alpha_bar = true
widgetsState.color_side_preview = true
widgetsState.color_ref_color_v = ImVec4{1.0, 0.0, 1.0, 0.5}
widgetsState.color_hsv = ImVec4{0.23, 1.0, 1.0, 1.0}
// Drag/Slider Flags
widgetsState.drag_f = 0.5
widgetsState.drag_i = 50
widgetsState.slider_f = 0.5
widgetsState.slider_i = 50
// Range Widgets
widgetsState.range_begin = 10
widgetsState.range_end = 90
widgetsState.range_begin_i = 100
widgetsState.range_end_i = 1000
}
func ShowDemoWindowWidgets() {
if !CollapsingHeader("Widgets", 0) {
return
}
if widgetsState.disable_all {
BeginDisabled(true)
}
if TreeNode("Basic") {
if Button("Button") {
widgetsState.clicked++
}
if widgetsState.clicked&1 != 0 {
SameLine(0, 0)
Text("Thanks for clicking me!")
}
Checkbox("checkbox", &widgetsState.check)
RadioButtonInt("radio a", &widgetsState.e, 0)
SameLine(0, 0)
RadioButtonInt("radio b", &widgetsState.e, 1)
SameLine(0, 0)
RadioButtonInt("radio c", &widgetsState.e, 2)
// Color buttons, demonstrate using PushID() to add unique identifier in the ID stack, and changing style.
for i := int(0); i < 7; i++ {
if i > 0 {
SameLine(0, 0)
}
PushID(i)
col := ImVec4FromHSV(float(i)/7.0, 0.6, 0.6)
PushStyleColorVec(ImGuiCol_Button, &col)
col2 := ImVec4FromHSV(float(i)/7.0, 0.7, 0.7)
PushStyleColorVec(ImGuiCol_ButtonHovered, &col2)
col3 := ImVec4FromHSV(float(i)/7.0, 0.8, 0.8)
PushStyleColorVec(ImGuiCol_ButtonActive, &col3)
Button("Click")
PopStyleColor(3)
PopID()
}
// Use AlignTextToFramePadding() to align text baseline to the baseline of framed widgets elements
AlignTextToFramePadding()
Text("Hold to repeat:")
SameLine(0, 0)
// Arrow buttons with Repeater
spacing := GetStyle().ItemInnerSpacing.x
PushButtonRepeat(true)
if ArrowButton("##left", ImGuiDir_Left) {
widgetsState.counter--
}
SameLine(0.0, spacing)
if ArrowButton("##right", ImGuiDir_Right) {
widgetsState.counter++
}
PopButtonRepeat()
SameLine(0, 0)
Text("%d", widgetsState.counter)
Text("Hover over me")
if IsItemHovered(0) {
SetTooltip("I am a tooltip")
}
SameLine(0, 0)
Text("- or me")
if IsItemHovered(0) {
BeginTooltip()
Text("I am a fancy tooltip")
arr := []float{0.6, 0.1, 1.0, 0.5, 0.92, 0.1, 0.2}
PlotLines("Curve", arr, int(len(arr)), 0, "", FLT_MAX, FLT_MAX, ImVec2{}, 1)
EndTooltip()
}
Separator()
LabelText("label", "Value")
{
// Using the _simplified_ one-liner Combo() api here
items := []string{"AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIIIIII", "JJJJ", "KKKKKKK"}
Combo("combo", &widgetsState.item_current_combo, items, int(len(items)), -1)
SameLine(0, 0)
HelpMarker("Using the simplified one-liner Combo API here.\nRefer to the \"Combo\" section below for an explanation of how to use the more flexible and general BeginCombo/EndCombo API.")
}
{
InputText("input text", &widgetsState.str0, 0, nil, nil)
SameLine(0, 0)
HelpMarker(
"USER:\n" +
"Hold SHIFT or use mouse to select text.\n" +
"CTRL+Left/Right to word jump.\n" +
"CTRL+A or double-click to select all.\n" +
"CTRL+X,CTRL+C,CTRL+V clipboard.\n" +
"CTRL+Z,CTRL+Y undo/redo.\n" +
"ESCAPE to revert.\n\n" +
"PROGRAMMER:\n" +
"You can use the ImGuiInputTextFlags_CallbackResize facility if you need to wire InputText() " +
"to a dynamic string type. See misc/cpp/imgui_stdlib.h for an example (this is not demonstrated " +
"in imgui_demo.cpp).")
InputTextWithHint("input text (w/ hint)", "enter text here", &widgetsState.str1, 0, nil, nil)
InputInt("input int", &widgetsState.i0, 1, 100, 0)
SameLine(0, 0)
HelpMarker(
"You can apply arithmetic operators +,*,/ on numerical values.\n" +
" e.g. [ 100 ], input '*2', result becomes [ 200 ]\n" +
"Use +- to subtract.")
InputFloat("input float", &widgetsState.f0, 0.01, 1.0, "%.3f", 0)
InputFloat("input scientific", &widgetsState.f1, 0.0, 0.0, "%e", 0)
SameLine(0, 0)
HelpMarker("You can input value using the scientific notation,\n e.g. \"1e+8\" becomes \"100000000\".")
var vec3 = [3]float{widgetsState.vec4a[0], widgetsState.vec4a[1], widgetsState.vec4a[2]}
InputFloat3("input float3", &vec3, "%.3f", 0)
widgetsState.vec4a[0], widgetsState.vec4a[1], widgetsState.vec4a[2] = vec3[0], vec3[1], vec3[2]
}
{
DragInt("drag int", &widgetsState.i1, 1, 0, 0, "%d", 0)
SameLine(0, 0)
HelpMarker(
"Click and drag to edit value.\n" +
"Hold SHIFT/ALT for faster/slower edit.\n" +
"Double-click or CTRL+click to input value.")
DragInt("drag int 0..100", &widgetsState.i2, 1, 0, 100, "%d%%", ImGuiSliderFlags_AlwaysClamp)
DragFloat("drag float", &widgetsState.f1drag, 0.005, 0.0, 0.0, "%.3f", 0)
DragFloat("drag small float", &widgetsState.f2drag, 0.0001, 0.0, 0.0, "%.06f ns", 0)
}
{
SliderInt("slider int", &widgetsState.i1slider, -1, 3, "%d", 0)
SameLine(0, 0)
HelpMarker("CTRL+click to input value.")
SliderFloat("slider float", &widgetsState.f1slider, 0.0, 1.0, "ratio = %.3f", 0)
SliderFloat("slider float (log)", &widgetsState.f2slider, -10.0, 10.0, "%.4f", ImGuiSliderFlags_Logarithmic)
SliderAngle("slider angle", &widgetsState.angle, -360.0, 360.0, "%.0f deg", 0)
// Using the format string to display a name instead of an integer.
elems_names := []string{"Fire", "Earth", "Air", "Water"}
elem_name := "Unknown"
if widgetsState.elem >= 0 && widgetsState.elem < int(len(elems_names)) {
elem_name = elems_names[widgetsState.elem]
}
SliderInt("slider enum", &widgetsState.elem, 0, int(len(elems_names)-1), elem_name, 0)
SameLine(0, 0)
HelpMarker("Using the format string parameter to display a name instead of the underlying integer.")
}
{
ColorEdit3("color 1", &widgetsState.col1, 0)
SameLine(0, 0)
HelpMarker(
"Click on the color square to open a color picker.\n" +
"Click and hold to use drag and drop.\n" +
"Right-click on the color square to show options.\n" +
"CTRL+click on individual component to input value.\n")
ColorEdit4("color 2", &widgetsState.col2, 0)
}
{
// Using the _simplified_ one-liner ListBox() api here
items := []string{"Apple", "Banana", "Cherry", "Kiwi", "Mango", "Orange", "Pineapple", "Strawberry", "Watermelon"}
ListBox("listbox", &widgetsState.item_current_list, items, int(len(items)), 4)
SameLine(0, 0)
HelpMarker("Using the simplified one-liner ListBox API here.\nRefer to the \"List boxes\" section below for an explanation of how to use the more flexible and general BeginListBox/EndListBox API.")
}
TreePop()
}
if TreeNode("Trees") {
if TreeNode("Basic trees") {
for i := int(0); i < 5; i++ {
// Use SetNextItemOpen() so set the default state of a node to be open.
if i == 0 {
SetNextItemOpen(true, ImGuiCond_Once)
}
if TreeNodeInterface(i, "Child %d", i) {
Text("blah blah")
SameLine(0, 0)
if SmallButton("button") {
}
TreePop()
}
}
TreePop()
}
if TreeNode("Advanced, with Selectable nodes") {
HelpMarker(
"This is a more typical looking tree with selectable nodes.\n" +
"Click to select, CTRL+Click to toggle, click on arrows or double-click to open.")
CheckboxFlagsInt("ImGuiTreeNodeFlags_OpenOnArrow", (*int32)(&widgetsState.base_flags), int32(ImGuiTreeNodeFlags_OpenOnArrow))
CheckboxFlagsInt("ImGuiTreeNodeFlags_OpenOnDoubleClick", (*int32)(&widgetsState.base_flags), int32(ImGuiTreeNodeFlags_OpenOnDoubleClick))
CheckboxFlagsInt("ImGuiTreeNodeFlags_SpanAvailWidth", (*int32)(&widgetsState.base_flags), int32(ImGuiTreeNodeFlags_SpanAvailWidth))
SameLine(0, 0)
HelpMarker("Extend hit area to all available width instead of allowing more items to be laid out after the node.")
CheckboxFlagsInt("ImGuiTreeNodeFlags_SpanFullWidth", (*int32)(&widgetsState.base_flags), int32(ImGuiTreeNodeFlags_SpanFullWidth))
Checkbox("Align label with current X position", &widgetsState.align_label_with_current_x_position)
Checkbox("Test tree node as drag source", &widgetsState.test_drag_and_drop)
Text("Hello!")
if widgetsState.align_label_with_current_x_position {
Unindent(GetTreeNodeToLabelSpacing())
}
node_clicked := int(-1)
for i := int(0); i < 6; i++ {
node_flags := widgetsState.base_flags
is_selected := (widgetsState.selection_mask & (1 << i)) != 0
if is_selected {
node_flags |= ImGuiTreeNodeFlags_Selected
}
if i < 3 {
// Items 0..2 are Tree Node
node_open := TreeNodeInterfaceEx(i, node_flags, "Selectable Node %d", i)
if IsItemClicked(0) {
node_clicked = int(i)
}
if widgetsState.test_drag_and_drop && BeginDragDropSource(0) {
SetDragDropPayload("_TREENODE", nil, 0, 0)
Text("This is a drag and drop source")
EndDragDropSource()
}
if node_open {
BulletText("Blah blah\nBlah Blah")
TreePop()
}
} else {
// Items 3..5 are Tree Leaves
node_flags |= ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen
TreeNodeInterfaceEx(i, node_flags, "Selectable Leaf %d", i)
if IsItemClicked(0) {
node_clicked = int(i)
}
if widgetsState.test_drag_and_drop && BeginDragDropSource(0) {
SetDragDropPayload("_TREENODE", nil, 0, 0)
Text("This is a drag and drop source")
EndDragDropSource()
}
}
}
if node_clicked != -1 {
// Update selection state
if GetIO().KeyCtrl {
widgetsState.selection_mask ^= 1 << node_clicked // CTRL+click to toggle
} else {
widgetsState.selection_mask = 1 << node_clicked // Click to single-select
}
}
if widgetsState.align_label_with_current_x_position {
Indent(GetTreeNodeToLabelSpacing())
}
TreePop()
}
TreePop()
}
if TreeNode("Collapsing Headers") {
Checkbox("Show 2nd header", &widgetsState.closable_group)
if CollapsingHeader("Header", 0) {
Text("IsItemHovered: %d", bool2int(IsItemHovered(0)))
for i := int(0); i < 5; i++ {
Text("Some content %d", i)
}
}
if CollapsingHeaderVisible("Header with a close button", &widgetsState.closable_group, 0) {
Text("IsItemHovered: %d", bool2int(IsItemHovered(0)))
for i := int(0); i < 5; i++ {
Text("More content %d", i)
}
}
TreePop()
}
if TreeNode("Bullets") {
BulletText("Bullet point 1")
BulletText("Bullet point 2\nOn multiple lines")
if TreeNode("Tree node") {
BulletText("Another bullet point")
TreePop()
}
Bullet()
Text("Bullet point 3 (two calls)")
Bullet()
SmallButton("Button")
TreePop()
}
if TreeNode("Text") {
if TreeNode("Colorful Text") {
// Using shortcut. You can use PushStyleColor()/PopStyleColor() for more flexibility.
pink := ImVec4{1.0, 0.0, 1.0, 1.0}
TextColored(&pink, "Pink")
yellow := ImVec4{1.0, 1.0, 0.0, 1.0}
TextColored(&yellow, "Yellow")
TextDisabled("Disabled")
SameLine(0, 0)
HelpMarker("The TextDisabled color is stored in ImGuiStyle.")
TreePop()
}
if TreeNode("Word Wrapping") {
// Using shortcut. You can use PushTextWrapPos()/PopTextWrapPos() for more flexibility.
TextWrapped(
"This text should automatically wrap on the edge of the window. The current implementation " +
"for text wrapping follows simple rules suitable for English and possibly other languages.")
Spacing()
SliderFloat("Wrap width", &widgetsState.wrap_width, -20, 600, "%.0f", 0)
draw_list := GetWindowDrawList()
for n := int(0); n < 2; n++ {
Text("Test paragraph %d:", n)
pos := GetCursorScreenPos()
marker_min := ImVec2{pos.x + widgetsState.wrap_width, pos.y}
marker_max := ImVec2{pos.x + widgetsState.wrap_width + 10, pos.y + GetTextLineHeight()}
PushTextWrapPos(GetCursorPos().x + widgetsState.wrap_width)
if n == 0 {
Text("The lazy dog is a good dog. This paragraph should fit within %.0f pixels. Testing a 1 character word. The quick brown fox jumps over the lazy dog.", widgetsState.wrap_width)
} else {
Text("aaaaaaaa bbbbbbbb, c cccccccc,dddddddd. d eeeeeeee ffffffff. gggggggg!hhhhhhhh")
}
// Draw actual text bounding box, following by marker of our expected limit
draw_list.AddRect(GetItemRectMin(), GetItemRectMax(), IM_COL32(255, 255, 0, 255), 0, 0, 1.0)
draw_list.AddRectFilled(marker_min, marker_max, IM_COL32(255, 0, 255, 255), 0, 0)
PopTextWrapPos()
}
TreePop()
}
if TreeNode("UTF-8 Text") {
TextWrapped(
"CJK text will only appears if the font was loaded with the appropriate CJK character ranges. " +
"Call io.Fonts->AddFontFromFileTTF() manually to load extra character ranges. " +
"Read docs/FONTS.md for details.")
Text("Hiragana: かきくけこ (kakikukeko)")
Text("Kanjis: 日本語 (nihongo)")
TreePop()
}
TreePop()
}
if TreeNode("Images") {
io := GetIO()
TextWrapped(
"Below we are displaying the font texture (which is the only texture we have access to in this demo). " +
"Use the 'ImTextureID' type as storage to pass pointers or identifier to your own texture data. " +
"Hover the texture for a zoomed view!")
// Display the font texture
my_tex_id := io.Fonts.TexID
my_tex_w := float(io.Fonts.TexWidth)
my_tex_h := float(io.Fonts.TexHeight)
{
Text("%.0fx%.0f", my_tex_w, my_tex_h)
pos := GetCursorScreenPos()
uv_min := ImVec2{0.0, 0.0}
uv_max := ImVec2{1.0, 1.0}
tint_col := ImVec4{1.0, 1.0, 1.0, 1.0}
border_col := ImVec4{1.0, 1.0, 1.0, 0.5}
Image(my_tex_id, ImVec2{my_tex_w, my_tex_h}, uv_min, uv_max, tint_col, border_col)
if IsItemHovered(0) {
BeginTooltip()
region_sz := float(32.0)
region_x := io.MousePos.x - pos.x - region_sz*0.5
region_y := io.MousePos.y - pos.y - region_sz*0.5
zoom := float(4.0)
if region_x < 0.0 {
region_x = 0.0
} else if region_x > my_tex_w-region_sz {
region_x = my_tex_w - region_sz
}
if region_y < 0.0 {
region_y = 0.0
} else if region_y > my_tex_h-region_sz {
region_y = my_tex_h - region_sz
}
Text("Min: (%.2f, %.2f)", region_x, region_y)
Text("Max: (%.2f, %.2f)", region_x+region_sz, region_y+region_sz)
uv0 := ImVec2{region_x / my_tex_w, region_y / my_tex_h}
uv1 := ImVec2{(region_x + region_sz) / my_tex_w, (region_y + region_sz) / my_tex_h}
Image(my_tex_id, ImVec2{region_sz * zoom, region_sz * zoom}, uv0, uv1, tint_col, border_col)
EndTooltip()
}
}
TextWrapped("And now some textured buttons..")
for i := int(0); i < 8; i++ {
PushID(i)
frame_padding := int(-1 + i)
size := ImVec2{32.0, 32.0}
uv0 := ImVec2{0.0, 0.0}
uv1 := ImVec2{32.0 / my_tex_w, 32.0 / my_tex_h}
bg_col := ImVec4{0.0, 0.0, 0.0, 1.0}
tint_col := ImVec4{1.0, 1.0, 1.0, 1.0}
if ImageButton(my_tex_id, size, uv0, uv1, frame_padding, bg_col, tint_col) {
widgetsState.pressed_count++
}
PopID()
SameLine(0, 0)
}
NewLine()
Text("Pressed %d times.", widgetsState.pressed_count)
TreePop()
}
if TreeNode("Combo") {
// Expose flags as checkbox for the demo
combo_flags_int := int(widgetsState.combo_flags)
CheckboxFlagsInt("ImGuiComboFlags_PopupAlignLeft", &combo_flags_int, int(ImGuiComboFlags_PopupAlignLeft))
widgetsState.combo_flags = ImGuiComboFlags(combo_flags_int)
SameLine(0, 0)
HelpMarker("Only makes a difference if the popup is larger than the combo")
combo_flags_int = int(widgetsState.combo_flags)
if CheckboxFlagsInt("ImGuiComboFlags_NoArrowButton", &combo_flags_int, int(ImGuiComboFlags_NoArrowButton)) {
combo_flags_int &= ^int(ImGuiComboFlags_NoPreview)
}
widgetsState.combo_flags = ImGuiComboFlags(combo_flags_int)
combo_flags_int = int(widgetsState.combo_flags)
if CheckboxFlagsInt("ImGuiComboFlags_NoPreview", &combo_flags_int, int(ImGuiComboFlags_NoPreview)) {
combo_flags_int &= ^int(ImGuiComboFlags_NoArrowButton)
}
widgetsState.combo_flags = ImGuiComboFlags(combo_flags_int)
// Using the generic BeginCombo() API
items := []string{"AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK", "LLLLLLL", "MMMM", "OOOOOOO"}
combo_preview_value := items[widgetsState.combo_item_current_idx]
if BeginCombo("combo 1", combo_preview_value, widgetsState.combo_flags) {
for n := int(0); n < int(len(items)); n++ {
is_selected := widgetsState.combo_item_current_idx == n
if Selectable(items[n], is_selected, 0, ImVec2{}) {
widgetsState.combo_item_current_idx = n
}
if is_selected {
SetItemDefaultFocus()
}
}
EndCombo()
}
TreePop()
}
if TreeNode("List boxes") {
items := []string{"AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK", "LLLLLLL", "MMMM", "OOOOOOO"}
if BeginListBox("listbox 1", ImVec2{}) {