/
lib.rs
2504 lines (2351 loc) · 79.2 KB
/
lib.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
#![allow(non_upper_case_globals)]
#[macro_use]
extern crate bitflags;
extern crate libc;
#[cfg(feature = "gfx")]
#[macro_use]
extern crate gfx;
#[cfg(feature = "glium")]
extern crate glium;
use std::convert::From;
use std::mem;
use std::os::raw::{c_char, c_float, c_int, c_short, c_uchar, c_uint, c_ushort, c_void};
use std::slice;
#[cfg(feature = "gfx")]
mod gfx_support;
#[cfg(feature = "glium")]
mod glium_support;
/// ImGui context (opaque)
pub enum ImGuiContext { }
/// 32-bit unsigned integer (typically used to store packed colors)
pub type ImU32 = c_uint;
/// Character for keyboard input/display
pub type ImWchar = c_ushort;
/// User data to identify a texture
pub type ImTextureID = *mut c_void;
/// Unique ID used by widgets (typically hashed from a stack of string)
pub type ImGuiID = ImU32;
/// A color identifier for styling
#[repr(C)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ImGuiCol {
Text,
TextDisabled,
WindowBg,
ChildBg,
PopupBg,
Border,
BorderShadow,
FrameBg,
FrameBgHovered,
FrameBgActive,
TitleBg,
TitleBgActive,
TitleBgCollapsed,
MenuBarBg,
ScrollbarBg,
ScrollbarGrab,
ScrollbarGrabHovered,
ScrollbarGrabActive,
CheckMark,
SliderGrab,
SliderGrabActive,
Button,
ButtonHovered,
ButtonActive,
Header,
HeaderHovered,
HeaderActive,
Separator,
SeparatorHovered,
SeparatorActive,
ResizeGrip,
ResizeGripHovered,
ResizeGripActive,
CloseButton,
CloseButtonHovered,
CloseButtonActive,
PlotLines,
PlotLinesHovered,
PlotHistogram,
PlotHistogramHovered,
TextSelectedBg,
ModalWindowDarkening,
DragDropTarget,
}
impl ImGuiCol {
#[deprecated(since = "0.0.19", note = "ComboBg has been merged with PopupBg. Please use PopupBg instead")]
pub const ComboBg: ImGuiCol = ImGuiCol::PopupBg;
#[deprecated(since = "0.0.19", note = "please use ChildBg instead")]
pub const ChildWindowBg: ImGuiCol = ImGuiCol::ChildBg;
pub fn values() -> &'static [ImGuiCol] {
use ImGuiCol::*;
static values: &'static [ImGuiCol] = &[
Text,
TextDisabled,
WindowBg,
ChildBg,
PopupBg,
Border,
BorderShadow,
FrameBg,
FrameBgHovered,
FrameBgActive,
TitleBg,
TitleBgActive,
TitleBgCollapsed,
MenuBarBg,
ScrollbarBg,
ScrollbarGrab,
ScrollbarGrabHovered,
ScrollbarGrabActive,
CheckMark,
SliderGrab,
SliderGrabActive,
Button,
ButtonHovered,
ButtonActive,
Header,
HeaderHovered,
HeaderActive,
Separator,
SeparatorHovered,
SeparatorActive,
ResizeGrip,
ResizeGripHovered,
ResizeGripActive,
CloseButton,
CloseButtonHovered,
CloseButtonActive,
PlotLines,
PlotLinesHovered,
PlotHistogram,
PlotHistogramHovered,
TextSelectedBg,
ModalWindowDarkening,
DragDropTarget,
];
values
}
}
pub const ImGuiCol_COUNT: usize = 43;
/// A variable identifier for styling
#[repr(C)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ImGuiStyleVar {
Alpha,
WindowPadding,
WindowRounding,
WindowBorderSize,
WindowMinSize,
ChildRounding,
ChildBorderSize,
PopupRounding,
PopupBorderSize,
FramePadding,
FrameRounding,
FrameBorderSize,
ItemSpacing,
ItemInnerSpacing,
IndentSpacing,
GrabMinSize,
ButtonTextAlign,
}
pub const ImGuiStyleVar_COUNT: usize = 17;
impl ImGuiStyleVar {
#[deprecated(since = "0.0.19", note = "please use ChildRounding instead")]
pub const ChildWindowRounding: ImGuiStyleVar = ImGuiStyleVar::ChildRounding;
}
/// A key identifier (ImGui-side enum)
#[repr(C)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ImGuiKey {
Tab,
LeftArrow,
RightArrow,
UpArrow,
DownArrow,
PageUp,
PageDown,
Home,
End,
Delete,
Backspace,
Enter,
Escape,
A,
C,
V,
X,
Y,
Z,
}
pub const ImGuiKey_COUNT: usize = 19;
bitflags!(
/// Color edit flags
#[repr(C)]
pub struct ImGuiColorEditFlags: c_int {
const NoAlpha = 1 << 1;
const NoPicker = 1 << 2;
const NoOptions = 1 << 3;
const NoSmallPreview = 1 << 4;
const NoInputs = 1 << 5;
const NoTooltip = 1 << 6;
const NoLabel = 1 << 7;
const NoSidePreview = 1 << 8;
const AlphaBar = 1 << 9;
const AlphaPreview = 1 << 10;
const AlphaPreviewHalf = 1 << 11;
const HDR = 1 << 12;
const RGB = 1 << 13;
const HSV = 1 << 14;
const HEX = 1 << 15;
const Uint8 = 1 << 16;
const Float = 1 << 17;
const PickerHueBar = 1 << 18;
const PickerHueWheel = 1 << 19;
}
);
/// A mouse cursor identifier
#[repr(C)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ImGuiMouseCursor {
None = -1,
Arrow,
TextInput,
Move,
ResizeNS,
ResizeEW,
ResizeNESW,
ResizeNWSE,
}
pub const ImGuiMouseCursor_COUNT: usize = 7;
bitflags!(
/// Window flags
#[repr(C)]
pub struct ImGuiWindowFlags: c_int {
const NoTitleBar = 1;
const NoResize = 1 << 1;
const NoMove = 1 << 2;
const NoScrollbar = 1 << 3;
const NoScrollWithMouse = 1 << 4;
const NoCollapse = 1 << 5;
const AlwaysAutoResize = 1 << 6;
const NoSavedSettings = 1 << 8;
const NoInputs = 1 << 9;
const MenuBar = 1 << 10;
const HorizontalScrollbar = 1 << 11;
const NoFocusOnAppearing = 1 << 12;
const NoBringToFrontOnFocus = 1 << 13;
const AlwaysVerticalScrollbar = 1 << 14;
const AlwaysHorizontalScrollbar = 1 << 15;
const AlwaysUseWindowPadding = 1 << 16;
const ResizeFromAnySide = 1 << 17;
}
);
bitflags!(
/// Condition flags
#[repr(C)]
pub struct ImGuiCond: c_int {
const Always = 1;
const Once = 1 << 1;
const FirstUseEver = 1 << 2;
const Appearing = 1 << 3;
}
);
bitflags!(
/// Flags for text inputs
#[repr(C)]
pub struct ImGuiInputTextFlags: c_int {
const CharsDecimal = 1;
const CharsHexadecimal = 1 << 1;
const CharsUppercase = 1 << 2;
const CharsNoBlank = 1 << 3;
const AutoSelectAll = 1 << 4;
const EnterReturnsTrue = 1 << 5;
const CallbackCompletion = 1 << 6;
const CallbackHistory = 1 << 7;
const CallbackAlways = 1 << 8;
const CallbackCharFilter = 1 << 9;
const AllowTabInput = 1 << 10;
const CtrlEnterForNewLine = 1 << 11;
const NoHorizontalScroll = 1 << 12;
const AlwaysInsertMode = 1 << 13;
const ReadOnly = 1 << 14;
const Password = 1 << 15;
const NoUndoRedo = 1 << 16;
}
);
bitflags!(
/// Flags for selectables
#[repr(C)]
pub struct ImGuiSelectableFlags: c_int {
const DontClosePopups = 1;
const SpanAllColumns = 1 << 1;
const AllowDoubleClick = 1 << 2;
}
);
bitflags!(
/// Flags for trees and collapsing headers
#[repr(C)]
pub struct ImGuiTreeNodeFlags: c_int {
const Selected = 1;
const Framed = 1 << 1;
#[deprecated(since = "0.0.19", note = "please use AllowItemOverlap instead")]
const AllowOverlapMode = 1 << 2;
const AllowItemOverlap = 1 << 2;
const NoTreePushOnOpen = 1 << 3;
const NoAutoOpenOnLog = 1 << 4;
const DefaultOpen = 1 << 5;
const OpenOnDoubleClick = 1 << 6;
const OpenOnArrow = 1 << 7;
const Leaf = 1 << 8;
const Bullet = 1 << 9;
const FramePadding = 1 << 10;
const CollapsingHeader =
ImGuiTreeNodeFlags::Framed.bits | ImGuiTreeNodeFlags::NoAutoOpenOnLog.bits;
}
);
bitflags!(
/// Flags for window focus check
#[repr(C)]
pub struct ImGuiFocusedFlags: c_int {
const ChildWindows = 1 << 0;
const RootWindow = 1 << 1;
const RootAndChildWindows =
ImGuiFocusedFlags::RootWindow.bits | ImGuiFocusedFlags::ChildWindows.bits;
}
);
bitflags!(
/// Flags for hover checks
#[repr(C)]
pub struct ImGuiHoveredFlags: c_int {
const ChildWindows = 1 << 0;
const RootWindow = 1 << 1;
const AllowWhenBlockedByPopup = 1 << 2;
const AllowWhenBlockedByActiveItem = 1 << 4;
const AllowWhenOverlapped = 1 << 5;
const RectOnly = ImGuiHoveredFlags::AllowWhenBlockedByPopup.bits
| ImGuiHoveredFlags::AllowWhenBlockedByActiveItem.bits
| ImGuiHoveredFlags::AllowWhenOverlapped.bits;
const RootAndChildWindows = ImGuiFocusedFlags::RootWindow.bits
| ImGuiFocusedFlags::ChildWindows.bits;
}
);
bitflags!(
/// Flags for igBeginCombo
#[repr(C)]
pub struct ImGuiComboFlags: c_int {
/// Align the popup toward the left by default
const PopupAlignLeft = 1 << 0;
/// Max ~4 items visible.
/// Tip: If you want your combo popup to be a specific size you can use
/// igSetNextWindowSizeConstraints() prior to calling igBeginCombo()
const HeightSmall = 1 << 1;
/// Max ~8 items visible (default)
const HeightRegular = 1 << 2;
/// Max ~20 items visible
const HeightLarge = 1 << 3;
/// As many fitting items as possible
const HeightLargest = 1 << 4;
const HeightMask = ImGuiComboFlags::HeightSmall.bits
| ImGuiComboFlags::HeightRegular.bits
| ImGuiComboFlags::HeightLarge.bits
| ImGuiComboFlags::HeightLargest.bits;
}
);
bitflags!(
/// Flags for igBeginDragDropSource(), igAcceptDragDropPayload()
#[repr(C)]
pub struct ImGuiDragDropFlags: c_int {
// BeginDragDropSource() flags
/// By default, a successful call to igBeginDragDropSource opens a
/// tooltip so you can display a preview or description of the source
/// contents. This flag disable this behavior.
const SourceNoPreviewTooltip = 1 << 0;
/// By default, when dragging we clear data so that igIsItemHovered()
/// will return true, to avoid subsequent user code submitting tooltips.
/// This flag disable this behavior so you can still call
/// igIsItemHovered() on the source item.
const SourceNoDisableHover = 1 << 1;
/// Disable the behavior that allows to open tree nodes and collapsing
/// header by holding over them while dragging a source item.
const SourceNoHoldToOpenOthers = 1 << 2;
/// Allow items such as igText(), igImage() that have no unique
/// identifier to be used as drag source, by manufacturing a temporary
/// identifier based on their window-relative position. This is
/// extremely unusual within the dear imgui ecosystem and so we made it
/// explicit.
const SourceAllowNullID = 1 << 3;
/// External source (from outside of imgui), won't attempt to read
/// current item/window info. Will always return true. Only one Extern
/// source can be active simultaneously.
const SourceExtern = 1 << 4;
// AcceptDragDropPayload() flags
/// igAcceptDragDropPayload() will returns true even before the mouse
/// button is released. You can then call igIsDelivery() to test if the
/// payload needs to be delivered.
const AcceptBeforeDelivery = 1 << 10;
/// Do not draw the default highlight rectangle when hovering over target.
const AcceptNoDrawDefaultRect = 1 << 11;
/// For peeking ahead and inspecting the payload before delivery.
const AcceptPeekOnly = ImGuiDragDropFlags::AcceptBeforeDelivery.bits
| ImGuiDragDropFlags::AcceptNoDrawDefaultRect.bits;
}
);
bitflags!(
/// Flags for indictating which corner of a rectangle should be rounded
#[repr(C)]
pub struct ImDrawCornerFlags: c_int {
const TopLeft = 1 << 0;
const TopRight = 1 << 1;
const BotLeft = 1 << 2;
const BotRight = 1 << 3;
const Top = ImDrawCornerFlags::TopLeft.bits
| ImDrawCornerFlags::TopRight.bits;
const Bot = ImDrawCornerFlags::BotLeft.bits
| ImDrawCornerFlags::BotRight.bits;
const Left = ImDrawCornerFlags::TopLeft.bits
| ImDrawCornerFlags::BotLeft.bits;
const Right = ImDrawCornerFlags::TopRight.bits
| ImDrawCornerFlags::BotRight.bits;
const All = 0xF;
}
);
bitflags!(
#[repr(C)]
pub struct ImDrawListFlags: c_int {
const AntiAliasedLines = 1 << 0;
const AntiAliasedFill = 1 << 1;
}
);
pub type ImGuiTextEditCallback = Option<
extern "C" fn(data: *mut ImGuiTextEditCallbackData) -> c_int,
>;
pub type ImGuiSizeConstraintCallback =
Option<extern "C" fn(data: *mut ImGuiSizeConstraintCallbackData)>;
/// A tuple of 2 floating-point values
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, PartialEq)]
pub struct ImVec2 {
pub x: c_float,
pub y: c_float,
}
impl ImVec2 {
pub fn new(x: f32, y: f32) -> ImVec2 {
ImVec2 {
x: x as c_float,
y: y as c_float,
}
}
pub fn zero() -> ImVec2 {
ImVec2 {
x: 0.0 as c_float,
y: 0.0 as c_float,
}
}
}
impl From<[f32; 2]> for ImVec2 {
fn from(array: [f32; 2]) -> ImVec2 { ImVec2::new(array[0], array[1]) }
}
impl From<(f32, f32)> for ImVec2 {
fn from((x, y): (f32, f32)) -> ImVec2 { ImVec2::new(x, y) }
}
impl Into<[f32; 2]> for ImVec2 {
fn into(self) -> [f32; 2] { [self.x, self.y] }
}
impl Into<(f32, f32)> for ImVec2 {
fn into(self) -> (f32, f32) { (self.x, self.y) }
}
/// A tuple of 4 floating-point values
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, PartialEq)]
pub struct ImVec4 {
pub x: c_float,
pub y: c_float,
pub z: c_float,
pub w: c_float,
}
impl ImVec4 {
pub fn new(x: f32, y: f32, z: f32, w: f32) -> ImVec4 {
ImVec4 {
x: x as c_float,
y: y as c_float,
z: z as c_float,
w: w as c_float,
}
}
pub fn zero() -> ImVec4 {
ImVec4 {
x: 0.0 as c_float,
y: 0.0 as c_float,
z: 0.0 as c_float,
w: 0.0 as c_float,
}
}
}
impl From<[f32; 4]> for ImVec4 {
fn from(array: [f32; 4]) -> ImVec4 { ImVec4::new(array[0], array[1], array[2], array[3]) }
}
impl From<(f32, f32, f32, f32)> for ImVec4 {
fn from((x, y, z, w): (f32, f32, f32, f32)) -> ImVec4 { ImVec4::new(x, y, z, w) }
}
impl Into<[f32; 4]> for ImVec4 {
fn into(self) -> [f32; 4] { [self.x, self.y, self.z, self.w] }
}
impl Into<(f32, f32, f32, f32)> for ImVec4 {
fn into(self) -> (f32, f32, f32, f32) { (self.x, self.y, self.z, self.w) }
}
/// Runtime data for styling/colors
#[repr(C)]
pub struct ImGuiStyle {
/// Global alpha applies to everything in ImGui
pub alpha: c_float,
/// Padding within a window
pub window_padding: ImVec2,
/// Radius of window corners rounding. Set to 0.0f to have rectangular windows
pub window_rounding: c_float,
/// Thickness of border around windows. Generally set to 0.0f or 1.0f. Other values not well tested.
pub window_border_size: c_float,
/// Minimum window size
pub window_min_size: ImVec2,
/// Alignment for title bar text. Defaults to (0.0f, 0.5f) for left-aligned, vertically centered
pub window_title_align: ImVec2,
/// Radius of child window corners rounding. Set to 0.0f to have rectangular child windows
pub child_rounding: c_float,
/// Thickness of border around child windows. Generally set to 0.0f or 1.0f. Other values not well tested.
pub child_border_size: c_float,
/// Radius of popup window corners rounding. Set to 0.0f to have rectangular child windows
pub popup_rounding: c_float,
/// Thickness of border around popup or tooltip windows. Generally set to 0.0f or 1.0f. Other values not well tested.
pub popup_border_size: c_float,
/// Padding within a framed rectangle (used by most widgets)
pub frame_padding: ImVec2,
/// Radius of frame corners rounding. Set to 0.0f to have rectangular frames (used by most
/// widgets).
pub frame_rounding: c_float,
/// Thickness of border around frames. Generally set to 0.0f or 1.0f. Other values not well tested.
pub frame_border_size: c_float,
/// Horizontal and vertical spacing between widgets/lines
pub item_spacing: ImVec2,
/// Horizontal and vertical spacing between within elements of a composed
/// widget (e.g. a slider and its label)
pub item_inner_spacing: ImVec2,
/// Expand reactive bounding box for touch-based system where touch position is not accurate
/// enough. Unfortunately we don't sort widgets so priority on overlap will always be given
/// to the first widget. So don't grow this too much!
pub touch_extra_padding: ImVec2,
/// Horizontal spacing when e.g. entering a tree node.
/// Generally == (FontSize + FramePadding.x*2).
pub indent_spacing: c_float,
/// Minimum horizontal spacing between two columns
pub columns_min_spacing: c_float,
/// Width of the vertical scrollbar, Height of the horizontal scrollbar
pub scrollbar_size: c_float,
/// Width of the vertical scrollbar, Height of the horizontal scrollbar
pub scrollbar_rounding: c_float,
/// Minimum width/height of a grab box for slider/scrollbar
pub grab_min_size: c_float,
/// Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
pub grab_rounding: c_float,
/// Alignment of button text when button is larger than text. Defaults to (0.5f, 0.5f)
/// for horizontally + vertically centered
pub button_text_align: ImVec2,
/// Window positions are clamped to be visible within the display area by at least this
/// amount. Only covers regular windows.
pub display_window_padding: ImVec2,
/// If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding.
/// Covers popups/tooltips as well regular windows.
pub display_safe_area_padding: ImVec2,
/// Enable anti-aliasing on lines/borders. Disable if you are really short on CPU/GPU.
pub anti_aliased_lines: bool,
/// Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.)
pub anti_aliased_fill: bool,
/// Tessellation tolerance. Decrease for highly tessellated curves (higher quality, more
/// polygons), increase to reduce quality.
pub curve_tessellation_tol: c_float,
/// Colors for the user interface
pub colors: [ImVec4; ImGuiCol_COUNT],
}
/// Main configuration and I/O between your application and ImGui
#[repr(C)]
pub struct ImGuiIO {
pub display_size: ImVec2,
pub delta_time: c_float,
pub ini_saving_rate: c_float,
pub ini_filename: *const c_char,
pub log_filename: *const c_char,
pub mouse_double_click_time: c_float,
pub mouse_double_click_max_dist: c_float,
pub mouse_drag_threshold: c_float,
pub key_map: [c_int; ImGuiKey_COUNT],
pub key_repeat_delay: c_float,
pub key_repeat_rate: c_float,
pub user_data: *mut c_void,
pub fonts: *mut ImFontAtlas,
pub font_global_scale: c_float,
pub font_allow_user_scaling: bool,
pub font_default: *mut ImFont,
pub display_framebuffer_scale: ImVec2,
pub display_visible_min: ImVec2,
pub display_visible_max: ImVec2,
pub opt_mac_osx_behaviors: bool,
pub opt_cursor_blink: bool,
pub render_draw_lists_fn: Option<extern "C" fn(data: *mut ImDrawData)>,
pub get_clipboard_text_fn: Option<extern "C" fn(user_data: *mut c_void) -> *const c_char>,
pub set_clipboard_text_fn: Option<extern "C" fn(user_data: *mut c_void, text: *const c_char)>,
pub clipboard_user_data: *mut c_void,
pub mem_alloc_fn: Option<extern "C" fn(sz: usize) -> *mut c_void>,
pub mem_free_fn: Option<extern "C" fn(ptr: *mut c_void)>,
pub ime_set_input_screen_pos_fn: Option<extern "C" fn(x: c_int, y: c_int)>,
pub ime_window_handle: *mut c_void,
pub mouse_pos: ImVec2,
pub mouse_down: [bool; 5],
pub mouse_wheel: c_float,
pub mouse_draw_cursor: bool,
pub key_ctrl: bool,
pub key_shift: bool,
pub key_alt: bool,
pub key_super: bool,
pub keys_down: [bool; 512],
pub input_characters: [ImWchar; 16 + 1],
pub want_capture_mouse: bool,
pub want_capture_keyboard: bool,
pub want_text_input: bool,
pub want_move_mouse: bool,
pub framerate: c_float,
pub metrics_allocs: c_int,
pub metrics_render_vertices: c_int,
pub metrics_render_indices: c_int,
pub metrics_active_windows: c_int,
pub mouse_delta: ImVec2,
mouse_pos_prev: ImVec2,
mouse_clicked_pos: [ImVec2; 5],
mouse_clicked_time: [c_float; 5],
mouse_clicked: [bool; 5],
mouse_double_clicked: [bool; 5],
mouse_released: [bool; 5],
mouse_down_owned: [bool; 5],
mouse_down_duration: [c_float; 5],
mouse_down_duration_prev: [c_float; 5],
mouse_drag_max_distance_abs: [ImVec2; 5],
mouse_drag_max_distance_sqr: [c_float; 5],
keys_down_duration: [c_float; 512],
keys_down_duration_prev: [c_float; 512],
}
/// Lightweight vector struct
#[repr(C)]
pub struct ImVector<T> {
pub size: c_int,
pub capacity: c_int,
pub data: *mut T,
}
impl<T> ImVector<T> {
pub unsafe fn as_slice(&self) -> &[T] { slice::from_raw_parts(self.data, self.size as usize) }
}
#[repr(C)]
pub struct TextRange {
pub begin: *const c_char,
pub end: *const c_char,
}
#[repr(C)]
pub struct ImGuiTextFilter {
pub input_buf: [c_char; 256],
pub filters: ImVector<TextRange>,
pub count_grep: c_int,
}
/// Data payload for Drag and Drop operations
#[repr(C)]
pub struct ImGuiPayload {
/// Data (copied and owned by dear imgui)
pub data: *const c_void,
/// Data size
pub data_size: c_int,
/// Source item id
source_id: ImGuiID,
/// Source parent id (if available)
source_parent_id: ImGuiID,
/// Data timestamp
data_frame_count: c_int,
/// Data type tag (short user-supplied string)
data_type: [c_char; 8 + 1],
/// Set when AcceptDragDropPayload() was called and mouse has been hovering the target item (nb: handle overlapping drag targets)
preview: bool,
/// Set when AcceptDragDropPayload() was called and mouse button is released over the target item.
delivery: bool,
}
#[repr(C)]
pub struct ImGuiTextBuffer {
pub buf: ImVector<c_char>,
}
#[repr(C)]
pub struct Pair {
pub key: ImGuiID,
pub value: PairValue,
}
#[repr(C)]
pub union PairValue {
val_i: c_int,
val_f: c_float,
val_p: *mut c_void,
}
#[repr(C)]
pub struct ImGuiStorage {
pub data: ImVector<Pair>,
}
#[repr(C)]
pub struct ImGuiTextEditCallbackData {
pub event_flag: ImGuiInputTextFlags,
pub flags: ImGuiInputTextFlags,
pub user_data: *mut c_void,
pub read_only: bool,
pub event_char: ImWchar,
pub event_key: ImGuiKey,
pub buf: *mut c_char,
pub buf_text_len: c_int,
pub buf_size: c_int,
pub buf_dirty: bool,
pub cursor_pos: c_int,
pub selection_start: c_int,
pub selection_end: c_int,
}
#[repr(C)]
pub struct ImGuiSizeConstraintCallbackData {
pub user_data: *mut c_void,
pub pos: ImVec2,
pub current_size: ImVec2,
pub desired_size: ImVec2,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Default)]
pub struct ImColor {
pub value: ImVec4,
}
/// Helper to manually clip large list of items
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct ImGuiListClipper {
pub start_pos_y: c_float,
pub items_height: c_float,
pub items_count: c_int,
pub step_no: c_int,
pub display_start: c_int,
pub display_end: c_int,
}
pub type ImDrawCallback = Option<
extern "C" fn(parent_list: *const ImDrawList,
cmd: *const ImDrawCmd),
>;
/// A single draw command within a parent ImDrawList (generally maps to 1 GPU draw call)
#[repr(C)]
pub struct ImDrawCmd {
pub elem_count: c_uint,
pub clip_rect: ImVec4,
pub texture_id: ImTextureID,
pub user_callback: ImDrawCallback,
pub user_callback_data: *mut c_void,
}
/// Vertex index
pub type ImDrawIdx = c_ushort;
/// A single vertex
#[repr(C)]
#[derive(Copy, Clone, Debug, Default)]
pub struct ImDrawVert {
pub pos: ImVec2,
pub uv: ImVec2,
pub col: ImU32,
}
/// Temporary storage for outputting drawing commands out of order
#[repr(C)]
pub struct ImDrawChannel {
pub cmd_buffer: ImVector<ImDrawCmd>,
pub idx_buffer: ImVector<ImDrawIdx>,
}
/// A single draw command list (generally one per window)
#[repr(C)]
pub struct ImDrawList {
pub cmd_buffer: ImVector<ImDrawCmd>,
pub idx_buffer: ImVector<ImDrawIdx>,
pub vtx_buffer: ImVector<ImDrawVert>,
flags: ImDrawListFlags,
data: *const ImDrawListSharedData,
owner_name: *const c_char,
vtx_current_idx: c_uint,
vtx_write_ptr: *mut ImDrawVert,
idx_write_ptr: *mut ImDrawIdx,
clip_rect_stack: ImVector<ImVec4>,
texture_id_stack: ImVector<ImTextureID>,
path: ImVector<ImVec2>,
channels_current: c_int,
channels_count: c_int,
channels: ImVector<ImDrawChannel>,
}
#[repr(C)]
pub struct ImDrawListSharedData {
/// UV of white pixel in the atlas
tex_uv_white_pixel: ImVec2,
/// Current/default font (optional, for simplified AddText overload)
font: *mut ImFont,
/// Current/default font size (optional, for simplified AddText overload)
font_size: c_float,
curve_tessellation_tol: c_float,
/// Value for PushClipRectFullscreen()
clip_rect_fullscreen: ImVec4,
circle_vtx12: [ImVec2; 12],
}
/// All draw command lists required to render the frame
#[repr(C)]
pub struct ImDrawData {
pub valid: bool,
pub cmd_lists: *mut *mut ImDrawList,
pub cmd_lists_count: c_int,
pub total_vtx_count: c_int,
pub total_idx_count: c_int,
}
impl ImDrawData {
pub unsafe fn cmd_lists(&self) -> &[*const ImDrawList] {
let cmd_lists: *const *const ImDrawList = mem::transmute(self.cmd_lists);
slice::from_raw_parts(cmd_lists, self.cmd_lists_count as usize)
}
}
/// Configuration data when adding a font or merging fonts
#[repr(C)]
pub struct ImFontConfig {
pub font_data: *mut c_void,
pub font_data_size: c_int,
pub font_data_owned_by_atlas: bool,
pub font_no: c_int,
pub size_pixels: c_float,
pub oversample_h: c_int,
pub oversample_v: c_int,
pub pixel_snap_h: bool,
pub glyph_extra_spacing: ImVec2,
pub glyph_offset: ImVec2,
pub glyph_ranges: *const ImWchar,
pub merge_mode: bool,
pub rasterizer_flags: c_uint,
pub rasterizer_multiply: c_float,
name: [c_char; 32],
dst_font: *mut ImFont,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Default)]
pub struct ImFontGlyph {
codepoint: ImWchar,
advance_x: c_float,
x0: c_float,
y0: c_float,
x1: c_float,
y1: c_float,
u0: c_float,
v0: c_float,
u1: c_float,
v1: c_float,
}
#[repr(C)]
pub struct CustomRect {
pub id: c_uint,
pub width: c_ushort,
pub height: c_ushort,
pub x: c_ushort,
pub y: c_ushort,
pub glyph_advance_x: c_float,
pub glyph_offset: ImVec2,
pub font: *mut ImFont,
}
/// Runtime data for multiple fonts, bake multiple fonts into a single texture, TTF/OTF font loader
#[repr(C)]
pub struct ImFontAtlas {
pub tex_id: *mut c_void,
pub tex_desired_width: c_int,
pub tex_glyph_padding: c_int,
tex_pixels_alpha8: *mut c_uchar,
tex_pixels_rgba32: *mut c_uint,
tex_width: c_int,
tex_height: c_int,
tex_uv_white_pixel: ImVec2,
fonts: ImVector<*mut ImFont>,
custom_rects: ImVector<CustomRect>,
config_data: ImVector<ImFontConfig>,
custom_rect_ids: [c_int; 1],
}
/// Runtime data for a single font within a parent ImFontAtlas
#[repr(C)]
pub struct ImFont {
font_size: c_float,
scale: c_float,
display_offset: ImVec2,
glyphs: ImVector<ImFontGlyph>,
index_advance_x: ImVector<c_float>,
index_lookup: ImVector<c_ushort>,
fallback_glyph: *const ImFontGlyph,
fallback_advance_x: c_float,
fallback_char: ImWchar,
config_data_count: c_short,
config_data: *mut ImFontConfig,
container_atlas: *mut ImFontAtlas,
ascent: c_float,
descent: c_float,
metrics_total_surface: c_int,
}
// Main
extern "C" {
pub fn igGetIO() -> *mut ImGuiIO;
pub fn igGetStyle() -> *mut ImGuiStyle;
pub fn igGetDrawData() -> *mut ImDrawData;
pub fn igNewFrame();
pub fn igRender();
pub fn igEndFrame();
pub fn igShutdown();
}
// Demo/Debug/Info
extern "C" {
pub fn igShowDemoWindow(opened: *mut bool);
pub fn igShowMetricsWindow(opened: *mut bool);
pub fn igShowStyleEditor(style: *mut ImGuiStyle);
pub fn igShowStyleSelector(label: *const c_char);
pub fn igShowFontSelector(label: *const c_char);
pub fn igShowUserGuide();
}