/
test_window_impl.rs
1307 lines (1217 loc) · 48 KB
/
test_window_impl.rs
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
use imgui::*;
mod support;
struct State {
show_app_main_menu_bar: bool,
show_app_console: bool,
show_app_log: bool,
show_app_layout: bool,
show_app_property_editor: bool,
show_app_long_text: bool,
show_app_auto_resize: bool,
show_app_constrained_resize: bool,
show_app_fixed_overlay: bool,
show_app_manipulating_window_title: bool,
show_app_custom_rendering: bool,
show_app_style_editor: bool,
show_app_metrics: bool,
show_app_about: bool,
no_titlebar: bool,
no_resize: bool,
no_move: bool,
no_scrollbar: bool,
no_collapse: bool,
no_menu: bool,
no_close: bool,
wrap_width: f32,
buf: String,
item: usize,
item2: usize,
item3: i32,
text: String,
text_with_hint: String,
text_multiline: String,
i0: i32,
u0: u64,
d0: f64,
f0: f32,
vec2f: [f32; 2],
vec3f: [f32; 3],
vec2i: [i32; 2],
vec3i: [i32; 3],
col1: [f32; 3],
col2: [f32; 4],
selected_fish: Option<usize>,
selected_fish2: Option<usize>,
auto_resize_state: AutoResizeState,
file_menu: FileMenuState,
radio_button: i32,
color_edit: ColorEditState,
custom_rendering: CustomRenderingState,
dont_ask_me_next_time: bool,
stacked_modals_item: usize,
stacked_modals_color: [f32; 4],
app_log: Vec<String>,
filter: imgui::TextFilter,
tabs: TabState,
}
impl Default for State {
fn default() -> Self {
let mut buf = String::with_capacity(32);
buf.push_str("日本語");
let mut text = String::with_capacity(128);
text.push_str("Hello, world!");
let text_with_hint = String::with_capacity(128);
let mut text_multiline = String::with_capacity(128);
text_multiline.push_str("Hello, world!\nMultiline");
State {
show_app_main_menu_bar: false,
show_app_console: false,
show_app_log: false,
show_app_layout: false,
show_app_property_editor: false,
show_app_long_text: false,
show_app_auto_resize: false,
show_app_fixed_overlay: false,
show_app_constrained_resize: false,
show_app_manipulating_window_title: false,
show_app_custom_rendering: false,
show_app_style_editor: false,
show_app_metrics: false,
show_app_about: false,
no_titlebar: false,
no_resize: false,
no_move: false,
no_scrollbar: false,
no_collapse: false,
no_menu: false,
no_close: false,
wrap_width: 200.0,
buf,
item: 0,
item2: 0,
item3: 0,
text,
text_with_hint,
text_multiline,
i0: 123,
u0: 1234,
f0: 0.001,
d0: 0.0001,
vec2f: [0.10, 0.20],
vec3f: [0.10, 0.20, 0.30],
vec2i: [10, 20],
vec3i: [10, 20, 30],
col1: [1.0, 0.0, 0.2],
col2: [0.4, 0.7, 0.0, 0.5],
selected_fish: None,
selected_fish2: None,
auto_resize_state: Default::default(),
file_menu: Default::default(),
radio_button: 0,
color_edit: ColorEditState::default(),
custom_rendering: Default::default(),
dont_ask_me_next_time: false,
stacked_modals_item: 0,
stacked_modals_color: [0.4, 0.7, 0.0, 0.5],
app_log: Vec::new(),
filter: TextFilter::new(String::from("Test")),
tabs: TabState::default(),
}
}
}
struct TabState {
// flags for the advanced tab example
reorderable: bool,
autoselect: bool,
listbutton: bool,
noclose_middlebutton: bool,
fitting_resizedown: bool,
fitting_scroll: bool,
// opened state for tab items
artichoke_tab: bool,
beetroot_tab: bool,
celery_tab: bool,
daikon_tab: bool,
}
impl Default for TabState {
fn default() -> Self {
Self {
reorderable: true,
autoselect: false,
listbutton: false,
noclose_middlebutton: false,
fitting_resizedown: true,
fitting_scroll: false,
artichoke_tab: true,
beetroot_tab: true,
celery_tab: true,
daikon_tab: true,
}
}
}
struct ColorEditState {
color: [f32; 4],
hdr: bool,
alpha_preview: bool,
alpha_half_preview: bool,
options_menu: bool,
alpha: bool,
alpha_bar: bool,
side_preview: bool,
ref_color: bool,
ref_color_v: [f32; 4],
}
impl Default for ColorEditState {
fn default() -> Self {
ColorEditState {
color: [114.0 / 255.0, 144.0 / 255.0, 154.0 / 255.0, 200.0 / 255.0],
hdr: false,
alpha_preview: true,
alpha_half_preview: false,
options_menu: true,
alpha: true,
alpha_bar: true,
side_preview: true,
ref_color: false,
ref_color_v: [1.0, 0.0, 1.0, 0.5],
}
}
}
struct FileMenuState {
enabled: bool,
f: f32,
n: usize,
b: bool,
}
impl Default for FileMenuState {
fn default() -> Self {
FileMenuState {
enabled: true,
f: 0.5,
n: 0,
b: true,
}
}
}
struct AutoResizeState {
lines: i32,
}
impl Default for AutoResizeState {
fn default() -> Self {
AutoResizeState { lines: 10 }
}
}
struct CustomRenderingState {
sz: f32,
col: [f32; 3],
points: Vec<[f32; 2]>,
adding_line: bool,
}
impl Default for CustomRenderingState {
fn default() -> Self {
CustomRenderingState {
sz: 36.0,
col: [1.0, 1.0, 0.4],
points: vec![],
adding_line: false,
}
}
}
fn main() {
let mut state = State::default();
let system = support::init(file!());
system.main_loop(move |run, ui| show_test_window(ui, &mut state, run));
}
fn show_help_marker(ui: &Ui, desc: &str) {
ui.text_disabled("(?)");
if ui.is_item_hovered() {
ui.tooltip(|| {
ui.text(desc);
});
}
}
fn show_user_guide(ui: &Ui) {
ui.bullet_text("Double-click on title bar to collapse window.");
ui.bullet_text("Click and drag on lower right corner to resize window.");
ui.bullet_text("Click and drag on any empty space to move window.");
ui.bullet_text("Mouse Wheel to scroll.");
// TODO: check font_allow_user_scaling
ui.bullet_text("TAB/SHIFT+TAB to cycle through keyboard editable fields.");
ui.bullet_text("CTRL+Click on a slider or drag box to input text.");
ui.bullet_text(
"While editing text:
- Hold SHIFT or use mouse to select text
- CTRL+Left/Right to word jump
- CTRL+A or double-click to select all
- CTRL+X,CTRL+C,CTRL+V clipboard
- CTRL+Z,CTRL+Y undo/redo
- ESCAPE to revert
- You can apply arithmetic operators +,*,/ on numerical values.
Use +- to subtract.\n",
);
}
fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) {
if state.show_app_main_menu_bar {
show_example_app_main_menu_bar(ui, state)
}
if state.show_app_auto_resize {
show_example_app_auto_resize(
ui,
&mut state.auto_resize_state,
&mut state.show_app_auto_resize,
);
}
if state.show_app_fixed_overlay {
show_example_app_fixed_overlay(ui, &mut state.show_app_fixed_overlay);
}
if state.show_app_manipulating_window_title {
show_example_app_manipulating_window_title(ui);
}
if state.show_app_metrics {
ui.show_metrics_window(&mut state.show_app_metrics);
}
if state.show_app_style_editor {
ui.window("Style Editor")
.opened(&mut state.show_app_style_editor)
.build(|| ui.show_default_style_editor());
}
if state.show_app_about {
ui.window("About ImGui")
.always_auto_resize(true)
.opened(&mut state.show_app_about)
.build(|| {
ui.text(format!("dear imgui, {}", imgui::dear_imgui_version()));
ui.separator();
ui.text("By Omar Cornut and all github contributors.");
ui.text(
"ImGui is licensed under the MIT License, see LICENSE for more \
information.",
);
});
}
if state.show_app_custom_rendering {
show_example_app_custom_rendering(
ui,
&mut state.custom_rendering,
&mut state.show_app_custom_rendering,
);
}
if state.show_app_log {
show_app_log(ui, &mut state.app_log);
}
let mut window = ui
.window("ImGui Demo")
.title_bar(!state.no_titlebar)
.resizable(!state.no_resize)
.movable(!state.no_move)
.scroll_bar(!state.no_scrollbar)
.collapsible(!state.no_collapse)
.menu_bar(!state.no_menu)
.size([550.0, 680.0], Condition::FirstUseEver);
if !state.no_close {
window = window.opened(opened)
}
window.build(|| {
let _w = ui.push_item_width(-140.0);
ui.text(format!("dear imgui says hello. ({})", imgui::dear_imgui_version()));
if let Some(_menu_bar) = ui.begin_menu_bar() {
if let Some(menu) = ui.begin_menu("Menu") {
show_example_menu_file(ui, &mut state.file_menu);
menu.end();
}
if let Some(_t) = ui.begin_menu("Examples") {
ui.menu_item_config("Main menu bar").build_with_ref(&mut state.show_app_main_menu_bar);
ui.menu_item_config("Console").build_with_ref(&mut state.show_app_console);
ui.menu_item_config("Log").build_with_ref(&mut state.show_app_log);
ui.menu_item_config("Simple layout").build_with_ref(&mut state.show_app_layout);
ui.menu_item_config("Property editor").build_with_ref(&mut state.show_app_property_editor);
ui.menu_item_config("Long text display").build_with_ref(&mut state.show_app_long_text);
ui.menu_item_config("Auto-resizing window").build_with_ref(&mut state.show_app_auto_resize);
ui.menu_item_config("Constrained-resizing window").build_with_ref(&mut state.show_app_constrained_resize);
ui.menu_item_config("Simple overlay").build_with_ref(&mut state.show_app_fixed_overlay);
ui.menu_item_config("Manipulating window title").build_with_ref(&mut state.show_app_manipulating_window_title);
ui.menu_item_config("Custom Rendering").build_with_ref(&mut state.show_app_custom_rendering);
}
if let Some(_menu) = ui.begin_menu("Help") {
ui.menu_item_config("Metrics").build_with_ref(&mut state.show_app_metrics);
ui.menu_item_config("Style Editor").build_with_ref(&mut state.show_app_style_editor);
ui.menu_item_config("About ImGui").build_with_ref(&mut state.show_app_about);
}
}
ui.spacing();
if CollapsingHeader::new("Help").build(ui) {
ui.text_wrapped(
"This window is being created by the show_test_window() \
function. Please refer to the code for programming \
reference.\n\nUser Guide:"
);
show_user_guide(ui);
}
if CollapsingHeader::new("Window options").build(ui) {
ui.checkbox("No titlebar", &mut state.no_titlebar);
ui.same_line_with_pos(150.0);
ui.checkbox("No scrollbar", &mut state.no_scrollbar);
ui.same_line_with_pos(300.0);
ui.checkbox("No menu", &mut state.no_menu);
ui.checkbox("No move", &mut state.no_move);
ui.same_line_with_pos(150.0);
ui.checkbox("No resize", &mut state.no_resize);
ui.same_line_with_pos(300.0);
ui.checkbox("No collapse", &mut state.no_collapse);
ui.checkbox("No close", &mut state.no_close);
if let Some(_t) = ui.tree_node("Style") {
ui.show_default_style_editor();
}
}
if CollapsingHeader::new("Widgets").build(ui) {
if let Some(_t) = ui.tree_node("Tree") {
let num_child = 4;
for i in 0..num_child {
if let Some(_t) = ui.tree_node(format!("Child {}", i)) {
ui.text("blah blah");
ui.same_line();
if ui.small_button("print") {
println!("Child {} pressed", i);
}
}
}
{
let tree_node_stack = ui.tree_node_config("##HideTreeNodeLabel")
.allow_item_overlap(true)
.push();
ui.same_line();
if ui.small_button(format!("Child {} is a button", num_child)) {
println!("TreeNode Button pressed.");
}
if tree_node_stack.is_some() {
ui.text("blah blah")
}
}
}
if let Some(_t) = ui.tree_node("Bullets") {
ui.bullet_text("Bullet point 1");
ui.bullet_text("Bullet point 2\nOn multiple lines");
ui.bullet();
ui.text("Bullet point 3 (two calls)");
ui.bullet();
ui.small_button("Button");
}
if let Some(_t) = ui.tree_node("Colored text") {
ui.text_colored([1.0, 0.0, 1.0, 1.0], "Pink");
ui.text_colored([1.0, 1.0, 0.0, 1.0], "Yellow");
ui.text_disabled("Disabled");
}
if let Some(_t) = ui.tree_node("Multi-line text") {
ui.input_text_multiline(
"multiline",
&mut state.text_multiline,
[300., 100.],
).build();
}
if let Some(_t) = ui.tree_node("Word wrapping") {
ui.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."
);
ui.spacing();
ui.slider_config("Wrap width", -20.0, 600.0)
.display_format("%.0f")
.build(&mut state.wrap_width);
ui.text("Test paragraph 1:");
// TODO
ui.text("Test paragraph 2:");
// TODO
}
if let Some(_t) = ui.tree_node("UTF-8 Text") {
ui.text_wrapped(
"CJK text will only appear if the font was loaded \
with theappropriate CJK character ranges. Call \
io.Font->LoadFromFileTTF()manually to load extra \
character ranges."
);
ui.text("Hiragana: かきくけこ (kakikukeko)");
ui.text("Kanjis: 日本語 (nihongo)");
ui.input_text("UTF-8 input", &mut state.buf)
.build();
}
ui.radio_button("radio a", &mut state.radio_button, 0);
ui.same_line();
ui.radio_button("radio b", &mut state.radio_button, 1);
ui.same_line();
ui.radio_button("radio c", &mut state.radio_button, 2);
ui.separator();
ui.label_text("label", "Value");
ui.combo_simple_string("combo",
&mut state.item,
&[
"aaaa",
"bbbb",
"cccc",
"dddd",
"eeee",
]);
let items = [
"AAAA",
"BBBB",
"CCCC",
"DDDD",
"EEEE",
"FFFF",
"GGGG",
"HHHH",
"IIII",
"JJJJ",
"KKKK",
];
ui.combo_simple_string("combo scroll", &mut state.item2, &items);
ui.list_box("list", &mut state.item3, &items, 8);
let names = [
"Bream",
"Haddock",
"Mackerel",
"Pollock",
"Tilefish",
];
ListBox::new("selectables list").build(ui, || {
for (index, name) in names.iter().enumerate() {
let selected = matches!(state.selected_fish2, Some(i) if i == index );
if ui.selectable_config(name).selected(selected).build() {
state.selected_fish2 = Some(index);
}
}
});
let last_size = ui.item_rect_size();
ListBox::new("selectable list 2").size([0.0, last_size[1] * 0.66]).build(ui, || {
for (index, name) in names.iter().enumerate() {
let selected = matches!(state.selected_fish2, Some(i) if i == index );
if ui.selectable_config(name).selected(selected).build() {
state.selected_fish2 = Some(index);
}
}
});
ui.input_text("input text", &mut state.text)
.build();
ui.input_text("input text with hint", &mut state.text_with_hint)
.hint("enter text here")
.build();
ui.input_int("input int", &mut state.i0).build();
// Drag::new("drag int").build(ui, &mut state.i0);
ui.input_float("input float", &mut state.f0)
.step(0.01)
.step_fast(1.0)
.build();
Drag::new("drag float").range(-1.0, 1.0).speed(0.001).build(ui, &mut state.f0);
ui.input_float3("input float3", &mut state.vec3f)
.build();
ui.color_edit3("color 1", &mut state.col1);
ui.color_edit4("color 2", &mut state.col2);
ui.input_scalar("input scalar i64", &mut state.u0).build();
ui.input_scalar("input scalar f64", &mut state.d0).build();
ui.input_scalar_n("input scalar int array", &mut state.vec3i).build();
ui.input_scalar_n("input scalar float array", &mut state.vec3f).build();
if let Some(_t) = ui.tree_node("Multi-component Widgets") {
ui.input_float2("input float2", &mut state.vec2f)
.build();
ui.input_int2("input int2", &mut state.vec2i)
.build();
ui.spacing();
ui.input_float3("input float3", &mut state.vec3f)
.build();
ui.input_int3("input int3", &mut state.vec3i)
.build();
ui.spacing();
};
if let Some(_t) = ui.tree_node("Color/Picker Widgets") {
let s = &mut state.color_edit;
ui.checkbox("With HDR", &mut s.hdr);
ui.same_line();
show_help_marker(
ui,
"Currently all this does is to lift the 0..1 \
limits on dragging widgets.",
);
ui.checkbox("With Alpha Preview", &mut s.alpha_preview);
ui.checkbox(
"With Half Alpha Preview",
&mut s.alpha_half_preview,
);
ui.checkbox("With Options Menu", &mut s.options_menu);
ui.same_line();
show_help_marker(
ui,
"Right-click on the individual color widget to \
show options.",
);
let misc_flags = {
let mut f = ColorEditFlags::empty();
f.set(ColorEditFlags::HDR, s.hdr);
f.set(ColorEditFlags::ALPHA_PREVIEW_HALF, s.alpha_half_preview);
if !s.alpha_half_preview {
f.set(ColorEditFlags::ALPHA_PREVIEW, s.alpha_preview);
}
f.set(ColorEditFlags::NO_OPTIONS, !s.options_menu);
f
};
ui.text("Color widget:");
ui.same_line();
show_help_marker(
ui,
"Click on the colored square to open a color picker.
CTRL+click on individual component to input value.\n",
);
ui.color_edit4_config("MyColor##1", &mut s.color)
.flags(misc_flags)
.alpha(false)
.build();
ui.text("Color widget HSV with Alpha:");
ui.color_edit4_config("MyColor##2", &mut s.color)
.flags(misc_flags)
.input_mode(ColorEditInputMode::HSV)
.build();
ui.text("Color widget with Float Display:");
ui.color_edit4_config("MyColor##2f", &mut s.color)
.flags(misc_flags)
.format(ColorFormat::Float)
.build();
ui.text("Color button with Picker:");
ui.same_line();
show_help_marker(
ui,
"With the inputs(false) function you can hide all \
the slider/text inputs.\n \
With the label(false) function you can pass a non-empty label which \
will only be used for the tooltip and picker popup.",
);
ui.color_edit4_config("MyColor##3", &mut s.color)
.flags(misc_flags)
.inputs(false)
.label(false)
.build();
ui.text("Color picker:");
ui.checkbox("With Alpha", &mut s.alpha);
ui.checkbox("With Alpha Bar", &mut s.alpha_bar);
ui.checkbox("With Side Preview", &mut s.side_preview);
if s.side_preview {
ui.same_line();
ui.checkbox("With Ref Color", &mut s.ref_color);
if s.ref_color {
ui.same_line();
ui.color_edit4_config("##RefColor", &mut s.ref_color_v)
.flags(misc_flags)
.inputs(false)
.build();
}
}
let mut b = ui.color_picker4_config
("MyColor##4", &mut s.color)
.flags(misc_flags)
.alpha(s.alpha)
.alpha_bar(s.alpha_bar)
.side_preview(s.side_preview)
.display_rgb(true);
if s.ref_color {
b = b.reference_color(s.ref_color_v)
}
b.build();
}
}
if CollapsingHeader::new("Layout").build(ui) {
if let Some(_t) = ui.tree_node("Tabs") {
if let Some(_t) = ui.tree_node("Basic") {
TabBar::new("basictabbar").build(ui, || {
TabItem::new("Avocado").build(ui, || {
ui.text("This is the Avocado tab!");
ui.text("blah blah blah blah blah");
});
TabItem::new("Broccoli").build(ui, || {
ui.text("This is the Broccoli tab!");
ui.text("blah blah blah blah blah");
});
TabItem::new("Cucumber").build(ui, || {
ui.text("This is the Cucumber tab!");
ui.text("blah blah blah blah blah");
});
});
}
if let Some(_t) = ui.tree_node("Advanced & Close button") {
ui.separator();
let s = &mut state.tabs;
ui.checkbox("ImGuiTabBarFlags_Reorderable", &mut s.reorderable);
ui.checkbox("ImGuiTabBarFlags_AutoSelectNewTabs", &mut s.autoselect);
ui.checkbox("ImGuiTabBarFlags_TabListPopupButton", &mut s.listbutton);
ui.checkbox("ImGuiTabBarFlags_NoCloseWithMiddleMouseButton", &mut s.noclose_middlebutton);
if ui.checkbox("ImGuiTabBarFlags_FittingPolicyResizeDown", &mut s.fitting_resizedown) {
s.fitting_scroll = !s.fitting_resizedown;
}
if ui.checkbox("ImGuiTabBarFlags_FittingPolicyScroll", &mut s.fitting_scroll) {
s.fitting_resizedown = !s.fitting_scroll;
}
let style = ui.push_style_var(StyleVar::FramePadding([0.0, 0.0]));
ui.checkbox("Artichoke", &mut s.artichoke_tab);
ui.same_line();
ui.checkbox("Beetroot", &mut s.beetroot_tab);
ui.same_line();
ui.checkbox("Celery", &mut s.celery_tab);
ui.same_line();
ui.checkbox("Daikon", &mut s.daikon_tab);
style.pop();
let flags = {
let mut f = TabBarFlags::empty();
f.set(TabBarFlags::REORDERABLE, s.reorderable);
f.set(TabBarFlags::AUTO_SELECT_NEW_TABS, s.autoselect);
f.set(TabBarFlags::TAB_LIST_POPUP_BUTTON, s.listbutton);
f.set(TabBarFlags::NO_CLOSE_WITH_MIDDLE_MOUSE_BUTTON, s.noclose_middlebutton);
f.set(TabBarFlags::FITTING_POLICY_RESIZE_DOWN, s.fitting_resizedown);
f.set(TabBarFlags::FITTING_POLICY_SCROLL, s.fitting_scroll);
f
};
TabBar::new("tabbar").flags(flags).build(ui, || {
TabItem::new("Artichoke").opened(&mut s.artichoke_tab).build(ui, || {
ui.text("This is the Artichoke tab!");
});
TabItem::new("Beetroot").opened(&mut s.beetroot_tab).build(ui, || {
ui.text("This is the Beetroot tab!");
});
TabItem::new("Celery").opened(&mut s.celery_tab).build(ui, || {
ui.text("This is the Celery tab!");
});
TabItem::new("Daikon").opened(&mut s.daikon_tab).build(ui, || {
ui.text("This is the Daikon tab!");
});
});
}
}
}
if CollapsingHeader::new("Filtering").build(ui) {
ui.text_wrapped(
"Filter usage:\n\
\"\" display all lines\n\
\"xxx\" display lines containing \"xxx\"\n\
\"xxx,yyy\" display lines containing \"xxx\" or \"yyy\"\n\
\"-xxx\" hide lines containing \"xxx\""
);
state.filter.draw();
let lines = ["aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world!"];
ui.same_line();
if ui.button("Clear##clear_filter") {
state.filter.clear();
}
for i in lines.iter() {
if state.filter.pass_filter(i) {
ui.bullet_text(i);
}
}
}
if CollapsingHeader::new("Popups & Modal windows").build(ui) {
if let Some(_t) = ui.tree_node("Popups") {
ui.text_wrapped(
"When a popup is active, it inhibits interacting \
with windows that are behind the popup. Clicking \
outside the popup closes it."
);
let names = [
"Bream",
"Haddock",
"Mackerel",
"Pollock",
"Tilefish",
];
if ui.small_button("Select..") {
ui.open_popup("select");
}
ui.same_line();
ui.text(match state.selected_fish {
Some(index) => names[index],
None => "<None>",
});
ui.popup("select", || {
ui.text("Aquarium");
ui.separator();
for (index, name) in names.iter().enumerate() {
if ui.selectable(name) {
state.selected_fish = Some(index);
}
}
});
}
if let Some(_t) = ui.tree_node("Modals") {
ui.text_wrapped(
"Modal windows are like popups but the user cannot close \
them by clicking outside the window."
);
if ui.button("Delete..") {
ui.open_popup("Delete?");
}
ui.modal_popup_config("Delete?").always_auto_resize(true).build(|| {
ui.text("All those beautiful files will be deleted.\nThis operation cannot be undone!\n\n");
ui.separator();
let style = ui.push_style_var(StyleVar::FramePadding([0.0, 0.0]));
ui.checkbox("Don't ask me next time", &mut state.dont_ask_me_next_time);
if ui.button_with_size("OK", [120.0, 0.0]) {
ui.close_current_popup();
}
ui.same_line();
if ui.button_with_size("Cancel", [120.0, 0.0]) {
ui.close_current_popup();
}
style.pop();
});
if ui.button("Stacked modals..") {
ui.open_popup("Stacked 1");
}
ui.modal_popup_config("Stacked 1").build(|| {
ui.text(
"Hello from Stacked The First\n\
Using style[StyleColor::ModalWindowDarkening] for darkening."
);
let items = &["aaaa", "bbbb", "cccc", "dddd", "eeee"];
ui.combo_simple_string("Combo", &mut state.stacked_modals_item, items);
ui.color_edit4_config("color", &mut state.stacked_modals_color).build();
if ui.button("Add another modal..") {
ui.open_popup("Stacked 2") ;
}
ui.modal_popup_config("Stacked 2").build(|| {
ui.text("Hello from Stacked The Second");
if ui.button("Close") {
ui.close_current_popup();
}
});
if ui.button("Close") {
ui.close_current_popup();
}
});
}
}
});
}
fn show_example_app_main_menu_bar(ui: &Ui, state: &mut State) {
if let Some(menu_bar) = ui.begin_main_menu_bar() {
if let Some(menu) = ui.begin_menu("File") {
show_example_menu_file(ui, &mut state.file_menu);
menu.end();
}
if let Some(menu) = ui.begin_menu("Edit") {
ui.menu_item_config("Undo").shortcut("CTRL+Z").build();
ui.menu_item_config("Redo")
.shortcut("CTRL+Y")
.enabled(false)
.build();
ui.separator();
ui.menu_item_config("Cut").shortcut("CTRL+X").build();
ui.menu_item_config("Copy").shortcut("CTRL+C").build();
ui.menu_item_config("Paste").shortcut("CTRL+V").build();
menu.end();
}
menu_bar.end();
}
}
fn show_example_menu_file(ui: &Ui, state: &mut FileMenuState) {
ui.menu_item_config("(dummy_menu)").enabled(false).build();
ui.menu_item("New");
ui.menu_item_config("Open").shortcut("Ctrl+O").build();
if let Some(_menu) = ui.begin_menu("Open Recent") {
ui.menu_item("fish_hat.c");
ui.menu_item("fish_hat.inl");
ui.menu_item("fish_hat.h");
if let Some(menu) = ui.begin_menu("More..") {
ui.menu_item("Hello");
ui.menu_item("Sailor");
if let Some(_menu) = ui.begin_menu("Recurse..") {
show_example_menu_file(ui, state);
menu.end();
}
}
}
ui.menu_item_config("Save").shortcut("Ctrl+S").build();
ui.menu_item("Save As..");
ui.separator();
if let Some(_menu) = ui.begin_menu("Options") {
ui.menu_item_config("Enabled")
.build_with_ref(&mut state.enabled);
ui.child_window("child")
.size([0.0, 60.0])
.border(true)
.build(|| {
for i in 0..10 {
ui.text(format!("Scrolling Text {}", i));
}
});
ui.slider("Value", 0.0, 1.0, &mut state.f);
ui.input_float("Input", &mut state.f).step(0.1).build();
let items = ["Yes", "No", "Maybe"];
ui.combo_simple_string("Combo", &mut state.n, &items);
ui.checkbox("Check", &mut state.b);
}
if let Some(_menu) = ui.begin_menu("Colors") {
for &col in StyleColor::VARIANTS.iter() {
ui.menu_item(format!("{:?}", col));
}
}
assert!(ui.begin_menu_with_enabled("Disabled", false).is_none());
ui.menu_item_config("Checked").selected(true).build();
ui.menu_item_config("Quit").shortcut("Alt+F4").build();
}
fn show_example_app_auto_resize(ui: &Ui, state: &mut AutoResizeState, opened: &mut bool) {
ui.window("Example: Auto-resizing window")
.opened(opened)
.always_auto_resize(true)
.build(|| {
ui.text(
"Window will resize every-ui to the size of its content.
Note that you probably don't want to query the window size to
output your content because that would create a feedback loop.",
);
ui.slider("Number of lines", 1, 20, &mut state.lines);
for i in 0..state.lines {
ui.text(format!("{:2$}This is line {}", "", i, i as usize * 4));
}
});
}
fn show_example_app_fixed_overlay(ui: &Ui, opened: &mut bool) {
const DISTANCE: f32 = 10.0;
let window_pos = [DISTANCE, DISTANCE];
let style = ui.push_style_color(StyleColor::WindowBg, [0.0, 0.0, 0.0, 0.3]);
ui.window("Example: Fixed Overlay")
.opened(opened)
.position(window_pos, Condition::Always)
.title_bar(false)
.resizable(false)
.always_auto_resize(true)
.movable(false)
.save_settings(false)
.build(|| {
ui.text(
"Simple overlay\nin the corner of the screen.\n(right-click to change position)",
);
ui.separator();
let mouse_pos = ui.io().mouse_pos;
ui.text(format!(
"Mouse Position: ({:.1},{:.1})",
mouse_pos[0], mouse_pos[1]
));
});
style.pop();
}
fn show_example_app_manipulating_window_title(ui: &Ui) {
ui.window("Same title as another window##1")
.position([100.0, 100.0], Condition::FirstUseEver)
.build(|| {
ui.text(
"This is window 1.
My title is the same as window 2, but my identifier is unique.",
);
});
ui.window("Same title as another window##2")
.position([100.0, 200.0], Condition::FirstUseEver)
.build(|| {
ui.text(
"This is window 2.
My title is the same as window 1, but my identifier is unique.",
);
});
let chars = ['|', '/', '-', '\\'];
let ch_idx = (ui.time() / 0.25) as usize & 3;