-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdemo.cr
7395 lines (6727 loc) · 314 KB
/
demo.cr
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
# Based on https://github.com/ocornut/imgui/blob/v1.90.6/imgui_demo.cpp
require "./imgui"
require "./util"
module ImGuiDemo
include ImGui::TopLevel
def self.help_marker(desc)
ImGui.text_disabled("(?)")
if ImGui.begin_item_tooltip
ImGui.with_text_wrap_pos(ImGui.get_font_size * 35.0f32) do
ImGui.text_unformatted(desc)
end
ImGui.end_tooltip
end
end
def self.demo_marker(section)
end
ImGui.pointer_wrapper def self.show_demo_window(p_open = Pointer(Bool).null)
assert(ImGui.get_current_context != nil && "Missing Dear ImGui context. Refer to examples app!")
static show_app_main_menu_bar = false
static show_app_console = false
static show_app_custom_rendering = false
static show_app_documents = false
static show_app_log = false
static show_app_layout = false
static show_app_property_editor = false
static show_app_simple_overlay = false
static show_app_auto_resize = false
static show_app_constrained_resize = false
static show_app_fullscreen = false
static show_app_long_text = false
static show_app_window_titles = false
if show_app_main_menu_bar.val
show_example_app_main_menu_bar
end
if show_app_documents.val
show_example_app_documents(pointerof(show_app_documents.val))
end
if show_app_console.val
show_example_app_console(pointerof(show_app_console.val))
end
if show_app_custom_rendering.val
show_example_app_custom_rendering(pointerof(show_app_custom_rendering.val))
end
if show_app_log.val
show_example_app_log(pointerof(show_app_log.val))
end
if show_app_layout.val
show_example_app_layout(pointerof(show_app_layout.val))
end
if show_app_property_editor.val
show_example_app_property_editor(pointerof(show_app_property_editor.val))
end
if show_app_simple_overlay.val
show_example_app_simple_overlay(pointerof(show_app_simple_overlay.val))
end
if show_app_auto_resize.val
show_example_app_auto_resize(pointerof(show_app_auto_resize.val))
end
if show_app_constrained_resize.val
show_example_app_constrained_resize(pointerof(show_app_constrained_resize.val))
end
if show_app_fullscreen.val
show_example_app_fullscreen(pointerof(show_app_fullscreen.val))
end
if show_app_long_text.val
show_example_app_long_text(pointerof(show_app_long_text.val))
end
if show_app_window_titles.val
show_example_app_window_titles(pointerof(show_app_window_titles.val))
end
static show_tool_metrics = false
static show_tool_debug_log = false
static show_tool_id_stack_tool = false
static show_tool_style_editor = false
static show_tool_about = false
if show_tool_metrics.val
ImGui.show_metrics_window(pointerof(show_tool_metrics.val))
end
if show_tool_debug_log.val
ImGui.show_debug_log_window(pointerof(show_tool_debug_log.val))
end
if show_tool_id_stack_tool.val
ImGui.show_id_stack_tool_window(pointerof(show_tool_id_stack_tool.val))
end
if show_tool_style_editor.val
ImGui.window("crystal-imgui Style Editor", pointerof(show_tool_style_editor.val)) do
show_style_editor
end
end
if show_tool_about.val
show_about_window(pointerof(show_tool_about.val))
end
static no_titlebar = false
static no_scrollbar = false
static no_menu = false
static no_move = false
static no_resize = false
static no_collapse = false
static no_close = false
static no_nav = false
static no_background = false
static no_bring_to_front = false
static unsaved_document = false
window_flags = ImGuiWindowFlags::None
if no_titlebar.val
window_flags |= ImGuiWindowFlags::NoTitleBar
end
if no_scrollbar.val
window_flags |= ImGuiWindowFlags::NoScrollbar
end
if !no_menu.val
window_flags |= ImGuiWindowFlags::MenuBar
end
if no_move.val
window_flags |= ImGuiWindowFlags::NoMove
end
if no_resize.val
window_flags |= ImGuiWindowFlags::NoResize
end
if no_collapse.val
window_flags |= ImGuiWindowFlags::NoCollapse
end
if no_nav.val
window_flags |= ImGuiWindowFlags::NoNav
end
if no_background.val
window_flags |= ImGuiWindowFlags::NoBackground
end
if no_bring_to_front.val
window_flags |= ImGuiWindowFlags::NoBringToFrontOnFocus
end
if unsaved_document.val
window_flags |= ImGuiWindowFlags::UnsavedDocument
end
if no_close.val
p_open = Pointer(Bool).null
end
main_viewport = ImGui.get_main_viewport
ImGui.set_next_window_pos(ImVec2.new(20, main_viewport.work_pos.y + 20), ImGuiCond::FirstUseEver)
ImGui.set_next_window_size(ImVec2.new(550, 680), ImGuiCond::FirstUseEver)
if !ImGui.begin("crystal-imgui Demo", p_open, window_flags)
ImGui.end
return
end
ImGui.with_item_width(ImGui.get_font_size * -12) do
ImGui.menu_bar do
ImGui.menu("Menu") do
demo_marker("Menu/File")
show_example_menu_file
end
ImGui.menu("Examples") do
demo_marker("Menu/Examples")
ImGui.menu_item("Main menu bar", "", pointerof(show_app_main_menu_bar.val))
ImGui.separator_text("Mini apps")
ImGui.menu_item("Console", "", pointerof(show_app_console.val))
ImGui.menu_item("Custom rendering", "", pointerof(show_app_custom_rendering.val))
ImGui.menu_item("Documents", "", pointerof(show_app_documents.val))
ImGui.menu_item("Log", "", pointerof(show_app_log.val))
ImGui.menu_item("Property editor", "", pointerof(show_app_property_editor.val))
ImGui.menu_item("Simple layout", "", pointerof(show_app_layout.val))
ImGui.menu_item("Simple overlay", "", pointerof(show_app_simple_overlay.val))
ImGui.separator_text("Concepts")
ImGui.menu_item("Auto-resizing window", "", pointerof(show_app_auto_resize.val))
ImGui.menu_item("Constrained-resizing window", "", pointerof(show_app_constrained_resize.val))
ImGui.menu_item("Fullscreen window", "", pointerof(show_app_fullscreen.val))
ImGui.menu_item("Long text display", "", pointerof(show_app_long_text.val))
ImGui.menu_item("Manipulating window titles", "", pointerof(show_app_window_titles.val))
end
ImGui.menu("Tools") do
demo_marker("Menu/Tools")
has_debug_tools = true
ImGui.menu_item("Metrics/Debugger", "", pointerof(show_tool_metrics.val), has_debug_tools)
ImGui.menu_item("Debug Log", "", pointerof(show_tool_debug_log.val), has_debug_tools)
ImGui.menu_item("ID Stack Tool", "", pointerof(show_tool_id_stack_tool.val), has_debug_tools)
ImGui.menu_item("Style Editor", "", pointerof(show_tool_style_editor.val))
is_debugger_present = ImGui.get_io.config_debug_is_debugger_present
if ImGui.menu_item("Item Picker", "", false, has_debug_tools && is_debugger_present)
ImGui.debug_start_item_picker
end
if !is_debugger_present
ImGui.set_item_tooltip("Requires io.ConfigDebugIsDebuggerPresent=true to be set.\n\nWe otherwise disable the menu option to avoid casual users crashing the application.\n\nYou can however always access the Item Picker in Metrics->Tools.")
end
ImGui.separator
ImGui.menu_item("About Dear ImGui", "", pointerof(show_tool_about.val))
end
end
ImGui.text("dear imgui says hello! (%s) (%d)", ImGui::VERSION, ImGui::VERSION_NUM)
ImGui.spacing
demo_marker("Help")
if ImGui.collapsing_header("Help")
ImGui.separator_text("ABOUT THIS DEMO:")
ImGui.bullet_text("Sections below are demonstrating many aspects of the library.")
ImGui.bullet_text("The \"Examples\" menu above leads to more demo contents.")
ImGui.bullet_text("The \"Tools\" menu above gives access to: About Box, Style Editor,\n" +
"and Metrics/Debugger (general purpose Dear ImGui debugging tool).")
ImGui.separator_text("PROGRAMMER GUIDE:")
ImGui.bullet_text("See the ShowDemoWindow() code in src/demo.cr. <- you are here!")
ImGui.bullet_text("See comments in imgui.cpp.")
ImGui.bullet_text("See example applications in the examples/ folder.")
ImGui.bullet_text("Read the FAQ at https://www.dearimgui.com/faq/")
ImGui.bullet_text("Set 'io.ConfigFlags |= NavEnableKeyboard' for keyboard controls.")
ImGui.bullet_text("Set 'io.ConfigFlags |= NavEnableGamepad' for gamepad controls.")
ImGui.separator_text("USER GUIDE:")
show_user_guide
end
demo_marker("Configuration")
if ImGui.collapsing_header("Configuration")
io = ImGui.get_io
ImGui.tree_node("Configuration##2") do
ImGui.separator_text("General")
ImGui.checkbox_flags("io.ConfigFlags: NavEnableKeyboard", pointerof(io.config_flags), ImGuiConfigFlags::NavEnableKeyboard)
ImGui.same_line
help_marker("Enable keyboard controls.")
ImGui.checkbox_flags("io.ConfigFlags: NavEnableGamepad", pointerof(io.config_flags), ImGuiConfigFlags::NavEnableGamepad)
ImGui.same_line
help_marker("Enable gamepad controls. Require backend to set io.BackendFlags |= ImGuiBackendFlags_HasGamepad.\n\nRead instructions in imgui.cpp for details.")
ImGui.checkbox_flags("io.ConfigFlags: NavEnableSetMousePos", pointerof(io.config_flags), ImGuiConfigFlags::NavEnableSetMousePos)
ImGui.same_line
help_marker("Instruct navigation to move the mouse cursor. See comment for ImGuiConfigFlags_NavEnableSetMousePos.")
ImGui.checkbox_flags("io.ConfigFlags: NoMouse", pointerof(io.config_flags), ImGuiConfigFlags::NoMouse)
if io.config_flags.includes?(:NoMouse)
if ImGui.get_time % 0.40f32 < 0.20f32
ImGui.same_line
ImGui.text("<<PRESS SPACE TO DISABLE>>")
end
if ImGui.is_key_pressed(ImGuiKey::Space)
io.config_flags &= ~ImGuiConfigFlags::NoMouse
end
end
ImGui.checkbox_flags("io.ConfigFlags: NoMouseCursorChange", pointerof(io.config_flags), ImGuiConfigFlags::NoMouseCursorChange)
ImGui.same_line
help_marker("Instruct backend to not alter mouse cursor shape and visibility.")
ImGui.checkbox("io.ConfigInputTrickleEventQueue", pointerof(io.config_input_trickle_event_queue))
ImGui.same_line
help_marker("Enable input queue trickling: some types of events submitted during the same frame (e.g. button down + up) will be spread over multiple frames, improving interactions with low framerates.")
ImGui.checkbox("io.MouseDrawCursor", pointerof(io.mouse_draw_cursor))
ImGui.same_line
help_marker("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).")
ImGui.separator_text("Widgets")
ImGui.checkbox("io.ConfigInputTextCursorBlink", pointerof(io.config_input_text_cursor_blink))
ImGui.same_line
help_marker("Enable blinking cursor (optional as some users consider it to be distracting).")
ImGui.checkbox("io.ConfigInputTextEnterKeepActive", pointerof(io.config_input_text_enter_keep_active))
ImGui.same_line
help_marker("Pressing Enter will keep item active and select contents (single-line only).")
ImGui.checkbox("io.ConfigDragClickToInputText", pointerof(io.config_drag_click_to_input_text))
ImGui.same_line
help_marker("Enable turning DragXXX widgets into text input with a simple mouse click-release (without moving).")
ImGui.checkbox("io.ConfigWindowsResizeFromEdges", pointerof(io.config_windows_resize_from_edges))
ImGui.same_line
help_marker("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.")
ImGui.checkbox("io.ConfigWindowsMoveFromTitleBarOnly", pointerof(io.config_windows_move_from_title_bar_only))
ImGui.checkbox("io.ConfigMacOSXBehaviors", pointerof(io.config_mac_osx_behaviors))
ImGui.text("Also see Style->Rendering for rendering options.")
ImGui.separator_text("Debug")
ImGui.checkbox("io.ConfigDebugIsDebuggerPresent", pointerof(io.config_debug_is_debugger_present))
ImGui.same_line
help_marker("Enable various tools calling IM_DEBUG_BREAK().\n\nRequires a debugger being attached, otherwise IM_DEBUG_BREAK() options will appear to crash your application.")
ImGui.disabled do
ImGui.checkbox("io.ConfigDebugBeginReturnValueOnce", pointerof(io.config_debug_begin_return_value_once))
end
ImGui.same_line
help_marker("First calls to Begin()/BeginChild() will return false.\n\nTHIS OPTION IS DISABLED because it needs to be set at application boot-time to make sense. Showing the disabled option is a way to make this feature easier to discover.")
ImGui.checkbox("io.ConfigDebugBeginReturnValueLoop", pointerof(io.config_debug_begin_return_value_loop))
ImGui.same_line
help_marker("Some calls to Begin()/BeginChild() will return false.\n\nWill cycle through window depths then repeat. Windows should be flickering while running.")
ImGui.checkbox("io.ConfigDebugIgnoreFocusLoss", pointerof(io.config_debug_ignore_focus_loss))
ImGui.same_line
help_marker("Option to deactivate io.AddFocusEvent(false) handling. May facilitate interactions with a debugger when focus loss leads to clearing inputs data.")
ImGui.checkbox("io.ConfigDebugIniSettings", pointerof(io.config_debug_ini_settings))
ImGui.same_line
help_marker("Option to save .ini data with extra comments (particularly helpful for Docking, but makes saving slower).")
ImGui.spacing
end
demo_marker("Configuration/Backend Flags")
ImGui.tree_node("Backend Flags") do
help_marker(
"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.")
ImGui.disabled do
ImGui.checkbox_flags("io.BackendFlags: HasGamepad", pointerof(io.backend_flags), ImGuiBackendFlags::HasGamepad)
ImGui.checkbox_flags("io.BackendFlags: HasMouseCursors", pointerof(io.backend_flags), ImGuiBackendFlags::HasMouseCursors)
ImGui.checkbox_flags("io.BackendFlags: HasSetMousePos", pointerof(io.backend_flags), ImGuiBackendFlags::HasSetMousePos)
ImGui.checkbox_flags("io.BackendFlags: RendererHasVtxOffset", pointerof(io.backend_flags), ImGuiBackendFlags::RendererHasVtxOffset)
end
ImGui.spacing
end
demo_marker("Configuration/Style")
ImGui.tree_node("Style") do
help_marker("The same contents can be accessed in 'Tools->Style Editor' or by calling the ShowStyleEditor() function.")
show_style_editor
ImGui.spacing
end
demo_marker("Configuration/Capture, Logging")
ImGui.tree_node("Capture/Logging") do
help_marker(
"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.")
ImGui.log_buttons
help_marker("You can also call ImGui::LogText() to output directly to the log without a visual output.")
if ImGui.button("Copy \"Hello, world!\" to clipboard")
ImGui.log_to_clipboard
ImGui.log_text("Hello, world!")
ImGui.log_finish
end
end
end
demo_marker("Window options")
if ImGui.collapsing_header("Window options")
ImGui.table("split", 3) do
ImGui.table_next_column
ImGui.checkbox("No titlebar", pointerof(no_titlebar.val))
ImGui.table_next_column
ImGui.checkbox("No scrollbar", pointerof(no_scrollbar.val))
ImGui.table_next_column
ImGui.checkbox("No menu", pointerof(no_menu.val))
ImGui.table_next_column
ImGui.checkbox("No move", pointerof(no_move.val))
ImGui.table_next_column
ImGui.checkbox("No resize", pointerof(no_resize.val))
ImGui.table_next_column
ImGui.checkbox("No collapse", pointerof(no_collapse.val))
ImGui.table_next_column
ImGui.checkbox("No close", pointerof(no_close.val))
ImGui.table_next_column
ImGui.checkbox("No nav", pointerof(no_nav.val))
ImGui.table_next_column
ImGui.checkbox("No background", pointerof(no_background.val))
ImGui.table_next_column
ImGui.checkbox("No bring to front", pointerof(no_bring_to_front.val))
ImGui.table_next_column
ImGui.checkbox("Unsaved document", pointerof(unsaved_document.val))
end
end
show_demo_window_widgets
show_demo_window_layout
show_demo_window_popups
show_demo_window_tables
show_demo_window_inputs
end
ImGui.end
end
enum Element
Fire
Earth
Air
Water
end
enum Mode
Copy
Move
Swap
end
def self.show_demo_window_widgets
demo_marker("Widgets")
if !ImGui.collapsing_header("Widgets")
return
end
static disable_all = false
if disable_all.val
ImGui.begin_disabled
end
demo_marker("Widgets/Basic")
ImGui.tree_node("Basic") do
ImGui.separator_text("General")
demo_marker("Widgets/Basic/Button")
static clicked = 0
if ImGui.button("Button")
clicked.val += 1
end
if clicked.val.odd?
ImGui.same_line
ImGui.text("Thanks for clicking me!")
end
demo_marker("Widgets/Basic/Checkbox")
static check = true
ImGui.checkbox("checkbox", pointerof(check.val))
demo_marker("Widgets/Basic/RadioButton")
static e = 0
ImGui.radio_button("radio a", pointerof(e.val), 0)
ImGui.same_line
ImGui.radio_button("radio b", pointerof(e.val), 1)
ImGui.same_line
ImGui.radio_button("radio c", pointerof(e.val), 2)
demo_marker("Widgets/Basic/Buttons (Colored)")
7.times do |i|
if i > 0
ImGui.same_line
end
ImGui.with_id(i) do
ImGui.push_style_color(ImGuiCol::Button, ImGui.hsv(i / 7.0f32, 0.6f32, 0.6f32))
ImGui.push_style_color(ImGuiCol::ButtonHovered, ImGui.hsv(i / 7.0f32, 0.7f32, 0.7f32))
ImGui.push_style_color(ImGuiCol::ButtonActive, ImGui.hsv(i / 7.0f32, 0.8f32, 0.8f32))
ImGui.button("Click")
ImGui.pop_style_color(3)
end
end
ImGui.align_text_to_frame_padding
ImGui.text("Hold to repeat:")
ImGui.same_line
demo_marker("Widgets/Basic/Buttons (Repeating)")
static counter = 0
spacing = ImGui.get_style.item_inner_spacing.x
ImGui.with_button_repeat(true) do
if ImGui.arrow_button("##left", ImGuiDir::Left)
counter.val -= 1
end
ImGui.same_line(0.0f32, spacing)
if ImGui.arrow_button("##right", ImGuiDir::Right)
counter.val += 1
end
end
ImGui.same_line
ImGui.text("%d", counter.val)
ImGui.button("Tooltip")
ImGui.set_item_tooltip("I am a tooltip")
ImGui.label_text("label", "Value")
ImGui.separator_text("Inputs")
begin
demo_marker("Widgets/Basic/InputText")
static str0 = ImGui::TextBuffer.new("Hello, world!", 128)
ImGui.input_text("input text", str0.val)
ImGui.same_line
help_marker(
"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 src/demo.cr).")
static str1 = ImGui::TextBuffer.new(128)
ImGui.input_text_with_hint("input text (w/ hint)", "enter text here", str1.val)
demo_marker("Widgets/Basic/InputInt, InputFloat")
static i0 = 123
ImGui.input_int("input int", pointerof(i0.val))
static f0 = 0.001f32
ImGui.input_float("input float", pointerof(f0.val), 0.01f32, 1.0f32, "%.3f")
static d0 = 999999.00000001
ImGui.input_double("input double", pointerof(d0.val), 0.01f32, 1.0f32, "%.8f")
static f1 = 1.0e10f32
ImGui.input_float("input scientific", pointerof(f1.val), 0.0f32, 0.0f32, "%e")
ImGui.same_line
help_marker(
"You can input value using the scientific notation,\n" +
" e.g. \"1e+8\" becomes \"100000000\".")
static vec4a = Slice[0.10f32, 0.20f32, 0.30f32, 0.44f32]
ImGui.input_float3("input float3", vec4a.val[...3])
end
ImGui.separator_text("Drags")
begin
demo_marker("Widgets/Basic/DragInt, DragFloat")
static i1 = 50
static i2 = 42
ImGui.drag_int("drag int", pointerof(i1.val), 1)
ImGui.same_line
help_marker(
"Click and drag to edit value.\n" +
"Hold SHIFT/ALT for faster/slower edit.\n" +
"Double-click or CTRL+click to input value.")
ImGui.drag_int("drag int 0..100", pointerof(i2.val), 1, 0, 100, "%d%%", ImGuiSliderFlags::AlwaysClamp)
static f1 = 1.00f32
static f2 = 0.0067f32
ImGui.drag_float("drag float", pointerof(f1.val), 0.005f32)
ImGui.drag_float("drag small float", pointerof(f2.val), 0.0001f32, 0.0f32, 0.0f32, "%.06f ns")
end
ImGui.separator_text("Sliders")
begin
demo_marker("Widgets/Basic/SliderInt, SliderFloat")
static i1 = 0
ImGui.slider_int("slider int", pointerof(i1.val), -1, 3)
ImGui.same_line
help_marker("CTRL+click to input value.")
static f1 = 0.123f32
static f2 = 0.0f32
ImGui.slider_float("slider float", pointerof(f1.val), 0.0f32, 1.0f32, "ratio = %.3f")
ImGui.slider_float("slider float (log)", pointerof(f2.val), -10.0f32, 10.0f32, "%.4f", ImGuiSliderFlags::Logarithmic)
demo_marker("Widgets/Basic/SliderAngle")
static angle = 0.0f32
ImGui.slider_angle("slider angle", pointerof(angle.val))
demo_marker("Widgets/Basic/Slider (enum)")
static elem = 0
ImGui.slider_int("slider enum", pointerof(elem.val), 0, Element.values.size - 1, Element.new(elem.val).to_s)
ImGui.same_line
help_marker("Using the format string parameter to display a name instead of the underlying integer.")
end
ImGui.separator_text("Selectors/Pickers")
begin
demo_marker("Widgets/Basic/ColorEdit3, ColorEdit4")
static col1 = Slice[1.0f32, 0.0f32, 0.2f32]
static col2 = Slice[0.4f32, 0.7f32, 0.0f32, 0.5f32]
ImGui.color_edit3("color 1", col1.val)
ImGui.same_line
help_marker(
"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")
ImGui.color_edit4("color 2", col2.val)
end
begin
demo_marker("Widgets/Basic/Combo")
items = ["AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIIIIII", "JJJJ", "KKKKKKK"]
static item_current = 0
ImGui.combo("combo", pointerof(item_current.val), items)
ImGui.same_line
help_marker(
"Using the simplified one-liner Combo API here.\n" +
"Refer to the \"Combo\" section below for an explanation of how to use the more flexible and general BeginCombo/EndCombo API.")
end
begin
demo_marker("Widgets/Basic/ListBox")
items = ["Apple", "Banana", "Cherry", "Kiwi", "Mango", "Orange", "Pineapple", "Strawberry", "Watermelon"]
static item_current = 1
ImGui.list_box("listbox", pointerof(item_current.val), items, 4)
ImGui.same_line
help_marker(
"Using the simplified one-liner ListBox API here.\n" +
"Refer to the \"List boxes\" section below for an explanation of how to use the more flexible and general BeginListBox/EndListBox API.")
end
end
demo_marker("Widgets/Tooltips")
ImGui.tree_node("Tooltips") do
ImGui.separator_text("General")
help_marker(
"Tooltip are typically created by using a IsItemHovered() + SetTooltip() sequence.\n\n" +
"We provide a helper SetItemTooltip() function to perform the two with standards flags.")
sz = ImVec2.new(-Float32::MIN_POSITIVE, 0.0f32)
ImGui.button("Basic", sz)
ImGui.set_item_tooltip("I am a tooltip")
ImGui.button("Fancy", sz)
if ImGui.begin_item_tooltip
ImGui.text("I am a fancy tooltip")
static arr = [0.6f32, 0.1f32, 1.0f32, 0.5f32, 0.92f32, 0.1f32, 0.2f32]
ImGui.plot_lines("Curve", arr.val)
ImGui.text("Sin(time) = %f", Math.sin(ImGui.get_time))
ImGui.end_tooltip
end
ImGui.separator_text("Always On")
static always_on = 0
ImGui.radio_button("Off", pointerof(always_on.val), 0)
ImGui.same_line
ImGui.radio_button("Always On (Simple)", pointerof(always_on.val), 1)
ImGui.same_line
ImGui.radio_button("Always On (Advanced)", pointerof(always_on.val), 2)
if always_on.val == 1
ImGui.set_tooltip("I am following you around.")
elsif always_on.val == 2 && ImGui.begin_tooltip
ImGui.progress_bar(Math.sin(ImGui.get_time).to_f32 * 0.5f32 + 0.5f32, ImVec2.new(ImGui.get_font_size * 25, 0.0f32))
ImGui.end_tooltip
end
ImGui.separator_text("Custom")
help_marker(
"Passing ImGuiHoveredFlags_ForTooltip to IsItemHovered() is the preferred way to standardize" +
"tooltip activation details across your application. You may however decide to use custom" +
"flags for a specific tooltip instance.")
ImGui.button("Manual", sz)
if ImGui.is_item_hovered(ImGuiHoveredFlags::ForTooltip)
ImGui.set_tooltip("I am a manually emitted tooltip.")
end
ImGui.button("DelayNone", sz)
if ImGui.is_item_hovered(ImGuiHoveredFlags::DelayNone)
ImGui.set_tooltip("I am a tooltip with no delay.")
end
ImGui.button("DelayShort", sz)
if ImGui.is_item_hovered(ImGuiHoveredFlags::DelayShort | ImGuiHoveredFlags::NoSharedDelay)
ImGui.set_tooltip("I am a tooltip with a short delay (%0.2f sec).", ImGui.get_style.hover_delay_short)
end
ImGui.button("DelayLong", sz)
if ImGui.is_item_hovered(ImGuiHoveredFlags::DelayNormal | ImGuiHoveredFlags::NoSharedDelay)
ImGui.set_tooltip("I am a tooltip with a long delay (%0.2f sec).", ImGui.get_style.hover_delay_normal)
end
ImGui.button("Stationary", sz)
if ImGui.is_item_hovered(ImGuiHoveredFlags::Stationary)
ImGui.set_tooltip("I am a tooltip requiring mouse to be stationary before activating.")
end
ImGui.disabled do
ImGui.button("Disabled item", sz)
end
if ImGui.is_item_hovered(ImGuiHoveredFlags::ForTooltip)
ImGui.set_tooltip("I am a a tooltip for a disabled item.")
end
end
demo_marker("Widgets/Tree Nodes")
ImGui.tree_node("Tree Nodes") do
demo_marker("Widgets/Tree Nodes/Basic trees")
ImGui.tree_node("Basic trees") do
5.times do |i|
if i == 0
ImGui.set_next_item_open(true, ImGuiCond::Once)
end
ImGui.with_id(i) do
ImGui.tree_node("", "Child %d", i) do
ImGui.text("blah blah")
ImGui.same_line
if ImGui.small_button("button")
end
end
end
end
end
demo_marker("Widgets/Tree Nodes/Advanced, with Selectable nodes")
ImGui.tree_node("Advanced, with Selectable nodes") do
help_marker(
"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.")
static base_flags = ImGuiTreeNodeFlags::OpenOnArrow | ImGuiTreeNodeFlags::OpenOnDoubleClick | ImGuiTreeNodeFlags::SpanAvailWidth
static align_label_with_current_x_position = false
static test_drag_and_drop = false
ImGui.checkbox_flags("ImGuiTreeNodeFlags_OpenOnArrow", pointerof(base_flags.val), ImGuiTreeNodeFlags::OpenOnArrow)
ImGui.checkbox_flags("ImGuiTreeNodeFlags_OpenOnDoubleClick", pointerof(base_flags.val), ImGuiTreeNodeFlags::OpenOnDoubleClick)
ImGui.checkbox_flags("ImGuiTreeNodeFlags_SpanAvailWidth", pointerof(base_flags.val), ImGuiTreeNodeFlags::SpanAvailWidth)
ImGui.same_line
help_marker("Extend hit area to all available width instead of allowing more items to be laid out after the node.")
ImGui.checkbox_flags("ImGuiTreeNodeFlags_SpanFullWidth", pointerof(base_flags.val), ImGuiTreeNodeFlags::SpanFullWidth)
ImGui.checkbox_flags("ImGuiTreeNodeFlags_SpanTextWidth", pointerof(base_flags.val), ImGuiTreeNodeFlags::SpanTextWidth)
ImGui.same_line
help_marker("Reduce hit area to the text label and a bit of margin.")
ImGui.checkbox_flags("ImGuiTreeNodeFlags_SpanAllColumns", pointerof(base_flags.val), ImGuiTreeNodeFlags::SpanAllColumns)
ImGui.same_line
help_marker("For use in Tables only.")
ImGui.checkbox_flags("ImGuiTreeNodeFlags_AllowOverlap", pointerof(base_flags.val), ImGuiTreeNodeFlags::AllowOverlap)
ImGui.checkbox_flags("ImGuiTreeNodeFlags_Framed", pointerof(base_flags.val), ImGuiTreeNodeFlags::Framed)
ImGui.same_line
help_marker("Draw frame with background (e.g. for CollapsingHeader)")
ImGui.checkbox("Align label with current X position", pointerof(align_label_with_current_x_position.val))
ImGui.checkbox("Test tree node as drag source", pointerof(test_drag_and_drop.val))
ImGui.text("Hello!")
if align_label_with_current_x_position.val
ImGui.unindent(ImGui.get_tree_node_to_label_spacing)
end
static selection_mask = (1 << 2)
node_clicked = -1
6.times do |i|
node_flags = base_flags.val
is_selected = (selection_mask.val & (1 << i)) != 0
if is_selected
node_flags |= ImGuiTreeNodeFlags::Selected
end
if i < 3
node_open = ImGui.tree_node_ex(i, node_flags, "Selectable Node %d", i)
if ImGui.is_item_clicked && !ImGui.is_item_toggled_open
node_clicked = i
end
if test_drag_and_drop.val && ImGui.begin_drag_drop_source
ImGui.set_drag_drop_payload("_TREENODE", Pointer(Void).null, 0)
ImGui.text("This is a drag and drop source")
ImGui.end_drag_drop_source
end
if i == 2
ImGui.same_line
if ImGui.small_button("button")
end
end
if node_open
ImGui.bullet_text("Blah blah\nBlah Blah")
ImGui.tree_pop
end
else
node_flags |= ImGuiTreeNodeFlags::Leaf | ImGuiTreeNodeFlags::NoTreePushOnOpen
ImGui.tree_node_ex(i, node_flags, "Selectable Leaf %d", i)
if ImGui.is_item_clicked && !ImGui.is_item_toggled_open
node_clicked = i
end
if test_drag_and_drop.val && ImGui.begin_drag_drop_source
ImGui.set_drag_drop_payload("_TREENODE", Pointer(Void).null, 0)
ImGui.text("This is a drag and drop source")
ImGui.end_drag_drop_source
end
end
end
if node_clicked != -1
if ImGui.get_io.key_ctrl
selection_mask.val ^= (1 << node_clicked)
else
selection_mask.val = (1 << node_clicked)
end
end
if align_label_with_current_x_position.val
ImGui.indent(ImGui.get_tree_node_to_label_spacing)
end
end
end
demo_marker("Widgets/Collapsing Headers")
ImGui.tree_node("Collapsing Headers") do
static closable_group = true
ImGui.checkbox("Show 2nd header", pointerof(closable_group.val))
if ImGui.collapsing_header("Header", ImGuiTreeNodeFlags::None)
ImGui.text("IsItemHovered: %d", ImGui.is_item_hovered)
5.times do |i|
ImGui.text("Some content %d", i)
end
end
if ImGui.collapsing_header("Header with a close button", pointerof(closable_group.val))
ImGui.text("IsItemHovered: %d", ImGui.is_item_hovered)
5.times do |i|
ImGui.text("More content %d", i)
end
end
end
demo_marker("Widgets/Bullets")
ImGui.tree_node("Bullets") do
ImGui.bullet_text("Bullet point 1")
ImGui.bullet_text("Bullet point 2\nOn multiple lines")
ImGui.tree_node("Tree node") do
ImGui.bullet_text("Another bullet point")
end
ImGui.bullet
ImGui.text("Bullet point 3 (two calls)")
ImGui.bullet
ImGui.small_button("Button")
end
demo_marker("Widgets/Text")
ImGui.tree_node("Text") do
demo_marker("Widgets/Text/Colored Text")
ImGui.tree_node("Colorful Text") do
ImGui.text_colored(ImVec4.new(1.0f32, 0.0f32, 1.0f32, 1.0f32), "Pink")
ImGui.text_colored(ImVec4.new(1.0f32, 1.0f32, 0.0f32, 1.0f32), "Yellow")
ImGui.text_disabled("Disabled")
ImGui.same_line
help_marker("The TextDisabled color is stored in ImGuiStyle.")
end
demo_marker("Widgets/Text/Word Wrapping")
ImGui.tree_node("Word Wrapping") do
ImGui.text_wrapped(
"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.")
ImGui.spacing
static wrap_width = 200.0f32
ImGui.slider_float("Wrap width", pointerof(wrap_width.val), -20, 600, "%.0f")
draw_list = ImGui.get_window_draw_list
2.times do |n|
ImGui.text("Test paragraph %d:", n)
pos = ImGui.get_cursor_screen_pos
marker_min = ImVec2.new(pos.x + wrap_width.val, pos.y)
marker_max = ImVec2.new(pos.x + wrap_width.val + 10, pos.y + ImGui.get_text_line_height)
ImGui.with_text_wrap_pos(ImGui.get_cursor_pos.x + wrap_width.val) do
if n == 0
ImGui.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.", wrap_width.val)
else
ImGui.text("aaaaaaaa bbbbbbbb, c cccccccc,dddddddd. d eeeeeeee ffffffff. gggggggg!hhhhhhhh")
end
draw_list.add_rect(ImGui.get_item_rect_min, ImGui.get_item_rect_max, ImGui.col32(255, 255, 0, 255))
draw_list.add_rect_filled(marker_min, marker_max, ImGui.col32(255, 0, 255, 255))
end
end
end
demo_marker("Widgets/Text/UTF-8 Text")
ImGui.tree_node("UTF-8 Text") do
ImGui.text_wrapped(
"CJK text will only appear 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.")
ImGui.text("Hiragana: かきくけこ (kakikukeko)")
ImGui.text("Kanjis: 日本語 (nihongo)")
static buf = ImGui::TextBuffer.new("日本語", 32)
ImGui.input_text("UTF-8 input", buf.val)
end
end
demo_marker("Widgets/Images")
ImGui.tree_node("Images") do
io = ImGui.get_io
ImGui.text_wrapped(
"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!")
my_tex_id = io.fonts.tex_id
my_tex_w = io.fonts.tex_width
my_tex_h = io.fonts.tex_height
begin
static use_text_color_for_tint = false
ImGui.checkbox("Use Text Color for Tint", pointerof(use_text_color_for_tint.val))
ImGui.text("%.0fx%.0f", my_tex_w, my_tex_h)
pos = ImGui.get_cursor_screen_pos
uv_min = ImVec2.new(0.0f32, 0.0f32)
uv_max = ImVec2.new(1.0f32, 1.0f32)
tint_col = use_text_color_for_tint.val ? ImGui.get_style_color_vec4(ImGuiCol::Text) : ImVec4.new(1.0f32, 1.0f32, 1.0f32, 1.0f32)
border_col = ImGui.get_style_color_vec4(ImGuiCol::Border)
ImGui.image(my_tex_id, ImVec2.new(my_tex_w, my_tex_h), uv_min, uv_max, tint_col, border_col)
if ImGui.begin_item_tooltip
region_sz = 32.0f32
region_x = io.mouse_pos.x - pos.x - region_sz * 0.5f32
region_y = io.mouse_pos.y - pos.y - region_sz * 0.5f32
zoom = 4.0f32
if region_x < 0.0f32
region_x = 0.0f32
elsif region_x > my_tex_w - region_sz
region_x = my_tex_w - region_sz
end
if region_y < 0.0f32
region_y = 0.0f32
elsif region_y > my_tex_h - region_sz
region_y = my_tex_h - region_sz
end
ImGui.text("Min: (%.2f, %.2f)", region_x, region_y)
ImGui.text("Max: (%.2f, %.2f)", region_x + region_sz, region_y + region_sz)
uv0 = ImVec2.new((region_x) / my_tex_w, (region_y) / my_tex_h)
uv1 = ImVec2.new((region_x + region_sz) / my_tex_w, (region_y + region_sz) / my_tex_h)
ImGui.image(my_tex_id, ImVec2.new(region_sz * zoom, region_sz * zoom), uv0, uv1, tint_col, border_col)
ImGui.end_tooltip
end
end
demo_marker("Widgets/Images/Textured buttons")
ImGui.text_wrapped("And now some textured buttons..")
static pressed_count = 0
8.times do |i|
ImGui.with_id(i) do
if i > 0
ImGui.push_style_var(ImGuiStyleVar::FramePadding, ImVec2.new(i - 1.0f32, i - 1.0f32))
end
size = ImVec2.new(32.0f32, 32.0f32)
uv0 = ImVec2.new(0.0f32, 0.0f32)
uv1 = ImVec2.new(32.0f32 / my_tex_w, 32.0f32 / my_tex_h)
bg_col = ImVec4.new(0.0f32, 0.0f32, 0.0f32, 1.0f32)
tint_col = ImVec4.new(1.0f32, 1.0f32, 1.0f32, 1.0f32)
if ImGui.image_button("", my_tex_id, size, uv0, uv1, bg_col, tint_col)
pressed_count.val += 1
end
if i > 0
ImGui.pop_style_var
end
end
ImGui.same_line
end
ImGui.new_line
ImGui.text("Pressed %d times.", pressed_count.val)
end
demo_marker("Widgets/Combo")
ImGui.tree_node("Combo") do
static flags = ImGuiComboFlags::None
ImGui.checkbox_flags("ImGuiComboFlags_PopupAlignLeft", pointerof(flags.val), ImGuiComboFlags::PopupAlignLeft)
ImGui.same_line
help_marker("Only makes a difference if the popup is larger than the combo")
if ImGui.checkbox_flags("ImGuiComboFlags_NoArrowButton", pointerof(flags.val), ImGuiComboFlags::NoArrowButton)
flags.val &= ~ImGuiComboFlags::NoPreview
end
if ImGui.checkbox_flags("ImGuiComboFlags_NoPreview", pointerof(flags.val), ImGuiComboFlags::NoPreview)
flags.val &= ~(ImGuiComboFlags::NoArrowButton | ImGuiComboFlags::WidthFitPreview)
end
if ImGui.checkbox_flags("ImGuiComboFlags_WidthFitPreview", pointerof(flags.val), ImGuiComboFlags::WidthFitPreview)
flags.val &= ~ImGuiComboFlags::NoPreview
end
if ImGui.checkbox_flags("ImGuiComboFlags_HeightSmall", pointerof(flags.val), ImGuiComboFlags::HeightSmall)
flags.val &= ~(ImGuiComboFlags::HeightMask_ & ~ImGuiComboFlags::HeightSmall)
end
if ImGui.checkbox_flags("ImGuiComboFlags_HeightRegular", pointerof(flags.val), ImGuiComboFlags::HeightRegular)
flags.val &= ~(ImGuiComboFlags::HeightMask_ & ~ImGuiComboFlags::HeightRegular)
end
if ImGui.checkbox_flags("ImGuiComboFlags_HeightLargest", pointerof(flags.val), ImGuiComboFlags::HeightLargest)
flags.val &= ~(ImGuiComboFlags::HeightMask_ & ~ImGuiComboFlags::HeightLargest)
end
items = ["AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK", "LLLLLLL", "MMMM", "OOOOOOO"]
static item_current_idx = 0
combo_preview_value = items[item_current_idx.val]
ImGui.combo("combo 1", combo_preview_value, flags.val) do
items.size.times do |n|
is_selected = (item_current_idx.val == n)
if ImGui.selectable(items[n], is_selected)
item_current_idx.val = n
end
if is_selected
ImGui.set_item_default_focus
end
end
end
ImGui.spacing
ImGui.separator_text("One-liner variants")
help_marker("Flags above don't apply to this section.")
static item_current_2 = 0
ImGui.combo("combo 2 (one-liner)", pointerof(item_current_2.val), "aaaa\0bbbb\0cccc\0dddd\0eeee\0\0")
static item_current_3 = -1
ImGui.combo("combo 3 (array)", pointerof(item_current_3.val), items)
static item_current_4 = 0
ImGui.combo("combo 4 (function)", pointerof(item_current_4.val), items.size) do |idx|
items[idx]
end
end
demo_marker("Widgets/List Boxes")
ImGui.tree_node("List boxes") do
items = ["AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK", "LLLLLLL", "MMMM", "OOOOOOO"]
static item_current_idx = 0
ImGui.list_box("listbox 1") do
items.size.times do |n|
is_selected = (item_current_idx.val == n)
if ImGui.selectable(items[n], is_selected)
item_current_idx.val = n
end