-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathlib.rs
6100 lines (4880 loc) · 180 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
#![cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ptr))] // TODO later
#![cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] // TODO later
#![cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))] // API requirement
#![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] // API requirement
#![cfg_attr(feature = "cargo-clippy", allow(trivially_copy_pass_by_ref))] // API requirement
#![cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] // required by allocator
#![cfg_attr(feature = "cargo-clippy", allow(non_upper_case_globals))]
#![allow(non_upper_case_globals)]
#![cfg_attr(feature = "rust_allocator", feature(allocator_api))]
#[macro_use]
extern crate log;
#[cfg(feature = "rust_allocator")]
mod alloc_heap;
mod alloc_vec;
use std::borrow::Cow;
use std::default::Default;
use std::os::raw::*;
use nuklear_sys::*;
pub use nuklear_sys;
pub use nuklear_sys::nk_allocation_type as AllocationType;
pub use nuklear_sys::nk_draw_list_stroke as DrawListStroke;
pub use nuklear_sys::nk_flags as Flags; //TODO
pub use nuklear_sys::nk_font_coord_type as FontCoordType;
pub use nuklear_sys::nk_panel_row_layout_type as PanelRowLayoutType;
pub use nuklear_sys::nk_panel_type as PanelType;
pub use nuklear_sys::nk_style_colors as StyleColor;
pub use nuklear_sys::nk_style_cursor as StyleCursor;
pub use nuklear_sys::nk_style_header_align as StyleHeaderAlign;
pub use nuklear_sys::nk_widget_layout_states as WidgetLayoutState;
pub use nuklear_sys::nk_chart_slot as ChartSlot;
pub use nuklear_sys::nk_color as Color;
pub use nuklear_sys::nk_colorf as ColorF;
pub use nuklear_sys::nk_menu_state as MenuState;
pub use nuklear_sys::nk_popup_buffer as PopupBuffer;
pub use nuklear_sys::nk_rect as Rect;
pub use nuklear_sys::nk_recti as Recti;
pub use nuklear_sys::nk_scroll as Scroll;
pub use nuklear_sys::nk_size as Size;
pub use nuklear_sys::nk_style_text as StyleText;
pub use nuklear_sys::nk_vec2 as Vec2;
pub use nuklear_sys::nk_vec2i as Vec2i;
pub use nuklear_sys::nk_glyph as Glyph;
pub use nuklear_sys::nk_plugin_copy as PluginCopy;
pub use nuklear_sys::nk_plugin_filter as PluginFilter;
pub use nuklear_sys::nk_plugin_paste as PluginPaste;
pub const NK_FILTER_DEFAULT: PluginFilter = Some(nk_filter_default);
pub const NK_FILTER_ASCII: PluginFilter = Some(nk_filter_ascii);
pub const NK_FILTER_FLOAT: PluginFilter = Some(nk_filter_float);
pub const NK_FILTER_DECIMAL: PluginFilter = Some(nk_filter_decimal);
pub const NK_FILTER_HEX: PluginFilter = Some(nk_filter_hex);
pub const NK_FILTER_OCT: PluginFilter = Some(nk_filter_oct);
pub const NK_FILTER_BINARY: PluginFilter = Some(nk_filter_binary);
pub const ALIGNMENT: usize = 16;
macro_rules! wrapper_impls {
($name:ident, $typ:ty) => {
impl AsRef<$typ> for $name {
fn as_ref(&self) -> &$typ {
&self.internal
}
}
impl AsMut<$typ> for $name {
fn as_mut(&mut self) -> &mut $typ {
&mut self.internal
}
}
impl AsRef<$name> for $typ {
fn as_ref(&self) -> &$name {
unsafe { &*(self as *const $typ as *const $name) }
}
}
impl AsMut<$name> for $typ {
fn as_mut(&mut self) -> &mut $name {
unsafe { &mut *(self as *mut $typ as *mut $name) }
}
}
impl Default for $name {
fn default() -> Self {
$name { internal: unsafe { ::std::mem::zeroed() } }
}
}
};
}
macro_rules! wrapper_type {
($name:ident, $typ:ty) => {
#[derive(Clone)]
#[repr(C)]
pub struct $name {
internal: $typ,
}
wrapper_impls!($name, $typ);
};
}
macro_rules! wrapper_type_no_clone {
($name:ident, $typ:ty) => {
#[repr(C)]
pub struct $name {
internal: $typ,
}
wrapper_impls!($name, $typ);
};
}
macro_rules! from_into_enum {
($name:ident, $typ:ty) => {
impl From<$name> for $typ {
fn from(a: $name) -> $typ {
a as $typ
}
}
impl From<$typ> for $name {
fn from(a: $typ) -> $name {
unsafe { ::std::mem::transmute(a) }
}
}
impl<'a> From<&'a $typ> for &'a $name {
fn from(a: &'a $typ) -> &'a $name {
unsafe { ::std::mem::transmute(a) }
}
}
};
}
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum CommandType {
Nop = nk_command_type_NK_COMMAND_NOP as isize,
Scissor = nk_command_type_NK_COMMAND_SCISSOR as isize,
Line = nk_command_type_NK_COMMAND_LINE as isize,
Curve = nk_command_type_NK_COMMAND_CURVE as isize,
Rect = nk_command_type_NK_COMMAND_RECT as isize,
RectFilled = nk_command_type_NK_COMMAND_RECT_FILLED as isize,
RectMultiColor = nk_command_type_NK_COMMAND_RECT_MULTI_COLOR as isize,
Circle = nk_command_type_NK_COMMAND_CIRCLE as isize,
CircleFilled = nk_command_type_NK_COMMAND_CIRCLE_FILLED as isize,
Arc = nk_command_type_NK_COMMAND_ARC as isize,
ArcFilled = nk_command_type_NK_COMMAND_ARC_FILLED as isize,
Triangle = nk_command_type_NK_COMMAND_TRIANGLE as isize,
TriangleFilled = nk_command_type_NK_COMMAND_TRIANGLE_FILLED as isize,
Polygon = nk_command_type_NK_COMMAND_POLYGON as isize,
PolygonFilled = nk_command_type_NK_COMMAND_POLYGON_FILLED as isize,
Polyline = nk_command_type_NK_COMMAND_POLYLINE as isize,
Text = nk_command_type_NK_COMMAND_TEXT as isize,
Image = nk_command_type_NK_COMMAND_IMAGE as isize,
Custom = nk_command_type_NK_COMMAND_CUSTOM as isize,
}
from_into_enum!(CommandType, nk_command_type);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum SymbolType {
None = nk_symbol_type_NK_SYMBOL_NONE as isize,
X = nk_symbol_type_NK_SYMBOL_X as isize,
Underscore = nk_symbol_type_NK_SYMBOL_UNDERSCORE as isize,
CircleSolid = nk_symbol_type_NK_SYMBOL_CIRCLE_SOLID as isize,
CircleOutline = nk_symbol_type_NK_SYMBOL_CIRCLE_OUTLINE as isize,
RectSolid = nk_symbol_type_NK_SYMBOL_RECT_SOLID as isize,
RectOutline = nk_symbol_type_NK_SYMBOL_RECT_OUTLINE as isize,
TriangleUp = nk_symbol_type_NK_SYMBOL_TRIANGLE_UP as isize,
TriangleDown = nk_symbol_type_NK_SYMBOL_TRIANGLE_DOWN as isize,
TriangleLeft = nk_symbol_type_NK_SYMBOL_TRIANGLE_LEFT as isize,
TriangleRight = nk_symbol_type_NK_SYMBOL_TRIANGLE_RIGHT as isize,
Plus = nk_symbol_type_NK_SYMBOL_PLUS as isize,
Minus = nk_symbol_type_NK_SYMBOL_MINUS as isize,
Max = nk_symbol_type_NK_SYMBOL_MAX as isize,
}
from_into_enum!(SymbolType, nk_symbol_type);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum EditFlag {
Default = nk_edit_flags_NK_EDIT_DEFAULT as isize,
ReadOnly = nk_edit_flags_NK_EDIT_READ_ONLY as isize,
AutoSelect = nk_edit_flags_NK_EDIT_AUTO_SELECT as isize,
SigEnter = nk_edit_flags_NK_EDIT_SIG_ENTER as isize,
AllowTab = nk_edit_flags_NK_EDIT_ALLOW_TAB as isize,
NoCursor = nk_edit_flags_NK_EDIT_NO_CURSOR as isize,
Selectable = nk_edit_flags_NK_EDIT_SELECTABLE as isize,
Clipboard = nk_edit_flags_NK_EDIT_CLIPBOARD as isize,
CtrlEnterNewline = nk_edit_flags_NK_EDIT_CTRL_ENTER_NEWLINE as isize,
NoHorizontalScroll = nk_edit_flags_NK_EDIT_NO_HORIZONTAL_SCROLL as isize,
AlwaysInsertMode = nk_edit_flags_NK_EDIT_ALWAYS_INSERT_MODE as isize,
Multiline = nk_edit_flags_NK_EDIT_MULTILINE as isize,
GoToEndOnActivate = nk_edit_flags_NK_EDIT_GOTO_END_ON_ACTIVATE as isize,
}
from_into_enum!(EditFlag, nk_edit_flags);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum EditType {
Simple = nk_edit_types_NK_EDIT_SIMPLE as isize,
Field = nk_edit_types_NK_EDIT_FIELD as isize,
Box = nk_edit_types_NK_EDIT_BOX as isize,
Editor = nk_edit_types_NK_EDIT_EDITOR as isize,
}
from_into_enum!(EditType, nk_edit_types);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum EditEvent {
Active = nk_edit_events_NK_EDIT_ACTIVE as isize,
Inactive = nk_edit_events_NK_EDIT_INACTIVE as isize,
Activated = nk_edit_events_NK_EDIT_ACTIVATED as isize,
Deactivated = nk_edit_events_NK_EDIT_DEACTIVATED as isize,
Commited = nk_edit_events_NK_EDIT_COMMITED as isize,
}
from_into_enum!(EditEvent, nk_edit_events);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum PanelFlags {
Border = nk_panel_flags_NK_WINDOW_BORDER as isize,
Movable = nk_panel_flags_NK_WINDOW_MOVABLE as isize,
Scalable = nk_panel_flags_NK_WINDOW_SCALABLE as isize,
Closable = nk_panel_flags_NK_WINDOW_CLOSABLE as isize,
Minimizable = nk_panel_flags_NK_WINDOW_MINIMIZABLE as isize,
NoScrollbar = nk_panel_flags_NK_WINDOW_NO_SCROLLBAR as isize,
Title = nk_panel_flags_NK_WINDOW_TITLE as isize,
ScrollAutoHide = nk_panel_flags_NK_WINDOW_SCROLL_AUTO_HIDE as isize,
Background = nk_panel_flags_NK_WINDOW_BACKGROUND as isize,
ScaleLeft = nk_panel_flags_NK_WINDOW_SCALE_LEFT as isize,
NoInput = nk_panel_flags_NK_WINDOW_NO_INPUT as isize,
}
from_into_enum!(PanelFlags, nk_panel_flags);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum Heading {
Up = nk_heading_NK_UP as isize,
Right = nk_heading_NK_RIGHT as isize,
Down = nk_heading_NK_DOWN as isize,
Left = nk_heading_NK_LEFT as isize,
}
from_into_enum!(Heading, nk_heading);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum ButtonBehavior {
Default = nk_button_behavior_NK_BUTTON_DEFAULT as isize,
Repeater = nk_button_behavior_NK_BUTTON_REPEATER as isize,
}
from_into_enum!(ButtonBehavior, nk_button_behavior);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum Modify {
Fixed = nk_modify_NK_FIXED as isize,
Modifiable = nk_modify_NK_MODIFIABLE as isize,
}
from_into_enum!(Modify, nk_modify);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum Orientation {
Vertical = nk_orientation_NK_VERTICAL as isize,
Horizontal = nk_orientation_NK_HORIZONTAL as isize,
}
from_into_enum!(Orientation, nk_orientation);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum CollapseState {
Minimized = nk_collapse_states_NK_MINIMIZED as isize,
Maximized = nk_collapse_states_NK_MAXIMIZED as isize,
}
from_into_enum!(CollapseState, nk_collapse_states);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum ShowState {
Hidden = nk_show_states_NK_HIDDEN as isize,
Shown = nk_show_states_NK_SHOWN as isize,
}
from_into_enum!(ShowState, nk_show_states);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum ChartType {
Lines = nk_chart_type_NK_CHART_LINES as isize,
Column = nk_chart_type_NK_CHART_COLUMN as isize,
Max = nk_chart_type_NK_CHART_MAX as isize,
}
from_into_enum!(ChartType, nk_chart_type);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum ChartEvent {
Hovering = nk_chart_event_NK_CHART_HOVERING as isize,
Clicked = nk_chart_event_NK_CHART_CLICKED as isize,
}
from_into_enum!(ChartEvent, nk_chart_event);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum ColorFormat {
Rgb = nk_color_format_NK_RGB as isize,
Rgba = nk_color_format_NK_RGBA as isize,
}
from_into_enum!(ColorFormat, nk_color_format);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum PopupType {
Static = nk_popup_type_NK_POPUP_STATIC as isize,
Dynamic = nk_popup_type_NK_POPUP_DYNAMIC as isize,
}
from_into_enum!(PopupType, nk_popup_type);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum LayoutFormat {
Dynamic = nk_layout_format_NK_DYNAMIC as isize,
Static = nk_layout_format_NK_STATIC as isize,
}
from_into_enum!(LayoutFormat, nk_layout_format);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum TreeType {
Node = nk_tree_type_NK_TREE_NODE as isize,
Tab = nk_tree_type_NK_TREE_TAB as isize,
}
from_into_enum!(TreeType, nk_tree_type);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum TextAlign {
Left = nk_text_align_NK_TEXT_ALIGN_LEFT as isize,
Centered = nk_text_align_NK_TEXT_ALIGN_CENTERED as isize,
Right = nk_text_align_NK_TEXT_ALIGN_RIGHT as isize,
Top = nk_text_align_NK_TEXT_ALIGN_TOP as isize,
Middle = nk_text_align_NK_TEXT_ALIGN_MIDDLE as isize,
Bottom = nk_text_align_NK_TEXT_ALIGN_BOTTOM as isize,
}
from_into_enum!(TextAlign, nk_text_align);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum TextAlignment {
Left = nk_text_alignment_NK_TEXT_LEFT as isize,
Centered = nk_text_alignment_NK_TEXT_CENTERED as isize,
Right = nk_text_alignment_NK_TEXT_RIGHT as isize,
}
from_into_enum!(TextAlignment, nk_text_alignment);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum Key {
None = nk_keys_NK_KEY_NONE as isize,
Shift = nk_keys_NK_KEY_SHIFT as isize,
Ctrl = nk_keys_NK_KEY_CTRL as isize,
Del = nk_keys_NK_KEY_DEL as isize,
Enter = nk_keys_NK_KEY_ENTER as isize,
Tab = nk_keys_NK_KEY_TAB as isize,
Backspace = nk_keys_NK_KEY_BACKSPACE as isize,
Copy = nk_keys_NK_KEY_COPY as isize,
Cut = nk_keys_NK_KEY_CUT as isize,
Paste = nk_keys_NK_KEY_PASTE as isize,
Up = nk_keys_NK_KEY_UP as isize,
Down = nk_keys_NK_KEY_DOWN as isize,
Left = nk_keys_NK_KEY_LEFT as isize,
Right = nk_keys_NK_KEY_RIGHT as isize,
InsertMode = nk_keys_NK_KEY_TEXT_INSERT_MODE as isize,
ReplaceMode = nk_keys_NK_KEY_TEXT_REPLACE_MODE as isize,
ResetMode = nk_keys_NK_KEY_TEXT_RESET_MODE as isize,
LineStart = nk_keys_NK_KEY_TEXT_LINE_START as isize,
LineEnd = nk_keys_NK_KEY_TEXT_LINE_END as isize,
TextStart = nk_keys_NK_KEY_TEXT_START as isize,
TextEnd = nk_keys_NK_KEY_TEXT_END as isize,
TextUndo = nk_keys_NK_KEY_TEXT_UNDO as isize,
TextRedo = nk_keys_NK_KEY_TEXT_REDO as isize,
TextSelectAll = nk_keys_NK_KEY_TEXT_SELECT_ALL as isize,
TextWordLeft = nk_keys_NK_KEY_TEXT_WORD_LEFT as isize,
TextWordRight = nk_keys_NK_KEY_TEXT_WORD_RIGHT as isize,
ScrollStart = nk_keys_NK_KEY_SCROLL_START as isize,
ScrollEnd = nk_keys_NK_KEY_SCROLL_END as isize,
ScrollDown = nk_keys_NK_KEY_SCROLL_DOWN as isize,
ScrollUp = nk_keys_NK_KEY_SCROLL_UP as isize,
}
from_into_enum!(Key, nk_keys);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum Button {
Left = nk_buttons_NK_BUTTON_LEFT as isize,
Middle = nk_buttons_NK_BUTTON_MIDDLE as isize,
Right = nk_buttons_NK_BUTTON_RIGHT as isize,
Double = nk_buttons_NK_BUTTON_DOUBLE as isize,
Max = nk_buttons_NK_BUTTON_MAX as isize,
}
from_into_enum!(Button, nk_buttons);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum AntiAliasing {
Off = nk_anti_aliasing_NK_ANTI_ALIASING_OFF as isize,
On = nk_anti_aliasing_NK_ANTI_ALIASING_ON as isize,
}
from_into_enum!(AntiAliasing, nk_anti_aliasing);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum DrawVertexLayoutFormat {
Char = nk_draw_vertex_layout_format_NK_FORMAT_SCHAR as isize,
Short = nk_draw_vertex_layout_format_NK_FORMAT_SSHORT as isize,
Int = nk_draw_vertex_layout_format_NK_FORMAT_SINT as isize,
Uchar = nk_draw_vertex_layout_format_NK_FORMAT_UCHAR as isize,
Ushort = nk_draw_vertex_layout_format_NK_FORMAT_USHORT as isize,
Uint = nk_draw_vertex_layout_format_NK_FORMAT_UINT as isize,
Float = nk_draw_vertex_layout_format_NK_FORMAT_FLOAT as isize,
Double = nk_draw_vertex_layout_format_NK_FORMAT_DOUBLE as isize,
R8G8B8 = nk_draw_vertex_layout_format_NK_FORMAT_R8G8B8 as isize,
R16G16B16 = nk_draw_vertex_layout_format_NK_FORMAT_R16G15B16 as isize,
R32G32B32 = nk_draw_vertex_layout_format_NK_FORMAT_R32G32B32 as isize,
R8G8B8A8 = nk_draw_vertex_layout_format_NK_FORMAT_R8G8B8A8 as isize,
B8G8R8A8 = nk_draw_vertex_layout_format_NK_FORMAT_B8G8R8A8 as isize,
R16G15B16A16 = nk_draw_vertex_layout_format_NK_FORMAT_R16G15B16A16 as isize,
R32G32B32A32 = nk_draw_vertex_layout_format_NK_FORMAT_R32G32B32A32 as isize,
R32G32B32A32Float = nk_draw_vertex_layout_format_NK_FORMAT_R32G32B32A32_FLOAT as isize,
R32G32B32A32Double = nk_draw_vertex_layout_format_NK_FORMAT_R32G32B32A32_DOUBLE as isize,
Rgb32 = nk_draw_vertex_layout_format_NK_FORMAT_RGB32 as isize,
Rgba32 = nk_draw_vertex_layout_format_NK_FORMAT_RGBA32 as isize,
Count = nk_draw_vertex_layout_format_NK_FORMAT_COUNT as isize,
}
from_into_enum!(DrawVertexLayoutFormat, nk_draw_vertex_layout_format);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum DrawVertexLayoutAttribute {
Position = nk_draw_vertex_layout_attribute_NK_VERTEX_POSITION as isize,
Color = nk_draw_vertex_layout_attribute_NK_VERTEX_COLOR as isize,
TexCoord = nk_draw_vertex_layout_attribute_NK_VERTEX_TEXCOORD as isize,
AttributeCount = nk_draw_vertex_layout_attribute_NK_VERTEX_ATTRIBUTE_COUNT as isize,
}
from_into_enum!(DrawVertexLayoutAttribute, nk_draw_vertex_layout_attribute);
// ==========================================================================================================
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum FontAtlasFormat {
Alpha8 = nk_font_atlas_format_NK_FONT_ATLAS_ALPHA8 as isize,
Rgba32 = nk_font_atlas_format_NK_FONT_ATLAS_RGBA32 as isize,
}
from_into_enum!(FontAtlasFormat, nk_font_atlas_format);
// ==========================================================================================================
unsafe extern "C" fn nk_filter_custom(arg1: *const nk_text_edit, unicode: nk_rune) -> ::std::os::raw::c_int {
if let Some(f) = CUSTOM_EDIT_FILTER {
if f(&*(arg1 as *const TextEdit), ::std::char::from_u32_unchecked(unicode)) {
1
} else {
0
}
} else {
1
}
}
static mut CUSTOM_EDIT_FILTER: Option<fn(&TextEdit, char) -> bool> = None;
// ===========================================================================================================
// unsafe extern "C" fn nk_plot_value_getter_custom(user: *mut ::std::os::raw::c_void, index: ::std::os::raw::c_int) -> f32 {
// let f = user as *const _ as &[f32];
// f[index as usize]
// }
// ===========================================================================================================
#[derive(Clone)]
pub struct String<'a> {
bytes: Cow<'a, [u8]>,
}
impl<'a> String<'a> {
pub unsafe fn from_bytes_unchecked(bytes: &'a [u8]) -> String<'a> {
String { bytes: Cow::Borrowed(bytes) }
}
pub fn as_ptr(&self) -> *const c_char {
self.bytes.as_ptr() as *const c_char
}
// pub fn nk_str_init(arg1: *mut nk_str, arg2: *const nk_allocator,
// size: nk_size);
// pub fn nk_str_init_fixed(arg1: *mut nk_str,
// memory: *mut ::std::os::raw::c_void,
// size: nk_size);
// pub fn nk_str_clear(arg1: *mut nk_str);
// pub fn nk_str_free(arg1: *mut nk_str);
// pub fn nk_str_append_text_char(arg1: *mut nk_str,
// arg2: *const ::std::os::raw::c_char,
// arg3: ::std::os::raw::c_int)
// -> ::std::os::raw::c_int;
// pub fn nk_str_append_str_char(arg1: *mut nk_str,
// arg2: *const ::std::os::raw::c_char)
// -> ::std::os::raw::c_int;
// pub fn nk_str_append_text_utf8(arg1: *mut nk_str,
// arg2: *const ::std::os::raw::c_char,
// arg3: ::std::os::raw::c_int)
// -> ::std::os::raw::c_int;
// pub fn nk_str_append_str_utf8(arg1: *mut nk_str,
// arg2: *const ::std::os::raw::c_char)
// -> ::std::os::raw::c_int;
// pub fn nk_str_append_text_runes(arg1: *mut nk_str, arg2: *const nk_rune,
// arg3: ::std::os::raw::c_int)
// -> ::std::os::raw::c_int;
// pub fn nk_str_append_str_runes(arg1: *mut nk_str, arg2: *const nk_rune)
// -> ::std::os::raw::c_int;
// pub fn nk_str_insert_at_char(arg1: *mut nk_str,
// pos: ::std::os::raw::c_int,
// arg2: *const ::std::os::raw::c_char,
// arg3: ::std::os::raw::c_int)
// -> ::std::os::raw::c_int;
// pub fn nk_str_insert_at_rune(arg1: *mut nk_str,
// pos: ::std::os::raw::c_int,
// arg2: *const ::std::os::raw::c_char,
// arg3: ::std::os::raw::c_int)
// -> ::std::os::raw::c_int;
// pub fn nk_str_insert_text_char(arg1: *mut nk_str,
// pos: ::std::os::raw::c_int,
// arg2: *const ::std::os::raw::c_char,
// arg3: ::std::os::raw::c_int)
// -> ::std::os::raw::c_int;
// pub fn nk_str_insert_str_char(arg1: *mut nk_str,
// pos: ::std::os::raw::c_int,
// arg2: *const ::std::os::raw::c_char)
// -> ::std::os::raw::c_int;
// pub fn nk_str_insert_text_utf8(arg1: *mut nk_str,
// pos: ::std::os::raw::c_int,
// arg2: *const ::std::os::raw::c_char,
// arg3: ::std::os::raw::c_int)
// -> ::std::os::raw::c_int;
// pub fn nk_str_insert_str_utf8(arg1: *mut nk_str,
// pos: ::std::os::raw::c_int,
// arg2: *const ::std::os::raw::c_char)
// -> ::std::os::raw::c_int;
// pub fn nk_str_insert_text_runes(arg1: *mut nk_str,
// pos: ::std::os::raw::c_int,
// arg2: *const nk_rune,
// arg3: ::std::os::raw::c_int)
// -> ::std::os::raw::c_int;
// pub fn nk_str_insert_str_runes(arg1: *mut nk_str,
// pos: ::std::os::raw::c_int,
// arg2: *const nk_rune)
// -> ::std::os::raw::c_int;
// pub fn nk_str_remove_chars(arg1: *mut nk_str, len: ::std::os::raw::c_int);
// pub fn nk_str_remove_runes(str: *mut nk_str, len: ::std::os::raw::c_int);
// pub fn nk_str_delete_chars(arg1: *mut nk_str, pos: ::std::os::raw::c_int,
// len: ::std::os::raw::c_int);
// pub fn nk_str_delete_runes(arg1: *mut nk_str, pos: ::std::os::raw::c_int,
// len: ::std::os::raw::c_int);
// pub fn nk_str_at_char(arg1: *mut nk_str, pos: ::std::os::raw::c_int)
// -> *mut ::std::os::raw::c_char;
// pub fn nk_str_at_rune(arg1: *mut nk_str, pos: ::std::os::raw::c_int,
// unicode: *mut nk_rune,
// len: *mut ::std::os::raw::c_int)
// -> *mut ::std::os::raw::c_char;
// pub fn nk_str_rune_at(arg1: *const nk_str, pos: ::std::os::raw::c_int)
// -> nk_rune;
// pub fn nk_str_at_char_const(arg1: *const nk_str,
// pos: ::std::os::raw::c_int)
// -> *const ::std::os::raw::c_char;
// pub fn nk_str_at_const(arg1: *const nk_str, pos: ::std::os::raw::c_int,
// unicode: *mut nk_rune,
// len: *mut ::std::os::raw::c_int)
// -> *const ::std::os::raw::c_char;
// pub fn nk_str_get(arg1: *mut nk_str) -> *mut ::std::os::raw::c_char;
// pub fn nk_str_get_const(arg1: *const nk_str)
// -> *const ::std::os::raw::c_char;
// pub fn nk_str_len(arg1: *mut nk_str) -> ::std::os::raw::c_int;
// pub fn nk_str_len_char(arg1: *mut nk_str) -> ::std::os::raw::c_int;
//
}
impl<'a> From<&'a str> for String<'a> {
fn from(value: &'a str) -> String<'a> {
let mut bytes: Vec<u8> = value.bytes().collect();
bytes.push(0);
String { bytes: Cow::Owned(bytes) }
}
}
impl<'a> From<::std::string::String> for String<'a> {
fn from(mut value: ::std::string::String) -> String<'a> {
value.push('\0');
String { bytes: Cow::Owned(value.into_bytes()) }
}
}
#[macro_export]
macro_rules! nk_string {
($e:tt) => ({
let value = concat!($e, "\0");
unsafe { $crate::String::from_bytes_unchecked(value.as_bytes()) }
});
($e:tt, $($arg:tt)*) => ({
$crate::String::from(format!($e, $($arg)*))
})
}
// ======================================================================================
#[derive(Clone)]
pub struct StringArray<'a> {
arr: Vec<String<'a>>,
ptrs: Vec<*const c_char>,
}
impl<'a> StringArray<'a> {
pub fn as_ptr(&self) -> *const *const c_char {
self.ptrs.as_slice() as *const _ as *const *const c_char
}
pub fn as_mut(&mut self) -> *mut *const c_char {
self.ptrs.as_mut_slice() as *mut _ as *mut *const c_char
}
pub fn len(&self) -> usize {
self.ptrs.len()
}
pub fn is_empty(&self) -> bool {
self.len() < 1
}
}
impl<'a> From<&'a [&'a str]> for StringArray<'a> {
fn from(value: &[&'a str]) -> StringArray<'a> {
let mut r = StringArray {
arr: Vec::with_capacity(value.len()),
ptrs: Vec::with_capacity(value.len()),
};
for s in value {
r.arr.push(String::from(*s));
r.ptrs.push(r.arr[r.arr.len() - 1].as_ptr());
}
r
}
}
// ======================================================================================
#[derive(Debug, Clone, PartialEq, Copy)]
enum HandleKind {
Empty,
Ptr,
Id,
Unknown,
}
#[derive(Clone, Copy)]
#[repr(C)]
pub struct Handle {
internal: nk_handle,
kind: HandleKind,
}
impl Default for Handle {
fn default() -> Self {
Handle {
kind: HandleKind::Empty,
internal: nk_handle::default(),
}
}
}
impl Handle {
pub fn id(&mut self) -> Option<i32> {
match self.kind {
HandleKind::Id | HandleKind::Unknown => Some(unsafe { self.internal.id }),
_ => None,
}
}
pub fn ptr(&mut self) -> Option<*mut c_void> {
match self.kind {
HandleKind::Ptr | HandleKind::Unknown => Some(unsafe { self.internal.ptr }),
_ => None,
}
}
pub fn from_id(value: i32) -> Handle {
Handle {
kind: HandleKind::Id,
internal: unsafe { nk_handle_id(value) },
}
}
pub unsafe fn from_ptr(value: *mut c_void) -> Handle {
Handle { kind: HandleKind::Ptr, internal: nk_handle_ptr(value) }
}
}
// ==================================================================================
/*
wrapper_type!(ConfigurationStacks, nk_configuration_stacks);
impl ConfigurationStacks {
pub style_items: nk_config_stack_style_item,
pub floats: nk_config_stack_float,
pub vectors: nk_config_stack_vec2,
pub flags: nk_config_stack_flags,
pub colors: nk_config_stack_color,
pub fonts: nk_config_stack_user_font,
pub button_behaviors: nk_config_stack_button_behavior,
}
*/
// ==================================================================================
wrapper_type!(Clipboard, nk_clipboard);
impl Clipboard {
pub unsafe fn userdata_ptr(&self) -> Handle {
Handle::from_ptr(self.internal.userdata.ptr)
}
pub unsafe fn userdata_id(&self) -> Handle {
Handle::from_id(self.internal.userdata.id)
}
pub fn paste(&self) -> PluginPaste {
self.internal.paste
}
pub fn set_paste(&mut self, plug: PluginPaste) {
self.internal.paste = plug;
}
pub fn copy(&self) -> PluginCopy {
self.internal.copy
}
pub fn set_copy(&mut self, plug: PluginCopy) {
self.internal.copy = plug;
}
}
// ==================================================================================
wrapper_type!(Input, nk_input);
impl Input {
pub fn mouse(&self) -> Mouse {
Mouse { internal: self.internal.mouse }
}
pub fn has_mouse_click(&self, b: Button) -> bool {
unsafe { nk_input_has_mouse_click(&self.internal, b.into()) != 0 }
}
pub fn has_mouse_click_in_rect(&self, b: Button, rect: Rect) -> bool {
unsafe { nk_input_has_mouse_click_in_rect(&self.internal, b.into(), rect) != 0 }
}
pub fn has_mouse_click_down_in_rect(&self, b: Button, rect: Rect, down: bool) -> bool {
unsafe { nk_input_has_mouse_click_down_in_rect(&self.internal, b.into(), rect, if down { 1 } else { 0 }) != 0 }
}
pub fn is_mouse_click_in_rect(&self, b: Button, rect: Rect) -> bool {
unsafe { nk_input_is_mouse_click_in_rect(&self.internal, b.into(), rect) != 0 }
}
pub fn is_mouse_click_down_in_rect(&self, b: Button, rect: Rect, down: bool) -> bool {
unsafe { nk_input_is_mouse_click_down_in_rect(&self.internal, b.into(), rect, down as ::std::os::raw::c_int) != 0 }
}
pub fn any_mouse_click_in_rect(&self, rect: Rect) -> bool {
unsafe { nk_input_any_mouse_click_in_rect(&self.internal, rect) != 0 }
}
pub fn is_mouse_prev_hovering_rect(&self, rect: Rect) -> bool {
unsafe { nk_input_is_mouse_prev_hovering_rect(&self.internal, rect) != 0 }
}
pub fn is_mouse_hovering_rect(&self, rect: Rect) -> bool {
unsafe { nk_input_is_mouse_hovering_rect(&self.internal, rect) != 0 }
}
pub fn is_mouse_clicked(&self, b: Button, rect: Rect) -> bool {
unsafe { nk_input_mouse_clicked(&self.internal, b.into(), rect) != 0 }
}
pub fn is_mouse_down(&self, b: Button) -> bool {
unsafe { nk_input_is_mouse_down(&self.internal, b.into()) != 0 }
}
pub fn is_mouse_pressed(&self, b: Button) -> bool {
unsafe { nk_input_is_mouse_pressed(&self.internal, b.into()) != 0 }
}
pub fn is_mouse_released(&self, b: Button) -> bool {
unsafe { nk_input_is_mouse_released(&self.internal, b.into()) != 0 }
}
pub fn is_key_pressed(&self, k: Key) -> bool {
unsafe { nk_input_is_key_pressed(&self.internal, k.into()) != 0 }
}
pub fn is_key_released(&self, k: Key) -> bool {
unsafe { nk_input_is_key_released(&self.internal, k.into()) != 0 }
}
pub fn is_key_down(&self, k: Key) -> bool {
unsafe { nk_input_is_key_down(&self.internal, k.into()) != 0 }
}
}
// =====================================================================
wrapper_type!(DrawCommand, nk_draw_command);
impl DrawCommand {
pub fn clip_rect(&self) -> &Rect {
&self.internal.clip_rect
}
pub fn elem_count(&self) -> u32 {
self.internal.elem_count
}
pub fn texture(&self) -> Handle {
Handle {
kind: HandleKind::Unknown,
internal: self.internal.texture,
}
}
}
// =====================================================================
#[derive(Copy, Clone, Debug)]
pub struct MouseButton {
pub down: bool,
pub clicked: bool,
pub clicked_pos: Vec2,
}
impl MouseButton {
fn from_native(n: nk_mouse_button) -> MouseButton {
MouseButton {
down: n.down > 0,
clicked: n.clicked > 0,
clicked_pos: n.clicked_pos,
}
}
}
wrapper_type!(Mouse, nk_mouse);
impl Mouse {
pub fn pos(&self) -> &Vec2 {
&self.internal.pos
}
pub fn prev(&self) -> &Vec2 {
&self.internal.prev
}
pub fn delta(&self) -> &Vec2 {
&self.internal.delta
}
pub fn scroll_delta(&self) -> &Vec2 {
&self.internal.scroll_delta
}
pub fn buttons(&self) -> [MouseButton; 3] {
[MouseButton::from_native(self.internal.buttons[0]), MouseButton::from_native(self.internal.buttons[1]), MouseButton::from_native(self.internal.buttons[2])]
}
pub fn grabbed(&self) -> bool {
self.internal.grabbed > 0
}
// pub fn grab(&mut self) {
// self.internal.grab = 1;
// self.internal.ungrab = 0;
// }
//
// pub fn ungrab(&mut self) {
// self.internal.grab = 0;
// self.internal.ungrab = 1;
// }
}
// =====================================================================
// =====================================================================
wrapper_type!(Style, nk_style);
impl Style {
// ===== mut getters =====
pub fn window_mut(&mut self) -> &mut StyleWindow {
unsafe { ::std::mem::transmute(&mut self.internal.window) }
}
pub fn font_mut(&mut self) -> &mut UserFont {
unsafe { ::std::mem::transmute(self.internal.font) }
}
pub fn cursors_mut(&mut self) -> &mut CursorMap {
unsafe { ::std::mem::transmute(&mut self.internal.cursors) }
}
pub fn cursor_active_mut(&mut self) -> &mut Cursor {
unsafe { ::std::mem::transmute(&mut self.internal.cursor_active) }
}
pub fn set_cursor_visible(&mut self, value: bool) {
self.internal.cursor_visible = if value { 1 } else { 0 }
}
pub fn text_mut(&mut self) -> &mut StyleText {
&mut self.internal.text
}
pub fn button_mut(&mut self) -> &mut StyleButton {
unsafe { ::std::mem::transmute(&mut self.internal.button) }
}
pub fn contextual_button_mut(&mut self) -> &mut StyleButton {
unsafe { ::std::mem::transmute(&mut self.internal.contextual_button) }
}
pub fn menu_button_mut(&mut self) -> &mut StyleButton {
unsafe { ::std::mem::transmute(&mut self.internal.menu_button) }
}
pub fn option_mut(&mut self) -> &mut StyleToggle {
unsafe { ::std::mem::transmute(&mut self.internal.option) }
}
pub fn checkbox_mut(&mut self) -> &mut StyleToggle {