This repository has been archived by the owner on Mar 19, 2021. It is now read-only.
/
nuklear.nim
3632 lines (2925 loc) · 153 KB
/
nuklear.nim
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
#[
Nuklear - 1.33.0 - public domain
no warrenty implied; use at your own risk.
authored from 2015-2016 by Micha Mettke
ABOUT:
This is a minimal state graphical user interface single header toolkit
written in ANSI C and licensed under public domain.
It was designed as a simple embeddable user interface for application and does
not have any dependencies, a default renderbackend or OS window and input handling
but instead provides a very modular library approach by using simple input state
for input and draw commands describing primitive shapes as output.
So instead of providing a layered library that tries to abstract over a number
of platform and render backends it only focuses on the actual UI.
VALUES:
- Graphical user interface toolkit
- Single header library
- Written in C89 (a.k.a. ANSI C or ISO C90)
- Small codebase (~17kLOC)
- Focus on portability, efficiency and simplicity
- No dependencies (not even the standard library if not wanted)
- Fully skinnable and customizable
- Low memory footprint with total memory control if needed or wanted
- UTF-8 support
- No global or hidden state
- Customizable library modules (you can compile and use only what you need)
- Optional font baker and vertex buffer output
USAGE:
This library is self contained in one single header file and can be used either
in header only mode or in implementation mode. The header only mode is used
by default when included and allows including this header in other headers
and does not contain the actual implementation.
The implementation mode requires to define the preprocessor macro
NK_IMPLEMENTATION in *one* .c/.cpp file before #includeing this file, e.g.:
#define NK_IMPLEMENTATION
#include "nuklear.h"
Also optionally define the symbols listed in the section "OPTIONAL DEFINES"
below in header and implementation mode if you want to use additional functionality
or need more control over the library.
IMPORTANT: Every time you include "nuklear.h" you have to define the same flags.
This is very important not doing it either leads to compiler errors
or even worse stack corruptions.
FEATURES:
- Absolutely no platform dependend code
- Memory management control ranging from/to
- Ease of use by allocating everything from standard library
- Control every byte of memory inside the library
- Font handling control ranging from/to
- Use your own font implementation for everything
- Use this libraries internal font baking and handling API
- Drawing output control ranging from/to
- Simple shapes for more high level APIs which already have drawing capabilities
- Hardware accessible anti-aliased vertex buffer output
- Customizable colors and properties ranging from/to
- Simple changes to color by filling a simple color table
- Complete control with ability to use skinning to decorate widgets
- Bendable UI library with widget ranging from/to
- Basic widgets like buttons, checkboxes, slider, ...
- Advanced widget like abstract comboboxes, contextual menus,...
- Compile time configuration to only compile what you need
- Subset which can be used if you do not want to link or use the standard library
- Can be easily modified to only update on user input instead of frame updates
OPTIONAL DEFINES:
NK_PRIVATE
If defined declares all functions as static, so they can only be accessed
inside the file that contains the implementation
NK_INCLUDE_FIXED_TYPES
If defined it will include header <stdint.h> for fixed sized types
otherwise nuklear tries to select the correct type. If that fails it will
throw a compiler error and you have to select the correct types yourself.
<!> If used needs to be defined for implementation and header <!>
NK_INCLUDE_DEFAULT_ALLOCATOR
if defined it will include header <stdlib.h> and provide additional functions
to use this library without caring for memory allocation control and therefore
ease memory management.
<!> Adds the standard library with malloc and free so don't define if you
don't want to link to the standard library <!>
<!> If used needs to be defined for implementation and header <!>
NK_INCLUDE_STANDARD_IO
if defined it will include header <stdio.h> and provide
additional functions depending on file loading.
<!> Adds the standard library with fopen, fclose,... so don't define this
if you don't want to link to the standard library <!>
<!> If used needs to be defined for implementation and header <!>
NK_INCLUDE_STANDARD_VARARGS
if defined it will include header <stdarg.h> and provide
additional functions depending on variable arguments
<!> Adds the standard library with va_list and so don't define this if
you don't want to link to the standard library<!>
<!> If used needs to be defined for implementation and header <!>
NK_INCLUDE_VERTEX_BUFFER_OUTPUT
Defining this adds a vertex draw command list backend to this
library, which allows you to convert queue commands into vertex draw commands.
This is mainly if you need a hardware accessible format for OpenGL, DirectX,
Vulkan, Metal,...
<!> If used needs to be defined for implementation and header <!>
NK_INCLUDE_FONT_BAKING
Defining this adds the `stb_truetype` and `stb_rect_pack` implementation
to this library and provides font baking and rendering.
If you already have font handling or do not want to use this font handler
you don't have to define it.
<!> If used needs to be defined for implementation and header <!>
NK_INCLUDE_DEFAULT_FONT
Defining this adds the default font: ProggyClean.ttf into this library
which can be loaded into a font atlas and allows using this library without
having a truetype font
<!> Enabling this adds ~12kb to global stack memory <!>
<!> If used needs to be defined for implementation and header <!>
NK_INCLUDE_COMMAND_USERDATA
Defining this adds a userdata pointer into each command. Can be useful for
example if you want to provide custom shaders depending on the used widget.
Can be combined with the style structures.
<!> If used needs to be defined for implementation and header <!>
NK_BUTTON_TRIGGER_ON_RELEASE
Different platforms require button clicks occuring either on buttons being
pressed (up to down) or released (down to up).
By default this library will react on buttons being pressed, but if you
define this it will only trigger if a button is released.
<!> If used it is only required to be defined for the implementation part <!>
NK_ZERO_COMMAND_MEMORY
Defining this will zero out memory for each drawing command added to a
drawing queue (inside nk_command_buffer_push). Zeroing command memory
is very useful for fast checking (using memcmp) if command buffers are
equal and avoid drawing frames when nothing on screen has changed since
previous frame.
NK_ASSERT
If you don't define this, nuklear will use <assert.h> with assert().
<!> Adds the standard library so define to nothing of not wanted <!>
<!> If used needs to be defined for implementation and header <!>
NK_BUFFER_DEFAULT_INITIAL_SIZE
Initial buffer size allocated by all buffers while using the default allocator
functions included by defining NK_INCLUDE_DEFAULT_ALLOCATOR. If you don't
want to allocate the default 4k memory then redefine it.
<!> If used needs to be defined for implementation and header <!>
NK_MAX_NUMBER_BUFFER
Maximum buffer size for the conversion buffer between float and string
Under normal circumstances this should be more than sufficient.
<!> If used needs to be defined for implementation and header <!>
NK_INPUT_MAX
Defines the max number of bytes which can be added as text input in one frame.
Under normal circumstances this should be more than sufficient.
<!> If used it is only required to be defined for the implementation part <!>
NK_MEMSET
You can define this to 'memset' or your own memset implementation
replacement. If not nuklear will use its own version.
<!> If used it is only required to be defined for the implementation part <!>
NK_MEMCPY
You can define this to 'memcpy' or your own memcpy implementation
replacement. If not nuklear will use its own version.
<!> If used it is only required to be defined for the implementation part <!>
NK_SQRT
You can define this to 'sqrt' or your own sqrt implementation
replacement. If not nuklear will use its own slow and not highly
accurate version.
<!> If used it is only required to be defined for the implementation part <!>
NK_SIN
You can define this to 'sinf' or your own sine implementation
replacement. If not nuklear will use its own approximation implementation.
<!> If used it is only required to be defined for the implementation part <!>
NK_COS
You can define this to 'cosf' or your own cosine implementation
replacement. If not nuklear will use its own approximation implementation.
<!> If used it is only required to be defined for the implementation part <!>
NK_STRTOD
You can define this to `strtod` or your own string to double conversion
implementation replacement. If not defined nuklear will use its own
imprecise and possibly unsafe version (does not handle nan or infinity!).
<!> If used it is only required to be defined for the implementation part <!>
NK_DTOA
You can define this to `dtoa` or your own double to string conversion
implementation replacement. If not defined nuklear will use its own
imprecise and possibly unsafe version (does not handle nan or infinity!).
<!> If used it is only required to be defined for the implementation part <!>
NK_VSNPRINTF
If you define `NK_INCLUDE_STANDARD_VARARGS` as well as `NK_INCLUDE_STANDARD_IO`
and want to be safe define this to `vsnprintf` on compilers supporting
later versions of C or C++. By default nuklear will check for your stdlib version
in C as well as compiler version in C++. if `vsnprintf` is available
it will define it to `vsnprintf` directly. If not defined and if you have
older versions of C or C++ it will be defined to `vsprintf` which is unsafe.
<!> If used it is only required to be defined for the implementation part <!>
NK_BYTE
NK_INT16
NK_UINT16
NK_INT32
NK_UINT32
NK_SIZE_TYPE
NK_POINTER_TYPE
If you compile without NK_USE_FIXED_TYPE then a number of standard types
will be selected and compile time validated. If they are incorrect you can
define the correct types by overloading these type defines.
CREDITS:
Developed by Micha Mettke and every direct or indirect contributor.
Embeds stb_texedit, stb_truetype and stb_rectpack by Sean Barret (public domain)
Embeds ProggyClean.ttf font by Tristan Grimmer (MIT license).
Big thank you to Omar Cornut (ocornut@github) for his imgui library and
giving me the inspiration for this library, Casey Muratori for handmade hero
and his original immediate mode graphical user interface idea and Sean
Barret for his amazing single header libraries which restored my faith
in libraries and brought me to create some of my own.
LICENSE:
This software is dual-licensed to the public domain and under the following
license: you are granted a perpetual, irrevocable license to copy, modify,
publish and distribute this file as you see fit.
]#
{.deadCodeElim: on.}
{.compile: "src/bind.c".}
import macros
macro find_size(a,b: untyped): untyped =
if sizeof(a) < sizeof(b):
sizeof(b)
else:
sizeof(a) div sizeof(uint32) div 2
type
style_slide* = object
const
nk_false* = 0
nk_true* = 1
type
handle* = pointer
color* = object
r*: char
g*: char
b*: char
a*: char
colorf* = object
r*: float32
g*: float32
b*: float32
a*: float32
vec2* = object
x*: float32
y*: float32
vec2i* = object
x*: int16
y*: int16
rect* = object
x*: float32
y*: float32
w*: float32
h*: float32
recti* = object
x*: int16
y*: int16
w*: int16
h*: int16
glyph* = array[4, char]
img* = object {.byCopy.}
handle*: handle
w*: uint16
h*: uint16
region*: array[4, uint16]
cursor* = object
img*: img
size*: vec2
offset*: vec2
scroll* = object
x*: uint32
y*: uint32
heading* {.size: sizeof(int32).} = enum
UP, RIGHT, DOWN, LEFT
type
user_font_glyph* = object
uv*: array[2, vec2] ## texture coordinates
offset*: vec2 ## offset between top left and glyph
width*: float32
height*: float32 ## size of the glyph
xadvance*: float32 ## offset to the next glyph
text_width_f* = proc (a2: handle; h: float32; a4: cstring; len: int32): float32 {.cdecl.}
query_font_glyph_f* = proc (handle: handle; font_height: float32;
glyph: ptr user_font_glyph; codepoint: uint32;
next_codepoint: uint32) {.cdecl.}
user_font* = object
userdata*: handle
height*: float32
width*: text_width_f
query* :query_font_glyph_f
texture*: handle
font_coord_type* {.size: sizeof(int32).} = enum
COORD_UV, COORD_PIXEL
memory_status* = object
memory*: pointer
typ*: uint32
size*: uint
allocated*: uint
needed*: uint
calls*: uint
allocation_type* {.size: sizeof(int32).} = enum
BUFFER_FIXED, BUFFER_DYNAMIC
type
buffer_allocation_type* {.size: sizeof(int32).} = enum
BUFFER_FRONT, BUFFER_BACK, BUFFER_MAX
type
anti_aliasing* {.size: sizeof(int32).} = enum
ANTI_ALIASING_OFF, ANTI_ALIASING_ON
##################################################################
#
# MEMORY BUFFER
#
##################################################################
#[ A basic (double)-buffer with linear allocation and resetting as only
freeing policy. The buffer's main purpose is to control all memory management
inside the GUI toolkit and still leave memory control as much as possible in
the hand of the user while also making sure the library is easy to use if
not as much control is needed.
In general all memory inside this library can be provided from the user in
three different ways.
The first way and the one providing most control is by just passing a fixed
size memory block. In this case all control lies in the hand of the user
since he can exactly control where the memory comes from and how much memory
the library should consume. Of course using the fixed size API removes the
ability to automatically resize a buffer if not enough memory is provided so
you have to take over the resizing. While being a fixed sized buffer sounds
quite limiting, it is very effective in this library since the actual memory
consumption is quite stable and has a fixed upper bound for a lot of cases.
If you don't want to think about how much memory the library should allocate
at all time or have a very dynamic UI with unpredictable memory consumption
habits but still want control over memory allocation you can use the dynamic
allocator based API. The allocator consists of two callbacks for allocating
and freeing memory and optional userdata so you can plugin your own allocator.
The final and easiest way can be used by defining
NK_INCLUDE_DEFAULT_ALLOCATOR which uses the standard library memory
allocation functions malloc and free and takes over complete control over
memory in this library.
]#
type
plugin_alloc* = proc (a2: handle; old: pointer; a4: uint): pointer {.cdecl.}
plugin_free* = proc (a2: handle; old: pointer) {.cdecl.}
allocator* = object
userdata*: handle
alloc*: plugin_alloc
free*: plugin_free
buffer_marker* = object
active*: int32
offset*: uint
memory* = object
pointr*: pointer
size*: uint
buffer* = object
marker*: array[BUFFER_MAX, buffer_marker]
pool*: allocator
typ*: allocation_type
memory*: memory
grow_factor*: float32
allocated*: uint
needed*: uint
calls*: uint
size*: uint
proc buffer_init_default(a2: ptr buffer) {.importc: "nk_buffer_init_default".}
proc init*(b: var buffer) =
buffer_init_default(addr b)
proc buffer_init(a2: ptr buffer; a3: ptr allocator; size: uint) {.importc: "nk_buffer_init".}
proc init*(b: var buffer, a: var allocator, size: uint) =
buffer_init(addr b, addr a, size)
proc buffer_init_fixed(a2: ptr buffer; memory: pointer; size: uint) {.importc: "nk_buffer_init_fixed".}
proc init*(b: var buffer, memory: pointer, size:uint) =
buffer_init_fixed(addr b, memory, size)
proc buffer_info(a2: ptr memory_status; a3: ptr buffer) {.importc: "nk_buffer_info".}
proc info*(b: var buffer, ms: var memory_status) =
buffer_info(addr ms, addr b)
proc buffer_push(a2: ptr buffer; typ: buffer_allocation_type;
memory: pointer; size: uint; align: uint) {.importc: "nk_buffer_push".}
proc push*(b: var buffer, `type`: buffer_allocation_type, memory: pointer, size, align: uint) =
buffer_push(addr b, `type`, memory, size, align)
proc buffer_mark*(a2: ptr buffer; typ: buffer_allocation_type) {.importc: "nk_buffer_mark".}
proc mark*(b: var buffer, `type`: buffer_allocation_type) =
buffer_mark(addr b, `type`)
proc buffer_reset(a2: ptr buffer; typ: buffer_allocation_type) {.importc: "nk_buffer_reset".}
proc reset*(b: var buffer, `type`: buffer_allocation_type) =
buffer_reset(addr b, `type`)
proc buffer_clear(a2: ptr buffer) {.importc: "nk_buffer_clear".}
proc clear*(b: var buffer) =
buffer_clear(addr b)
proc buffer_free(a2: ptr buffer) {.importc: "nk_buffer_free".}
proc free*(b: var buffer) =
buffer_free(addr b)
proc buffer_memory(a2: ptr buffer): pointer {.importc: "nk_buffer_memory".}
proc bufferMemory*(b: var buffer): pointer =
buffer_memory(addr b)
proc buffer_memory_const(a2: ptr buffer): pointer {.importc: "nk_buffer_memory_const".}
proc bufferMemoryConst*(b: var buffer): pointer =
buffer_memory_const(addr b)
proc buffer_total*(a2: ptr buffer): uint {.importc: "nk_buffer_total".}
proc total*(b: var buffer): uint =
buffer_total(addr b)
##################################################################
#*
# STRING
#
###################################################################
## Basic string buffer which is only used in context with the text editor
# to manage and manipulate dynamic or fixed size string content. This is _NOT_
# the default string handling method. The only instance you should have any contact
# with this API is if you interact with an `nk_text_edit` object inside one of the
# copy and paste functions and even there only for more advanced cases. */
type
str* = object
buffer*: buffer
len*: int32
proc str_init(a2: ptr str; a3: ptr allocator; size: uint) {.importc: "nk_str_init".}
proc init*(s: var str, a: var allocator, size: uint) =
str_init(addr s, addr a, size)
proc str_init_fixed(a2: ptr str; memory: pointer; size: uint) {.importc: "nk_str_init_fixed".}
proc initFixed*(s: var str, memory: pointer, size: uint) =
str_init_fixed(addr s, memory, size)
proc str_clear(a2: ptr str) {.importc: "nk_str_clear".}
proc clear*(s: var str) =
str_clear(addr s)
proc str_free(a2: ptr str) {.importc: "nk_str_free".}
proc free*(s: var str) =
str_free(addr s)
proc str_append_text_char(a2: ptr str; a3: cstring; a4: int32): int32 {.importc: "nk_str_append_text_char".}
proc appendTextChar*(s: var str, t: string, c: int32): int32 =
str_append_text_char(addr s, t, c)
proc str_append_str_char(a2: ptr str; a3: cstring): int32 {.importc: "nk_str_append_str_char".}
proc appendStrChar*(s: var str, t: string): int32 =
str_append_str_char(addr s, t)
proc str_append_text_utf8(a2: ptr str; a3: cstring; a4: int32): int32 {.importc: "nk_str_append_text_utf8".}
proc appendTextUTF8*(s: var str, t: string, u: int32): int32 =
str_append_text_utf8(addr s, t, u)
proc str_append_str_utf8(a2: ptr str; a3: cstring): int32 {.importc: "nk_str_append_str_utf8".}
proc appendStrUTF8*(s: var str, t: string): int32 =
str_append_str_utf8(addr s, t)
proc str_append_text_runes(a2: ptr str; a3: ptr uint32; a4: int32): int32 {.importc: "nk_str_append_text_runes".}
proc appendTextRunes*(s: var str, u: var uint32, i: int32): int32 =
str_append_text_runes(addr s, addr u, i)
proc str_append_str_runes(a2: ptr str; a3: ptr uint32): int32 {.importc: "nk_str_append_str_runes".}
proc appendStrRunes*(s: var str, u: var uint32): int32 =
str_append_str_runes(addr s, addr u)
proc str_insert_at_char(a2: ptr str; pos: int32; a4: cstring; a5: int32): int32 {. importc: "nk_str_insert_at_char".}
proc insertAtChar*(s: var str, pos: int32, t: string, i: int32): int32 =
str_insert_at_char(addr s, pos, t, i)
proc str_insert_at_rune(a2: ptr str; pos: int32; a4: cstring; a5: int32): int32 {. importc: "nk_str_insert_at_rune".}
proc insertAtRune*(s: var str, pos: int32, t: string, i: int32): int32 =
str_insert_at_rune(addr s, pos, t, i)
proc str_insert_text_char(a2: ptr str; pos: int32; a4: cstring; a5: int32): int32 {. importc: "nk_str_insert_text_char".}
proc insertTextChar*(s: var str, pos: int32, t: string, i: int32): int32 =
str_insert_text_char(addr s, pos, t, i)
proc str_insert_str_char(a2: ptr str; pos: int32; a4: cstring): int32 {.importc: "nk_str_insert_str_char".}
proc insertStrChar*(s: var str, pos: int32, t: string): int32 =
str_insert_str_char(addr s, pos, t)
proc str_insert_text_utf8(a2: ptr str; pos: int32; a4: cstring; a5: int32): int32 {. importc: "nk_str_insert_text_utf8".}
proc insertTextUTF8*(s: var str, pos: int32, t: string, i: int32): int32 =
str_insert_text_utf8(addr s, pos, t, i)
proc str_insert_str_utf8(a2: ptr str; pos: int32; a4: cstring): int32 {.importc: "nk_str_insert_str_utf8".}
proc insertStrUTF8*(s: var str, pos: int32, t: string): int32 =
str_insert_str_utf8(addr s, pos, t)
proc str_insert_text_runes(a2: ptr str; pos: int32; a4: ptr uint32; a5: int32): int32 {. importc: "nk_str_insert_text_runes".}
proc insertTextRunes*(s: var str, pos: int32, u: var uint32, i: int32): int32 =
str_insert_text_runes(addr s, pos, addr u, i)
proc str_insert_str_runes(a2: ptr str; pos: int32; a4: ptr uint32): int32 {.importc: "nk_str_insert_str_runes".}
proc insertStrRunes*(s: var str, pos: int32, u: var uint32): int32 =
str_insert_str_runes(addr s, pos, addr u)
proc str_remove_chars(a2: ptr str; len: int32) {.importc: "nk_str_remove_chars".}
proc removeChars*(s: var str, len: int32) =
str_remove_chars(addr s, len)
proc str_remove_runes(str: ptr str; len: int32) {.importc: "nk_str_remove_runes".}
proc removeRunes*(s: var str, len: int32) =
str_remove_runes(addr s, len)
proc str_delete_chars(a2: ptr str; pos: int32; len: int32) {.importc: "nk_str_delete_chars".}
proc deleteChars*(s: var str, pos: int32, len: int32) =
str_delete_chars(addr s, pos, len)
proc str_delete_runes(a2: ptr str; pos: int32; len: int32) {.importc: "nk_str_delete_runes".}
proc deleteRunes*(s: var str, pos: int32, len: int32) =
str_delete_runes(addr s, pos, len)
proc str_at_char(a2: ptr str; pos: int32): cstring {.importc: "nk_str_at_char".}
proc atChar*(s: var str, pos: int32) : string =
$str_at_char(addr s, pos)
proc str_at_rune(a2: ptr str; pos: int32; unicode: ptr uint32; len: ptr int32): cstring {. importc: "nk_str_at_rune".}
proc atRune*(s: var str, pos: int32, unicode: var uint32, len: var int32) : string =
$str_at_rune(addr s, pos, addr unicode, addr len)
proc str_rune_at(a2: ptr str; pos: int32): uint32 {.importc: "nk_str_rune_at".}
proc runeAt*(s: var str, pos: int32): uint32 =
str_rune_at(addr s, pos)
proc str_at_char_const(a2: ptr str; pos: int32): cstring {.importc: "nk_str_at_char_const".}
proc atCharConst*(s: var str, pos: int32): string =
$str_at_char_const(addr s, pos)
proc str_at_const(a2: ptr str; pos: int32; unicode: ptr uint32; len: ptr int32): cstring {. importc: "nk_str_at_const".}
proc atConst*(s: var str, pos: int32, unicode: var uint32, len: var int32): string =
$str_at_const(addr s, pos, addr unicode, addr len)
proc str_get(a2: ptr str): cstring {.importc: "nk_str_get".}
proc get*(s: var str): string =
$str_get(addr s)
proc str_get_const(a2: ptr str): cstring {.importc: "nk_str_get_const".}
proc getConst*(s: var str): string =
$str_get_const(addr s)
proc str_len(a2: ptr str): int32 {.importc: "nk_str_len".}
proc len*(s: var str): int32 =
str_len(addr s)
proc str_len_char(a2: ptr str): int32 {.importc: "nk_str_len_char".}
proc lenChar*(s: var str): int32 =
str_len_char(addr s)
type
command_buffer* = object
base*: ptr buffer
clip*: rect
use_clipping*: int32
userdata*: handle
begin*: uint
e*: uint
last*: uint
type
panel_type* {.size: sizeof(int32).} = enum
PANEL_WINDOW = (1 shl (0)), PANEL_GROUP = (1 shl (1)),
PANEL_POPUP = (1 shl (2)), PANEL_CONTEXTUAL = (1 shl (4)),
PANEL_COMBO = (1 shl (5)), PANEL_MENU = (1 shl (6)),
PANEL_TOOLTIP = (1 shl (7))
type
chart_type* {.size: sizeof(int32).} = enum
charT_LINES, charT_COLUMN, charT_MAX
type
style_item_type* {.size: sizeof(int32).} = enum
STYLE_ITEM_COLOR, STYLE_ITEM_IMAGE
type
button_behavior* {.size: sizeof(int32).} = enum
BUTTON_DEFAULT, BUTTON_REPEATER
type
buttons* {.size: sizeof(int32).} = enum
BUTTON_LEFT, BUTTON_MIDDLE, BUTTON_RIGHT, BUTTON_MAX
type
keys* {.size: sizeof(int32).} = enum
KEY_NONE, KEY_SHIFT, KEY_CTRL, KEY_DEL, KEY_ENTER, KEY_TAB,
KEY_BACKSPACE, KEY_COPY, KEY_CUT, KEY_PASTE, KEY_UP, KEY_DOWN,
KEY_LEFT, KEY_RIGHT, KEY_TEXT_INSERT_MODE, KEY_TEXT_REPLACE_MODE,
KEY_TEXT_RESET_MODE, KEY_TEXT_LINE_START, KEY_TEXT_LINE_END,
KEY_TEXT_START, KEY_TEXT_END, KEY_TEXT_UNDO, KEY_TEXT_REDO,
KEY_TEXT_SELECT_ALL, KEY_TEXT_WORD_LEFT, KEY_TEXT_WORD_RIGHT,
KEY_SCROLL_START, KEY_SCROLL_END, KEY_SCROLL_DOWN, KEY_SCROLL_UP,
KEY_MAX
type
style_cursor* {.size: sizeof(int32).} = enum
CURSOR_ARROW, CURSOR_TEXT, CURSOR_MOVE, CURSOR_RESIZE_VERTICAL,
CURSOR_RESIZE_HORIZONTAL, CURSOR_RESIZE_TOP_LEFT_DOWN_RIGHT,
CURSOR_RESIZE_TOP_RIGHT_DOWN_LEFT, CURSOR_COUNT
type
draw_vertex_layout_attribute* {.size: sizeof(int32).} = enum
VERTEX_POSITION, VERTEX_COLOR, VERTEX_TEXCOORD,
VERTEX_ATTRIBUTE_COUNT
type
draw_vertex_layout_format* {.size: sizeof(int32).} = enum
FORMAT_SCHAR, FORMAT_SSHORT, FORMAT_SINT, FORMAT_UCHAR,
FORMAT_USHORT, FORMAT_UINT, FORMAT_FLOAT, FORMAT_DOUBLE,
FORMAT_COLOR_BEGIN, FORMAT_R16G15B16, FORMAT_R32G32B32,
FORMAT_R8G8B8A8, FORMAT_R16G15B16A16, FORMAT_R32G32B32A32,
FORMAT_R32G32B32A32_FLOAT, FORMAT_R32G32B32A32_DOUBLE, FORMAT_RGB32,
FORMAT_RGBA32, FORMAT_COUNT
type
draw_vertex_layout_element* = object
attribute*: draw_vertex_layout_attribute
format*: draw_vertex_layout_format
offset*: uint
draw_command* = object
elem_count*: uint32
clip_rect*: rect
texture*: handle
draw_list* = object
clip_rect*: rect
circle_vtx*: array[12, vec2]
config*: convert_config
buffer*: ptr buffer
vertices*: ptr buffer
elements*: ptr buffer
element_count*: uint32
vertex_count*: uint32
cmd_count*: uint32
cmd_offset*: uint
path_count*: uint32
path_offset*: uint32
draw_null_texture* = object
texture*: handle
uv*: vec2
convert_config* = object
global_alpha*: float32
line_AA*: anti_aliasing
shape_AA*: anti_aliasing
circle_segment_count*: uint32
arc_segment_count*: uint32
curve_segment_count*: uint32
null*: draw_null_texture
vertex_layout*: ptr draw_vertex_layout_element
vertex_size*: uint
vertex_alignment*: uint
list_view* = object
begin*: int32
e*: int32
count*: int32
total_height*: int32
ctx*: ptr context
scroll_pointer*: ptr uint32
scroll_value*: uint32
symbol_type* {.size: sizeof(int32).} = enum
SYMBOL_NONE, SYMBOL_X, SYMBOL_UNDERSCORE, SYMBOL_CIRCLE_SOLID,
SYMBOL_CIRCLE_OUTLINE, SYMBOL_RECT_SOLID, SYMBOL_RECT_OUTLINE,
SYMBOL_TRIANGLE_UP, SYMBOL_TRIANGLE_DOWN, SYMBOL_TRIANGLE_LEFT,
SYMBOL_TRIANGLE_RIGHT, SYMBOL_PLUS, SYMBOL_MINUS, SYMBOL_MAX
menu_state* = object
x*: float32
y*: float32
w*: float32
h*: float32
offset*: scroll
row_layout* = object
typ*: panel_row_layout_type
index*: int32
height*: float32
columns*: int32
ratio*: ptr float32
item_width*: float32
item_height*: float32
item_offset*: float32
filled*: float32
item*: rect
tree_depth*: int32
templates*: array[16, float32]
popup_buffer* = object
begin*: uint
parent*: uint
last*: uint
e*: uint
active*: int32
chart_slot* = object
typ*: chart_type
color*: color
highlight*: color
min*: float32
max*: float32
range*: float32
count*: int32
last*: vec2
index*: int32
chart* = object
slot*: int32
x*: float32
y*: float32
w*: float32
h*: float32
slots*: array[4, chart_slot]
panel_row_layout_type* {.size: sizeof(int32).} = enum
LAYOUT_DYNAMIC_FIXED = 0, LAYOUT_DYNAMIC_ROW, LAYOUT_DYNAMIC_FREE,
LAYOUT_DYNAMIC, LAYOUT_STATIC_FIXED, LAYOUT_STATIC_ROW,
LAYOUT_STATIC_FREE, LAYOUT_STATIC, LAYOUT_TEMPLATE, LAYOUT_COUNT
panel* = object
typ*: panel_type
flags*: uint32
bounds*: rect
offset_x*: ptr uint32
offset_y*: ptr uint32
at_x*: float32
at_y*: float32
max_x*: float32
footer_height*: float32
header_height*: float32
border*: float32
has_scrolling*: uint32
clip*: rect
menu*: menu_state
row*: row_layout
chart*: chart
popup_buffer*: popup_buffer
buffer*: ptr command_buffer
parent*: ptr panel
window* = object
s*: uint32
name*: uint32
name_string*: array[64, char]
flags*: uint32
bounds*: rect
scrollbar*: scroll
buffer*: command_buffer
layout*: ptr panel
scrollbar_hiding_timer*: float32
property*: property_state
popup*: popup_state
edit*: edit_state
scrolled*: uint32
tables*: ptr table
table_count*: uint16
table_size*: uint16
next*: ptr window
prev*: ptr window
parent*: ptr window
popup_state* = object
win*: ptr window
typ*: panel_type
name*: uint32
active*: int32
combo_count*: uint32
con_count*: uint32
con_old*: uint32
active_con*: uint32
header*: rect
edit_state* = object
name*: uint32
s*: uint32
old*: uint32
active*: int32
prev*: int32
cursor*: int32
sel_start*: int32
sel_end*: int32
scrollbar*: scroll
mode*: cuchar
single_line*: cuchar
property_state* = object
active*: int32
prev*: int32
buffer*: array[64, char]
length*: int32
cursor*: int32
name*: uint32
s*: uint32
old*: uint32
state*: int32
style_item_data* = object {.union.}
image*: img
color*: color
style_item* = object
typ*: style_item_type
data*: style_item_data
config_stack_style_item_element* = object
address*: ptr style_item
old_value*: style_item
config_stack_float_element* = object
address*: ptr float32
old_value*: float32
config_stack_vec2_element* = object
address*: ptr vec2
old_value*: vec2
config_stack_flags_element* = object
address*: ptr uint32
old_value*: uint32
config_stack_color_element* = object
address*: ptr color
old_value*: color
config_stack_user_font_element* = object
address*: ptr ptr user_font
old_value*: ptr user_font
config_stack_button_behavior_element* = object
address*: ptr button_behavior
old_value*: button_behavior
config_stack_style_item* = object
head*: int32
elements*: array[16, config_stack_style_item_element]
config_stack_float* = object
head*: int32
elements*: array[32, config_stack_float_element]
config_stack_vec2* = object
head*: int32
elements*: array[16, config_stack_vec2_element]
config_stack_flags* = object
head*: int32
elements*: array[32, config_stack_flags_element]
config_stack_color* = object
head*: int32
elements*: array[32, config_stack_color_element]
config_stack_user_font* = object
head*: int32
elements*: array[8, config_stack_user_font_element]
config_stack_button_behavior* = object
head*: int32
elements*: array[8, config_stack_button_behavior_element]
configuration_stacks* = object
style_items*: config_stack_style_item
floats*: config_stack_float
vectors*: config_stack_vec2
flags*: config_stack_flags
colors*: config_stack_color
fonts*: config_stack_user_font
button_behaviors*: config_stack_button_behavior
table* = object
s*: uint32
keys: array[find_size(window, panel), uint32]
values: array[find_size(window, panel), uint32]
next*: ptr table
prev*: ptr table
page_data* = object {.union.}
tbl*: table
pan*: panel
win*: window
page_element* = object
data*: page_data
next*: ptr page_element
prev*: ptr page_element
page* = object
size*: uint32
next*: ptr page
win*: array[1, page_element]
pool* = object
alloc*: allocator
typ*: allocation_type
page_count*: uint32
pages*: ptr page
freelist*: ptr page_element
capacity*: uint32
size*: uint
cap*: uint
mouse_button* = object
down*: int32
clicked*: uint32
clicked_pos*: vec2
mouse* = object
buttons*: array[BUTTON_MAX, mouse_button]
pos*: vec2
prev*: vec2
delta*: vec2
scroll_delta*: float32
grab*: cuchar
grabbed*: cuchar
ungrab*: cuchar
key* = object
down*: int32
clicked*: uint32
keyboard* = object
keys*: array[KEY_MAX, key]
text*: array[16, char]
text_len*: int32
input* = object
keyboard*: keyboard
mouse*: mouse
context* = object
input*: input
style*: style
memory*: buffer
clip*: clipboard
last_widget_state*: uint32
button_behavior*: button_behavior
stacks*: configuration_stacks
delta_time_seconds*: float32
draw_list*: draw_list
text_edit*: text_edit
overlay*: command_buffer
build*: int32
use_pool*: int32
pool*: pool