Rev Author Line No. Line
23 ovan 1 /*
2  Nuklear - v1.00 - public domain
3  no warrenty implied; use at your own risk.
4  authored from 2015-2016 by Micha Mettke
5  
6 ABOUT:
7     This is a minimal state immediate mode graphical user interface single header
8     toolkit written in ANSI C and licensed under public domain.
9     It was designed as a simple embeddable user interface for application and does
10     not have any dependencies, a default renderbackend or OS window and input handling
11     but instead provides a very modular library approach by using simple input state
12     for input and draw commands describing primitive shapes as output.
13     So instead of providing a layered library that tries to abstract over a number
14     of platform and render backends it only focuses on the actual UI.
15  
16 VALUES:
17     - Immediate mode graphical user interface toolkit
18     - Single header library
19     - Written in C89 (ANSI C)
20     - Small codebase (~15kLOC)
21     - Focus on portability, efficiency and simplicity
22     - No dependencies (not even the standard library if not wanted)
23     - Fully skinnable and customizable
24     - Low memory footprint with total memory control if needed or wanted
25     - UTF-8 support
26     - No global or hidden state
27     - Customizable library modules (you can compile and use only what you need)
28     - Optional font baker and vertex buffer output
29  
30 USAGE:
31     This library is self contained in one single header file and can be used either
32     in header only mode or in implementation mode. The header only mode is used
33     by default when included and allows including this header in other headers
34     and does not contain the actual implementation.
35  
36     The implementation mode requires to define  the preprocessor macro
37     NK_IMPLEMENTATION in *one* .c/.cpp file before #includeing this file, e.g.:
38  
39         #define NK_IMPLEMENTATION
40         #include "nuklear.h"
41  
42     Also optionally define the symbols listed in the section "OPTIONAL DEFINES"
43     below in implementation mode if you want to use additional functionality
44     or need more control over the library.
45  
46 FEATURES:
47     - Absolutely no platform dependent code
48     - Memory management control ranging from/to
49         - Ease of use by allocating everything from the standard library
50         - Control every byte of memory inside the library
51     - Font handling control ranging from/to
52         - Use your own font implementation to draw shapes/vertexes
53         - Use this libraries internal font baking and handling API
54     - Drawing output control ranging from/to
55         - Simple shapes for more high level APIs which already having drawing capabilities
56         - Hardware accessible anti-aliased vertex buffer output
57     - Customizable colors and properties ranging from/to
58         - Simple changes to color by filling a simple color table
59         - Complete control with ability to use skinning to decorate widgets
60     - Bendable UI library with widget ranging from/to
61         - Basic widgets like buttons, checkboxes, slider, ...
62         - Advanced widget like abstract comboboxes, contextual menus,...
63     - Compile time configuration to only compile what you need
64         - Subset which can be used if you do not want to link or use the standard library
65     - Can be easily modified only update on user input instead of frame updates
66  
67 OPTIONAL DEFINES:
68     NK_PRIVATE
69         If defined declares all functions as static, so they can only be accessed
70         for the file that creates the implementation
71  
72     NK_INCLUDE_FIXED_TYPES
73         If defined it will include header <stdint.h> for fixed sized types
74         otherwise you have to select the correct types.
75  
76     NK_INCLUDE_DEFAULT_ALLOCATOR
77         if defined it will include header <stdlib.h> and provide additional functions
78         to use this library without caring for memory allocation control and therefore
79         ease memory management.
80         IMPORTANT:  this adds the standard library with malloc and free so don't define
81                     if you don't want to link to the standard library!
82  
83     NK_INCLUDE_STANDARD_IO
84         if defined it will include header <stdio.h> and <stdarg.h> and provide
85         additional functions depending on file loading and variable arguments
86         IMPORTANT:  this adds the standard library with fopen, fclose,...
87                     as well as va_list,... so don't define this
88                     if you don't want to link to the standard library!
89  
90     NK_INCLUDE_VERTEX_BUFFER_OUTPUT
91         Defining this adds a vertex draw command list backend to this
92         library, which allows you to convert queue commands into vertex draw commands.
93         This is mainly if you need a hardware accessible format for OpenGL, DirectX,
94         Vulkan, Metal,...
95  
96     NK_INCLUDE_FONT_BAKING
97         Defining this adds the `stb_truetype` and `stb_rect_pack` implementation
98         to this library and provides a default font for font loading and rendering.
99         If you already have font handling or do not want to use this font handler
100         you don't have to define it.
101  
102     NK_INCLUDE_DEFAULT_FONT
103         Defining this adds the default font: ProggyClean.ttf font into this library
104         which can be loaded into a font atlas and allows using this library without
105         having a truetype font
106         IMPORTANT: enabling this adds ~12kb to global stack memory
107  
108     NK_INCLUDE_COMMAND_USERDATA
109         Defining this adds a userdata pointer into each command. Can be useful for
110         example if you want to provide custom shader depending on the used widget.
111         Can be combined with the style structures.
112  
113     NK_BUTTON_TRIGGER_ON_RELEASE
114         Different platforms require button clicks occuring either on buttons being
115         pressed (up to down) or released (down to up).
116         By default this library will react on buttons being pressed, but if you
117         define this it will only trigger if a button is released.
118  
119     NK_ASSERT
120         If you don't define this, nuklear will use <assert.h> with assert().
121         IMPORTANT:  it also adds the standard library so define to nothing of not wanted!
122  
123     NK_BUFFER_DEFAULT_INITIAL_SIZE
124         Initial buffer size allocated by all buffers while using the default allocator
125         functions included by defining NK_INCLUDE_DEFAULT_ALLOCATOR. If you don't
126         want to allocate the default 4k memory then redefine it.
127  
128     NK_MAX_NUMBER_BUFFER
129         Maximum buffer size for the conversion buffer between float and string
130         Under normal circumstances this should be more than sufficient.
131  
132     NK_INPUT_MAX
133         Defines the max number of bytes which can be added as text input in one frame.
134         Under normal circumstances this should be more than sufficient.
135  
136     NK_MEMSET
137         You can define this to 'memset' or your own memset implementation
138         replacement. If not nuklear will use its own version.
139  
140     NK_MEMCOPY
141         You can define this to 'memcpy' or your own memset implementation
142         replacement. If not nuklear will use its own version.
143  
144     NK_SQRT
145         You can define this to 'sqrt' or your own sqrt implementation
146         replacement. If not nuklear will use its own slow and not highly
147         accurate version.
148  
149     NK_SIN
150         You can define this to 'sinf' or your own sine implementation
151         replacement. If not nuklear will use its own approximation implementation.
152  
153     NK_COS
154         You can define this to 'cosf' or your own cosine implementation
155         replacement. If not nuklear will use its own approximation implementation.
156  
157     NK_BYTE
158     NK_INT16
159     NK_UINT16
160     NK_INT32
161     NK_UINT32
162     NK_SIZE_TYPE
163     NK_POINTER_TYPE
164         If you compile without NK_USE_FIXED_TYPE then a number of standard types
165         will be selected and compile time validated. If they are incorrect you can
166         define the correct types.
167  
168 CREDITS:
169     Developed by Micha Mettke and every direct or indirect contributor to the GitHub.
170  
171     Embeds stb_texedit, stb_truetype and stb_rectpack by Sean Barret (public domain)
172     Embeds ProggyClean.ttf font by Tristan Grimmer (MIT license).
173  
174     Big thank you to Omar Cornut (ocornut@github) for his imgui library and
175     giving me the inspiration for this library, Casey Muratori for handmade hero
176     and his original immediate mode graphical user interface idea and Sean
177     Barret for his amazing single header libraries which restored by faith
178     in libraries and brought me to create some of my own.
179  
180 LICENSE:
181     This software is dual-licensed to the public domain and under the following
182     license: you are granted a perpetual, irrevocable license to copy, modify,
183     publish and distribute this file as you see fit.
184 */
185 #ifndef NK_H_
186 #define NK_H_
187  
188 #ifdef __cplusplus
189 extern "C" {
190 #endif
191 /*
192  * ==============================================================
193  *
194  *                          CONSTANTS
195  *
196  * ===============================================================
197  */
198 #define NK_UTF_INVALID 0xFFFD /* internal invalid utf8 rune */
199 #define NK_UTF_SIZE 4 /* describes the number of bytes a glyph consists of*/
200 #ifndef NK_INPUT_MAX
201 #define NK_INPUT_MAX 16
202 #endif
203 #ifndef NK_MAX_NUMBER_BUFFER
204 #define NK_MAX_NUMBER_BUFFER 64
205 #endif
206 /*
207  * ===============================================================
208  *
209  *                          BASIC
210  *
211  * ===============================================================
212  */
213 #ifdef NK_INCLUDE_FIXED_TYPES
214 #include <stdint.h>
215 typedef int16_t nk_short;
216 typedef uint16_t nk_ushort;
217 typedef int32_t nk_int;
218 typedef uint32_t nk_uint;
219 typedef uint32_t nk_hash;
220 typedef uintptr_t nk_size;
221 typedef uintptr_t nk_ptr;
222 typedef uint32_t nk_flags;
223 typedef uint32_t nk_rune;
224 typedef uint8_t nk_byte;
225 #else
226 #ifndef NK_BYTE
227 typedef unsigned char nk_byte;
228 #else
229 typedef NK_BYTE nk_byte;
230 #endif
231 #ifndef NK_INT16
232 typedef short nk_short;
233 #else
234 typedef NK_INT16 nk_short;
235 #endif
236 #ifndef NK_UINT16
237 typedef unsigned short nk_ushort;
238 #else
239 typedef NK_UINT16 nk_ushort;
240 #endif
241 #ifndef NK_INT32
242 typedef int nk_int;
243 #else
244 typedef NK_INT32 nk_int;
245 #endif
246 #ifndef NK_UINT32
247 typedef unsigned int nk_uint;
248 #else
249 typedef NK_UINT32 nk_uint;
250 #endif
251 #ifndef NK_SIZE_TYPE
252 typedef unsigned long nk_size;
253 #else
254 typedef NK_SIZE_TYPE nk_size;
255 #endif
256 #ifndef NK_POINTER_TYPE
257 typedef unsigned long nk_ptr;
258 #else
259 typedef NK_POINTER_TYPE nk_ptr;
260 #endif
261 typedef unsigned int nk_hash;
262 typedef unsigned int nk_flags;
263 typedef nk_uint nk_rune;
264 typedef unsigned char nk_byte;
265 #endif
266  
267 #ifdef NK_PRIVATE
268 #define NK_API static
269 #else
270 #define NK_API extern
271 #endif
272  
273 #define NK_INTERN static
274 #define NK_STORAGE static
275 #define NK_GLOBAL static
276  
277 /* ============================================================================
278  *
279  *                                  API
280  *
281  * =========================================================================== */
282 #define NK_UNDEFINED (-1.0f)
283 #define NK_FLAG(x) (1 << (x))
284 #define NK_STRINGIFY(x) #x
285 #define NK_LINE_STR(x) NK_STRINGIFY(x)
286 #define NK_FILE_LINE __FILE__ ":" NK_LINE_STR(__LINE__)
287  
288 struct nk_buffer;
289 struct nk_allocator;
290 struct nk_command_buffer;
291 struct nk_draw_command;
292 struct nk_convert_config;
293 struct nk_text_edit;
294 struct nk_draw_list;
295 struct nk_user_font;
296 struct nk_panel;
297 struct nk_context;
298  
299 enum {nk_false, nk_true};
300 struct nk_color {nk_byte r,g,b,a;};
301 struct nk_vec2 {float x,y;};
302 struct nk_vec2i {short x, y;};
303 struct nk_rect {float x,y,w,h;};
304 struct nk_recti {short x,y,w,h;};
305 typedef char nk_glyph[NK_UTF_SIZE];
306 typedef union {void *ptr; int id;} nk_handle;
307 struct nk_image {nk_handle handle;unsigned short w,h;unsigned short region[4];};
308 struct nk_scroll {unsigned short x, y;};
309 enum nk_heading {NK_UP, NK_RIGHT, NK_DOWN, NK_LEFT};
310  
311 typedef int(*nk_filter)(const struct nk_text_edit*, nk_rune unicode);
312 typedef void(*nk_paste_f)(nk_handle, struct nk_text_edit*);
313 typedef void(*nk_copy_f)(nk_handle, const char*, int len);
314  
315 enum nk_button_behavior {NK_BUTTON_DEFAULT,NK_BUTTON_REPEATER};
316 enum nk_modify          {NK_FIXED=nk_false,NK_MODIFIABLE=nk_true};
317 enum nk_orientation     {NK_VERTICAL,NK_HORIZONTAL};
318 enum nk_collapse_states {NK_MINIMIZED=nk_false,NK_MAXIMIZED = nk_true};
319 enum nk_show_states     {NK_HIDDEN=nk_false,NK_SHOWN=nk_true};
320 enum nk_chart_type      {NK_CHART_LINES,NK_CHART_COLUMN,NK_CHART_MAX};
321 enum nk_chart_event     {NK_CHART_HOVERING=0x01, NK_CHART_CLICKED=0x02};
322 enum nk_color_format    {NK_RGB, NK_RGBA};
323 enum nk_popup_type      {NK_POPUP_STATIC,NK_POPUP_DYNAMIC};
324 enum nk_layout_format   {NK_DYNAMIC,NK_STATIC};
325 enum nk_tree_type       {NK_TREE_NODE,NK_TREE_TAB};
326 enum nk_anti_aliasing   {NK_ANTI_ALIASING_OFF,NK_ANTI_ALIASING_ON};
327  
328 struct nk_allocator {
329     nk_handle userdata;
330     void*(*alloc)(nk_handle, void *old, nk_size);
331     void(*free)(nk_handle, void*);
332 };
333  
334 struct nk_draw_null_texture {
335     nk_handle texture;/* texture handle to a texture with a white pixel */
336     struct nk_vec2 uv; /* coordinates to a white pixel in the texture  */
337 };
338 struct nk_convert_config {
339     float global_alpha; /* global alpha value */
340     enum nk_anti_aliasing line_AA; /* line anti-aliasing flag can be turned off if you are tight on memory */
341     enum nk_anti_aliasing shape_AA; /* shape anti-aliasing flag can be turned off if you are tight on memory */
342     unsigned int circle_segment_count; /* number of segments used for circles: default to 22 */
343     unsigned int arc_segment_count; /* number of segments used for arcs: default to 22 */
344     unsigned int curve_segment_count; /* number of segments used for curves: default to 22 */
345     struct nk_draw_null_texture null; /* handle to texture with a white pixel for shape drawing */
346 };
347  
348 enum nk_symbol_type {
349     NK_SYMBOL_NONE,
350     NK_SYMBOL_X,
351     NK_SYMBOL_UNDERSCORE,
352     NK_SYMBOL_CIRCLE,
353     NK_SYMBOL_CIRCLE_FILLED,
354     NK_SYMBOL_RECT,
355     NK_SYMBOL_RECT_FILLED,
356     NK_SYMBOL_TRIANGLE_UP,
357     NK_SYMBOL_TRIANGLE_DOWN,
358     NK_SYMBOL_TRIANGLE_LEFT,
359     NK_SYMBOL_TRIANGLE_RIGHT,
360     NK_SYMBOL_PLUS,
361     NK_SYMBOL_MINUS,
362     NK_SYMBOL_MAX
363 };
364  
365 enum nk_keys {
366     NK_KEY_NONE,
367     NK_KEY_SHIFT,
368     NK_KEY_CTRL,
369     NK_KEY_DEL,
370     NK_KEY_ENTER,
371     NK_KEY_TAB,
372     NK_KEY_BACKSPACE,
373     NK_KEY_COPY,
374     NK_KEY_CUT,
375     NK_KEY_PASTE,
376     NK_KEY_UP,
377     NK_KEY_DOWN,
378     NK_KEY_LEFT,
379     NK_KEY_RIGHT,
380     NK_KEY_TEXT_INSERT_MODE,
381     NK_KEY_TEXT_LINE_START,
382     NK_KEY_TEXT_LINE_END,
383     NK_KEY_TEXT_START,
384     NK_KEY_TEXT_END,
385     NK_KEY_TEXT_UNDO,
386     NK_KEY_TEXT_REDO,
387     NK_KEY_TEXT_WORD_LEFT,
388     NK_KEY_TEXT_WORD_RIGHT,
389     NK_KEY_MAX
390 };
391  
392 enum nk_buttons {
393     NK_BUTTON_LEFT,
394     NK_BUTTON_MIDDLE,
395     NK_BUTTON_RIGHT,
396     NK_BUTTON_MAX
397 };
398  
399 enum nk_style_colors {
400     NK_COLOR_TEXT,
401     NK_COLOR_WINDOW,
402     NK_COLOR_HEADER,
403     NK_COLOR_BORDER,
404     NK_COLOR_BUTTON,
405     NK_COLOR_BUTTON_HOVER,
406     NK_COLOR_BUTTON_ACTIVE,
407     NK_COLOR_TOGGLE,
408     NK_COLOR_TOGGLE_HOVER,
409     NK_COLOR_TOGGLE_CURSOR,
410     NK_COLOR_SELECT,
411     NK_COLOR_SELECT_ACTIVE,
412     NK_COLOR_SLIDER,
413     NK_COLOR_SLIDER_CURSOR,
414     NK_COLOR_SLIDER_CURSOR_HOVER,
415     NK_COLOR_SLIDER_CURSOR_ACTIVE,
416     NK_COLOR_PROPERTY,
417     NK_COLOR_EDIT,
418     NK_COLOR_EDIT_CURSOR,
419     NK_COLOR_COMBO,
420     NK_COLOR_CHART,
421     NK_COLOR_CHART_COLOR,
422     NK_COLOR_CHART_COLOR_HIGHLIGHT,
423     NK_COLOR_SCROLLBAR,
424     NK_COLOR_SCROLLBAR_CURSOR,
425     NK_COLOR_SCROLLBAR_CURSOR_HOVER,
426     NK_COLOR_SCROLLBAR_CURSOR_ACTIVE,
427     NK_COLOR_TAB_HEADER,
428     NK_COLOR_COUNT
429 };
430  
431 enum nk_widget_layout_states {
432     NK_WIDGET_INVALID, /* The widget cannot be seen and is completely out of view */
433     NK_WIDGET_VALID, /* The widget is completely inside the window and can be updated and drawn */
434     NK_WIDGET_ROM /* The widget is partially visible and cannot be updated */
435 };
436  
437 /* widget states */
438 enum nk_widget_states {
439     NK_WIDGET_STATE_MODIFIED    = NK_FLAG(1),
440     NK_WIDGET_STATE_INACTIVE    = NK_FLAG(2), /* widget is neither active nor hovered */
441     NK_WIDGET_STATE_ENTERED     = NK_FLAG(3), /* widget has been hovered on the current frame */
442     NK_WIDGET_STATE_HOVER       = NK_FLAG(4), /* widget is being hovered */
443     NK_WIDGET_STATE_ACTIVED     = NK_FLAG(5),/* widget is currently activated */
444     NK_WIDGET_STATE_LEFT        = NK_FLAG(6), /* widget is from this frame on not hovered anymore */
445     NK_WIDGET_STATE_HOVERED     = NK_WIDGET_STATE_HOVER|NK_WIDGET_STATE_MODIFIED, /* widget is being hovered */
446     NK_WIDGET_STATE_ACTIVE      = NK_WIDGET_STATE_ACTIVED|NK_WIDGET_STATE_MODIFIED /* widget is currently activated */
447 };
448  
449 /* text alignment */
450 enum nk_text_align {
451     NK_TEXT_ALIGN_LEFT        = 0x01,
452     NK_TEXT_ALIGN_CENTERED    = 0x02,
453     NK_TEXT_ALIGN_RIGHT       = 0x04,
454     NK_TEXT_ALIGN_TOP         = 0x08,
455     NK_TEXT_ALIGN_MIDDLE      = 0x10,
456     NK_TEXT_ALIGN_BOTTOM      = 0x20
457 };
458 enum nk_text_alignment {
459     NK_TEXT_LEFT        = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_LEFT,
460     NK_TEXT_CENTERED    = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_CENTERED,
461     NK_TEXT_RIGHT       = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_RIGHT
462 };
463  
464 enum nk_edit_flags {
465     NK_EDIT_DEFAULT                 = 0,
466     NK_EDIT_READ_ONLY               = NK_FLAG(0),
467     NK_EDIT_AUTO_SELECT             = NK_FLAG(1),
468     NK_EDIT_SIG_ENTER               = NK_FLAG(2),
469     NK_EDIT_ALLOW_TAB               = NK_FLAG(3),
470     NK_EDIT_NO_CURSOR               = NK_FLAG(4),
471     NK_EDIT_SELECTABLE              = NK_FLAG(5),
472     NK_EDIT_CLIPBOARD               = NK_FLAG(6),
473     NK_EDIT_CTRL_ENTER_NEWLINE      = NK_FLAG(7),
474     NK_EDIT_NO_HORIZONTAL_SCROLL    = NK_FLAG(8),
475     NK_EDIT_ALWAYS_INSERT_MODE      = NK_FLAG(9),
476     NK_EDIT_MULTILINE               = NK_FLAG(11)
477 };
478 enum nk_edit_types {
479     NK_EDIT_SIMPLE  = NK_EDIT_ALWAYS_INSERT_MODE,
480     NK_EDIT_FIELD   = NK_EDIT_SIMPLE|NK_EDIT_SELECTABLE,
481     NK_EDIT_BOX     = NK_EDIT_ALWAYS_INSERT_MODE| NK_EDIT_SELECTABLE|
482                         NK_EDIT_MULTILINE|NK_EDIT_ALLOW_TAB
483 };
484 enum nk_edit_events {
485     NK_EDIT_ACTIVE      = NK_FLAG(0), /* edit widget is currently being modified */
486     NK_EDIT_INACTIVE    = NK_FLAG(1), /* edit widget is not active and is not being modified */
487     NK_EDIT_ACTIVATED   = NK_FLAG(2), /* edit widget went from state inactive to state active */
488     NK_EDIT_DEACTIVATED = NK_FLAG(3), /* edit widget went from state active to state inactive */
489     NK_EDIT_COMMITED    = NK_FLAG(4) /* edit widget has received an enter and lost focus */
490 };
491  
492 enum nk_panel_flags {
493     NK_WINDOW_BORDER        = NK_FLAG(0), /* Draws a border around the window to visually separate the window * from the background */
494     NK_WINDOW_BORDER_HEADER = NK_FLAG(1), /* Draws a border between window header and body */
495     NK_WINDOW_MOVABLE       = NK_FLAG(2), /* The movable flag indicates that a window can be moved by user input or * by dragging the window header */
496     NK_WINDOW_SCALABLE      = NK_FLAG(3), /* The scalable flag indicates that a window can be scaled by user input * by dragging a scaler icon at the button of the window */
497     NK_WINDOW_CLOSABLE      = NK_FLAG(4), /* adds a closable icon into the header */
498     NK_WINDOW_MINIMIZABLE   = NK_FLAG(5), /* adds a minimize icon into the header */
499     NK_WINDOW_DYNAMIC       = NK_FLAG(6), /* special window type growing up in height while being filled to a * certain maximum height */
500     NK_WINDOW_NO_SCROLLBAR  = NK_FLAG(7), /* Removes the scrollbar from the window */
501     NK_WINDOW_TITLE         = NK_FLAG(8) /* Forces a header at the top at the window showing the title */
502 };
503  
504 /* context */
505 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
506 NK_API int                      nk_init_default(struct nk_context*, const struct nk_user_font*);
507 #endif
508 NK_API int                      nk_init_fixed(struct nk_context*, void *memory, nk_size size, const struct nk_user_font*);
509 NK_API int                      nk_init_custom(struct nk_context*, struct nk_buffer *cmds, struct nk_buffer *pool, const struct nk_user_font*);
510 NK_API int                      nk_init(struct nk_context*, struct nk_allocator*, const struct nk_user_font*);
511 NK_API void                     nk_clear(struct nk_context*);
512 NK_API void                     nk_free(struct nk_context*);
513 #ifdef NK_INCLUDE_COMMAND_USERDATA
514 NK_API void                     nk_set_user_data(struct nk_context*, nk_handle handle);
515 #endif
516  
517 /* window */
518 NK_API int                      nk_begin(struct nk_context*, struct nk_panel*, const char *title, struct nk_rect bounds, nk_flags flags);
519 NK_API void                     nk_end(struct nk_context*);
520  
521 NK_API struct nk_window*        nk_window_find(struct nk_context *ctx, const char *name);
522 NK_API struct nk_rect           nk_window_get_bounds(const struct nk_context*);
523 NK_API struct nk_vec2           nk_window_get_position(const struct nk_context*);
524 NK_API struct nk_vec2           nk_window_get_size(const struct nk_context*);
525 NK_API float                    nk_window_get_width(const struct nk_context*);
526 NK_API float                    nk_window_get_height(const struct nk_context*);
527 NK_API struct nk_panel*         nk_window_get_panel(struct nk_context*);
528 NK_API struct nk_rect           nk_window_get_content_region(struct nk_context*);
529 NK_API struct nk_vec2           nk_window_get_content_region_min(struct nk_context*);
530 NK_API struct nk_vec2           nk_window_get_content_region_max(struct nk_context*);
531 NK_API struct nk_vec2           nk_window_get_content_region_size(struct nk_context*);
532 NK_API struct nk_command_buffer* nk_window_get_canvas(struct nk_context*);
533  
534 NK_API int                      nk_window_has_focus(const struct nk_context*);
535 NK_API int                      nk_window_is_collapsed(struct nk_context*, const char*);
536 NK_API int                      nk_window_is_closed(struct nk_context*, const char*);
537 NK_API int                      nk_window_is_active(struct nk_context*, const char*);
538 NK_API int                      nk_window_is_hovered(struct nk_context*);
539 NK_API int                      nk_window_is_any_hovered(struct nk_context*);
540 NK_API int                      nk_item_is_any_active(struct nk_context*);
541  
542 NK_API void                     nk_window_set_bounds(struct nk_context*, struct nk_rect);
543 NK_API void                     nk_window_set_position(struct nk_context*, struct nk_vec2);
544 NK_API void                     nk_window_set_size(struct nk_context*, struct nk_vec2);
545 NK_API void                     nk_window_set_focus(struct nk_context*, const char *name);
546  
547 NK_API void                     nk_window_close(struct nk_context *ctx, const char *name);
548 NK_API void                     nk_window_collapse(struct nk_context*, const char *name, enum nk_collapse_states);
549 NK_API void                     nk_window_collapse_if(struct nk_context*, const char *name, enum nk_collapse_states, int cond);
550 NK_API void                     nk_window_show(struct nk_context*, const char *name, enum nk_show_states);
551 NK_API void                     nk_window_show_if(struct nk_context*, const char *name, enum nk_show_states, int cond);
552  
553 /* Layout */
554 NK_API void                     nk_layout_row_dynamic(struct nk_context*, float height, int cols);
555 NK_API void                     nk_layout_row_static(struct nk_context*, float height, int item_width, int cols);
556  
557 NK_API void                     nk_layout_row_begin(struct nk_context*, enum nk_layout_format, float row_height, int cols);
558 NK_API void                     nk_layout_row_push(struct nk_context*, float value);
559 NK_API void                     nk_layout_row_end(struct nk_context*);
560 NK_API void                     nk_layout_row(struct nk_context*, enum nk_layout_format, float height, int cols, const float *ratio);
561  
562 NK_API void                     nk_layout_space_begin(struct nk_context*, enum nk_layout_format, float height, int widget_count);
563 NK_API void                     nk_layout_space_push(struct nk_context*, struct nk_rect);
564 NK_API void                     nk_layout_space_end(struct nk_context*);
565  
566 NK_API struct nk_rect           nk_layout_space_bounds(struct nk_context*);
567 NK_API struct nk_vec2           nk_layout_space_to_screen(struct nk_context*, struct nk_vec2);
568 NK_API struct nk_vec2           nk_layout_space_to_local(struct nk_context*, struct nk_vec2);
569 NK_API struct nk_rect           nk_layout_space_rect_to_screen(struct nk_context*, struct nk_rect);
570 NK_API struct nk_rect           nk_layout_space_rect_to_local(struct nk_context*, struct nk_rect);
571  
572 /* Layout: Group */
573 NK_API int                      nk_group_begin(struct nk_context*, struct nk_panel*, const char *title, nk_flags);
574 NK_API void                     nk_group_end(struct nk_context*);
575  
576 /* Layout: Tree */
577 #define                         nk_tree_push(ctx, type, title, state) nk_tree_push_hashed(ctx, type, title, state, __FILE__,nk_strlen(__FILE__),__LINE__)
578 #define                         nk_tree_push_id(ctx, type, title, state, id) nk_tree_push_hashed(ctx, type, title, state, NK_FILE_LINE,nk_strlen(NK_FILE_LINE),id)
579 NK_API int                      nk_tree_push_hashed(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed);
580 NK_API void                     nk_tree_pop(struct nk_context*);
581  
582 /* Widgets */
583 NK_API void                     nk_text(struct nk_context*, const char*, int, nk_flags);
584 NK_API void                     nk_text_colored(struct nk_context*, const char*, int, nk_flags, struct nk_color);
585 NK_API void                     nk_text_wrap(struct nk_context*, const char*, int);
586 NK_API void                     nk_text_wrap_colored(struct nk_context*, const char*, int, struct nk_color);
587  
588 NK_API void                     nk_label(struct nk_context*, const char*, nk_flags);
589 NK_API void                     nk_label_colored(struct nk_context*, const char*, nk_flags align, struct nk_color);
590 NK_API void                     nk_label_wrap(struct nk_context*, const char*);
591 NK_API void                     nk_label_colored_wrap(struct nk_context*, const char*, struct nk_color);
592 NK_API void                     nk_image(struct nk_context*, struct nk_image);
593 #ifdef NK_INCLUDE_STANDARD_IO
594 NK_API void                     nk_labelf(struct nk_context*, nk_flags, const char*, ...);
595 NK_API void                     nk_labelf_colored(struct nk_context*, nk_flags align, struct nk_color, const char*,...);
596 NK_API void                     nk_labelf_wrap(struct nk_context*, const char*,...);
597 NK_API void                     nk_labelf_colored_wrap(struct nk_context*, struct nk_color, const char*,...);
598  
599 NK_API void                     nk_value_bool(struct nk_context*, const char *prefix, int);
600 NK_API void                     nk_value_int(struct nk_context*, const char *prefix, int);
601 NK_API void                     nk_value_uint(struct nk_context*, const char *prefix, unsigned int);
602 NK_API void                     nk_value_float(struct nk_context*, const char *prefix, float);
603 NK_API void                     nk_value_color_byte(struct nk_context*, const char *prefix, struct nk_color);
604 NK_API void                     nk_value_color_float(struct nk_context*, const char *prefix, struct nk_color);
605 NK_API void                     nk_value_color_hex(struct nk_context*, const char *prefix, struct nk_color);
606 #endif
607  
608 /* Widgets: Buttons */
609 NK_API int                      nk_button_text(struct nk_context *ctx, const char *title, int len, enum nk_button_behavior);
610 NK_API int                      nk_button_label(struct nk_context *ctx, const char *title, enum nk_button_behavior);
611 NK_API int                      nk_button_color(struct nk_context*, struct nk_color, enum nk_button_behavior);
612 NK_API int                      nk_button_symbol(struct nk_context*, enum nk_symbol_type, enum nk_button_behavior);
613 NK_API int                      nk_button_image(struct nk_context*, struct nk_image img, enum nk_button_behavior);
614 NK_API int                      nk_button_symbol_label(struct nk_context*, enum nk_symbol_type, const char*, nk_flags text_alignment, enum nk_button_behavior);
615 NK_API int                      nk_button_symbol_text(struct nk_context*, enum nk_symbol_type, const char*, int, nk_flags alignment, enum nk_button_behavior);
616 NK_API int                      nk_button_image_label(struct nk_context*, struct nk_image img, const char*, nk_flags text_alignment, enum nk_button_behavior);
617 NK_API int                      nk_button_image_text(struct nk_context*, struct nk_image img, const char*, int, nk_flags alignment, enum nk_button_behavior);
618  
619 /* Widgets: Checkbox */
620 NK_API int                      nk_check_label(struct nk_context*, const char*, int active);
621 NK_API int                      nk_check_text(struct nk_context*, const char*, int,int active);
622 NK_API unsigned                 nk_check_flags_label(struct nk_context*, const char*, unsigned int flags, unsigned int value);
623 NK_API unsigned                 nk_check_flags_text(struct nk_context*, const char*, int, unsigned int flags, unsigned int value);
624 NK_API int                      nk_checkbox_label(struct nk_context*, const char*, int *active);
625 NK_API int                      nk_checkbox_text(struct nk_context*, const char*, int, int *active);
626 NK_API int                      nk_checkbox_flags_label(struct nk_context*, const char*, unsigned int *flags, unsigned int value);
627 NK_API int                      nk_checkbox_flags_text(struct nk_context*, const char*, int, unsigned int *flags, unsigned int value);
628  
629 /* Widgets: Radio */
630 NK_API int                      nk_radio_label(struct nk_context*, const char*, int *active);
631 NK_API int                      nk_radio_text(struct nk_context*, const char*, int, int *active);
632 NK_API int                      nk_option_label(struct nk_context*, const char*, int active);
633 NK_API int                      nk_option_text(struct nk_context*, const char*, int, int active);
634  
635 /* Widgets: Selectable */
636 NK_API int                      nk_selectable_label(struct nk_context*, const char*, nk_flags align, int *value);
637 NK_API int                      nk_selectable_text(struct nk_context*, const char*, int, nk_flags align, int *value);
638 NK_API int                      nk_select_label(struct nk_context*, const char*, nk_flags align, int value);
639 NK_API int                      nk_select_text(struct nk_context*, const char*, int, nk_flags align, int value);
640  
641 /* Widgets: Slider */
642 NK_API float                    nk_slide_float(struct nk_context*, float min, float val, float max, float step);
643 NK_API int                      nk_slide_int(struct nk_context*, int min, int val, int max, int step);
644 NK_API int                      nk_slider_float(struct nk_context*, float min, float *val, float max, float step);
645 NK_API int                      nk_slider_int(struct nk_context*, int min, int *val, int max, int step);
646  
647 /* Widgets: Progressbar */
648 NK_API int                      nk_progress(struct nk_context*, nk_size *cur, nk_size max, int modifyable);
649 NK_API nk_size                  nk_prog(struct nk_context*, nk_size cur, nk_size max, int modifyable);
650  
651 /* Widgets: Color picker */
652 NK_API struct nk_color          nk_color_picker(struct nk_context*, struct nk_color, enum nk_color_format);
653 NK_API int                      nk_color_pick(struct nk_context*, struct nk_color*, enum nk_color_format);
654  
655 /* Widgets: Property */
656 NK_API void                     nk_property_float(struct nk_context *layout, const char *name, float min, float *val, float max, float step, float inc_per_pixel);
657 NK_API void                     nk_property_int(struct nk_context *layout, const char *name, int min, int *val, int max, int step, int inc_per_pixel);
658 NK_API float                    nk_propertyf(struct nk_context *layout, const char *name, float min, float val, float max, float step, float inc_per_pixel);
659 NK_API int                      nk_propertyi(struct nk_context *layout, const char *name, int min, int val, int max, int step, int inc_per_pixel);
660  
661 /* Widgets: TextEdit */
662 NK_API nk_flags                 nk_edit_string(struct nk_context*, nk_flags, char *buffer, int *len, int max, nk_filter);
663 NK_API nk_flags                 nk_edit_buffer(struct nk_context*, nk_flags, struct nk_text_edit*, nk_filter);
664  
665 /* Chart */
666 NK_API int                      nk_chart_begin(struct nk_context*, enum nk_chart_type, int num, float min, float max);
667 NK_API nk_flags                 nk_chart_push(struct nk_context*, float);
668 NK_API void                     nk_chart_end(struct nk_context*);
669 NK_API void                     nk_plot(struct nk_context*, enum nk_chart_type, const float *values, int count, int offset);
670 NK_API void                     nk_plot_function(struct nk_context*, enum nk_chart_type, void *userdata, float(*value_getter)(void* user, int index), int count, int offset);
671  
672 /* Popups */
673 NK_API int                      nk_popup_begin(struct nk_context*, struct nk_panel*, enum nk_popup_type, const char*, nk_flags, struct nk_rect bounds);
674 NK_API void                     nk_popup_close(struct nk_context*);
675 NK_API void                     nk_popup_end(struct nk_context*);
676  
677 /* Combobox */
678 NK_API int                      nk_combo(struct nk_context*, const char **items, int count, int selected, int item_height);
679 NK_API int                      nk_combo_separator(struct nk_context*, const char *items_separated_by_separator, int separator, int selected, int count, int item_height);
680 NK_API int                      nk_combo_string(struct nk_context*, const char *items_separated_by_zeros, int selected, int count, int item_height);
681 NK_API int                      nk_combo_callback(struct nk_context*, void(*item_getter)(void*, int, const char**), void *userdata, int selected, int count, int item_height);
682 NK_API void                     nk_combobox(struct nk_context*, const char **items, int count, int *selected, int item_height);
683 NK_API void                     nk_combobox_string(struct nk_context*, const char *items_separated_by_zeros, int *selected, int count, int item_height);
684 NK_API void                     nk_combobox_separator(struct nk_context*, const char *items_separated_by_separator, int separator,int *selected, int count, int item_height);
685 NK_API void                     nk_combobox_callback(struct nk_context*, void(*item_getter)(void*, int, const char**), void*, int *selected, int count, int item_height);
686  
687 /* Combobox: abstract */
688 NK_API int                      nk_combo_begin_text(struct nk_context*, struct nk_panel*, const char *selected, int, int max_height);
689 NK_API int                      nk_combo_begin_label(struct nk_context*, struct nk_panel*, const char *selected, int max_height);
690 NK_API int                      nk_combo_begin_color(struct nk_context*, struct nk_panel*, struct nk_color color, int max_height);
691 NK_API int                      nk_combo_begin_symbol(struct nk_context*, struct nk_panel*, enum nk_symbol_type,  int max_height);
692 NK_API int                      nk_combo_begin_symbol_label(struct nk_context*, struct nk_panel*, const char *selected, enum nk_symbol_type, int height);
693 NK_API int                      nk_combo_begin_symbol_text(struct nk_context*, struct nk_panel*, const char *selected, int, enum nk_symbol_type, int height);
694 NK_API int                      nk_combo_begin_image(struct nk_context*, struct nk_panel*, struct nk_image img,  int max_height);
695 NK_API int                      nk_combo_begin_image_label(struct nk_context*, struct nk_panel*, const char *selected, struct nk_image, int height);
696 NK_API int                      nk_combo_begin_image_text(struct nk_context*, struct nk_panel*, const char *selected, int, struct nk_image, int height);
697 NK_API int                      nk_combo_item_label(struct nk_context*, const char*, nk_flags alignment);
698 NK_API int                      nk_combo_item_text(struct nk_context*, const char*,int, nk_flags alignment);
699 NK_API int                      nk_combo_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment);
700 NK_API int                      nk_combo_item_image_text(struct nk_context*, struct nk_image, const char*, int,nk_flags alignment);
701 NK_API int                      nk_combo_item_symbol_label(struct nk_context*, enum nk_symbol_type, const char*, nk_flags alignment);
702 NK_API int                      nk_combo_item_symbol_text(struct nk_context*, enum nk_symbol_type, const char*, int, nk_flags alignment);
703 NK_API void                     nk_combo_close(struct nk_context*);
704 NK_API void                     nk_combo_end(struct nk_context*);
705  
706 /* Contextual */
707 NK_API int                      nk_contextual_begin(struct nk_context*, struct nk_panel*, nk_flags, struct nk_vec2, struct nk_rect trigger_bounds);
708 NK_API int                      nk_contextual_item_text(struct nk_context*, const char*, int,nk_flags align);
709 NK_API int                      nk_contextual_item_label(struct nk_context*, const char*, nk_flags align);
710 NK_API int                      nk_contextual_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment);
711 NK_API int                      nk_contextual_item_image_text(struct nk_context*, struct nk_image, const char*, int len, nk_flags alignment);
712 NK_API int                      nk_contextual_item_symbol_label(struct nk_context*, enum nk_symbol_type, const char*, nk_flags alignment);
713 NK_API int                      nk_contextual_item_symbol_text(struct nk_context*, enum nk_symbol_type, const char*, int, nk_flags alignment);
714 NK_API void                     nk_contextual_close(struct nk_context*);
715 NK_API void                     nk_contextual_end(struct nk_context*);
716  
717 /* Tooltip */
718 NK_API void                     nk_tooltip(struct nk_context*, const char*);
719 NK_API int                      nk_tooltip_begin(struct nk_context*, struct nk_panel*, float width);
720 NK_API void                     nk_tooltip_end(struct nk_context*);
721  
722 /* Menu */
723 NK_API void                     nk_menubar_begin(struct nk_context*);
724 NK_API void                     nk_menubar_end(struct nk_context*);
725 NK_API int                      nk_menu_begin_text(struct nk_context*, struct nk_panel*, const char*, int, nk_flags align, float width);
726 NK_API int                      nk_menu_begin_label(struct nk_context*, struct nk_panel*, const char*, nk_flags align, float width);
727 NK_API int                      nk_menu_begin_image(struct nk_context*, struct nk_panel*, const char*, struct nk_image, float width);
728 NK_API int                      nk_menu_begin_image_text(struct nk_context*, struct nk_panel*, const char*, int,nk_flags align,struct nk_image, float width);
729 NK_API int                      nk_menu_begin_image_label(struct nk_context*, struct nk_panel*, const char*, nk_flags align,struct nk_image, float width);
730 NK_API int                      nk_menu_begin_symbol(struct nk_context*, struct nk_panel*, const char*, enum nk_symbol_type, float width);
731 NK_API int                      nk_menu_begin_symbol_text(struct nk_context*, struct nk_panel*, const char*, int,nk_flags align,enum nk_symbol_type, float width);
732 NK_API int                      nk_menu_begin_symbol_label(struct nk_context*, struct nk_panel*, const char*, nk_flags align,enum nk_symbol_type, float width);
733 NK_API int                      nk_menu_item_text(struct nk_context*, const char*, int,nk_flags align);
734 NK_API int                      nk_menu_item_label(struct nk_context*, const char*, nk_flags alignment);
735 NK_API int                      nk_menu_item_image_label(struct nk_context*, struct nk_image, const char*, nk_flags alignment);
736 NK_API int                      nk_menu_item_image_text(struct nk_context*, struct nk_image, const char*, int len, nk_flags alignment);
737 NK_API int                      nk_menu_item_symbol_text(struct nk_context*, enum nk_symbol_type, const char*, int, nk_flags alignment);
738 NK_API int                      nk_menu_item_symbol_label(struct nk_context*, enum nk_symbol_type, const char*, nk_flags alignment);
739 NK_API void                     nk_menu_close(struct nk_context*);
740 NK_API void                     nk_menu_end(struct nk_context*);
741  
742 /* Drawing*/
743 #define                         nk_foreach(c, ctx)for((c)=nk__begin(ctx); (c)!=0; (c)=nk__next(ctx, c))
744 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
745 NK_API void                     nk_convert(struct nk_context*, struct nk_buffer *cmds, struct nk_buffer *vertices, struct nk_buffer *elements, const struct nk_convert_config*);
746 #define                         nk_draw_foreach(cmd,ctx, b) for((cmd)=nk__draw_begin(ctx, b); (cmd)!=0; (cmd)=nk__draw_next(cmd, b, ctx))
747 #endif
748  
749 /* User Input */
750 NK_API void                     nk_input_begin(struct nk_context*);
751 NK_API void                     nk_input_motion(struct nk_context*, int x, int y);
752 NK_API void                     nk_input_key(struct nk_context*, enum nk_keys, int down);
753 NK_API void                     nk_input_button(struct nk_context*, enum nk_buttons, int x, int y, int down);
754 NK_API void                     nk_input_scroll(struct nk_context*, float y);
755 NK_API void                     nk_input_char(struct nk_context*, char);
756 NK_API void                     nk_input_glyph(struct nk_context*, const nk_glyph);
757 NK_API void                     nk_input_unicode(struct nk_context*, nk_rune);
758 NK_API void                     nk_input_end(struct nk_context*);
759  
760 /* Style */
761 NK_API void                     nk_style_default(struct nk_context*);
762 NK_API void                     nk_style_from_table(struct nk_context*, const struct nk_color*);
763 NK_API const char*              nk_style_color_name(enum nk_style_colors);
764 NK_API void                     nk_style_set_font(struct nk_context*, const struct nk_user_font*);
765  
766 /* Utilities */
767 NK_API struct nk_rect           nk_widget_bounds(struct nk_context*);
768 NK_API struct nk_vec2           nk_widget_position(struct nk_context*);
769 NK_API struct nk_vec2           nk_widget_size(struct nk_context*);
770 NK_API int                      nk_widget_is_hovered(struct nk_context*);
771 NK_API int                      nk_widget_is_mouse_clicked(struct nk_context*, enum nk_buttons);
772 NK_API int                      nk_widget_has_mouse_click_down(struct nk_context*, enum nk_buttons, int down);
773 NK_API void                     nk_spacing(struct nk_context*, int cols);
774  
775 /* base widget function  */
776 NK_API enum nk_widget_layout_states nk_widget(struct nk_rect*, const struct nk_context*);
777 NK_API enum nk_widget_layout_states nk_widget_fitting(struct nk_rect*, struct nk_context*, struct nk_vec2);
778  
779 /* color (conversion user --> nuklear) */
780 NK_API struct nk_color          nk_rgb(int r, int g, int b);
781 NK_API struct nk_color          nk_rgb_iv(const int *rgb);
782 NK_API struct nk_color          nk_rgb_bv(const nk_byte* rgb);
783 NK_API struct nk_color          nk_rgb_f(float r, float g, float b);
784 NK_API struct nk_color          nk_rgb_fv(const float *rgb);
785 NK_API struct nk_color          nk_rgb_hex(const char *rgb);
786  
787 NK_API struct nk_color          nk_rgba(int r, int g, int b, int a);
788 NK_API struct nk_color          nk_rgba_u32(nk_uint);
789 NK_API struct nk_color          nk_rgba_iv(const int *rgba);
790 NK_API struct nk_color          nk_rgba_bv(const nk_byte *rgba);
791 NK_API struct nk_color          nk_rgba_f(float r, float g, float b, float a);
792 NK_API struct nk_color          nk_rgba_fv(const float *rgba);
793 NK_API struct nk_color          nk_rgba_hex(const char *rgb);
794  
795 NK_API struct nk_color          nk_hsv(int h, int s, int v);
796 NK_API struct nk_color          nk_hsv_iv(const int *hsv);
797 NK_API struct nk_color          nk_hsv_bv(const nk_byte *hsv);
798 NK_API struct nk_color          nk_hsv_f(float h, float s, float v);
799 NK_API struct nk_color          nk_hsv_fv(const float *hsv);
800  
801 NK_API struct nk_color          nk_hsva(int h, int s, int v, int a);
802 NK_API struct nk_color          nk_hsva_iv(const int *hsva);
803 NK_API struct nk_color          nk_hsva_bv(const nk_byte *hsva);
804 NK_API struct nk_color          nk_hsva_f(float h, float s, float v, float a);
805 NK_API struct nk_color          nk_hsva_fv(const float *hsva);
806  
807 /* color (conversion nuklear --> user) */
808 NK_API void                     nk_color_f(float *r, float *g, float *b, float *a, struct nk_color);
809 NK_API void                     nk_color_fv(float *rgba_out, struct nk_color);
810 NK_API nk_uint                  nk_color_u32(struct nk_color);
811 NK_API void                     nk_color_hex_rgba(char *output, struct nk_color);
812 NK_API void                     nk_color_hex_rgb(char *output, struct nk_color);
813  
814 NK_API void                     nk_color_hsv_i(int *out_h, int *out_s, int *out_v, struct nk_color);
815 NK_API void                     nk_color_hsv_b(nk_byte *out_h, nk_byte *out_s, nk_byte *out_v, struct nk_color);
816 NK_API void                     nk_color_hsv_iv(int *hsv_out, struct nk_color);
817 NK_API void                     nk_color_hsv_bv(nk_byte *hsv_out, struct nk_color);
818 NK_API void                     nk_color_hsv_f(float *out_h, float *out_s, float *out_v, struct nk_color);
819 NK_API void                     nk_color_hsv_fv(float *hsv_out, struct nk_color);
820  
821 NK_API void                     nk_color_hsva_i(int *h, int *s, int *v, int *a, struct nk_color);
822 NK_API void                     nk_color_hsva_b(nk_byte *h, nk_byte *s, nk_byte *v, nk_byte *a, struct nk_color);
823 NK_API void                     nk_color_hsva_iv(int *hsva_out, struct nk_color);
824 NK_API void                     nk_color_hsva_bv(nk_byte *hsva_out, struct nk_color);
825 NK_API void                     nk_color_hsva_f(float *out_h, float *out_s, float *out_v, float *out_a, struct nk_color);
826 NK_API void                     nk_color_hsva_fv(float *hsva_out, struct nk_color);
827  
828 /* image */
829 NK_API nk_handle                nk_handle_ptr(void*);
830 NK_API nk_handle                nk_handle_id(int);
831 NK_API struct nk_image          nk_image_ptr(void*);
832 NK_API struct nk_image          nk_image_id(int);
833 NK_API int                      nk_image_is_subimage(const struct nk_image* img);
834 NK_API struct nk_image          nk_subimage_ptr(void*, unsigned short w, unsigned short h, struct nk_rect sub_region);
835 NK_API struct nk_image          nk_subimage_id(int, unsigned short w, unsigned short h, struct nk_rect sub_region);
836  
837 /* math */
838 NK_API nk_hash                  nk_murmur_hash(const void *key, int len, nk_hash seed);
839 NK_API void                     nk_triangle_from_direction(struct nk_vec2 *result, struct nk_rect r, float pad_x, float pad_y, enum nk_heading);
840  
841 NK_API struct nk_vec2           nk_vec2(float x, float y);
842 NK_API struct nk_vec2           nk_vec2i(int x, int y);
843 NK_API struct nk_vec2           nk_vec2v(const float *xy);
844 NK_API struct nk_vec2           nk_vec2iv(const int *xy);
845  
846 NK_API struct nk_rect           nk_get_null_rect(void);
847 NK_API struct nk_rect           nk_rect(float x, float y, float w, float h);
848 NK_API struct nk_rect           nk_recti(int x, int y, int w, int h);
849 NK_API struct nk_rect           nk_recta(struct nk_vec2 pos, struct nk_vec2 size);
850 NK_API struct nk_rect           nk_rectv(const float *xywh);
851 NK_API struct nk_rect           nk_rectiv(const int *xywh);
852  
853 /* string*/
854 NK_API int                      nk_strlen(const char *str);
855 NK_API int                      nk_stricmp(const char *s1, const char *s2);
856 NK_API int                      nk_stricmpn(const char *s1, const char *s2, int n);
857 NK_API int                      nk_strtof(float *number, const char *buffer);
858 NK_API int                      nk_strfilter(const char *text, const char *regexp);
859 NK_API int                      nk_strmatch_fuzzy_string(char const *str, char const *pattern, int *out_score);
860 NK_API int                      nk_strmatch_fuzzy_text(const char *txt, int txt_len, const char *pattern, int *out_score);
861 #ifdef NK_INCLUDE_STANDARD_IO
862 NK_API int                      nk_strfmt(char *buf, int len, const char *fmt,...);
863 #endif
864  
865 /* UTF-8 */
866 NK_API int                      nk_utf_decode(const char*, nk_rune*, int);
867 NK_API int                      nk_utf_encode(nk_rune, char*, int);
868 NK_API int                      nk_utf_len(const char*, int byte_len);
869 NK_API const char*              nk_utf_at(const char *buffer, int length, int index, nk_rune *unicode, int *len);
870  
871 /* ==============================================================
872  *
873  *                          MEMORY BUFFER
874  *
875  * ===============================================================*/
876 /*  A basic (double)-buffer with linear allocation and resetting as only
877     freeing policy. The buffers main purpose is to control all memory management
878     inside the GUI toolkit and still leave memory control as much as possible in
879     the hand of the user while also making sure the library is easy to use if
880     not as much control is needed.
881     In general all memory inside this library can be provided from the user in
882     three different ways.
883  
884     The first way and the one providing most control is by just passing a fixed
885     size memory block. In this case all control lies in the hand of the user
886     since he can exactly control where the memory comes from and how much memory
887     the library should consume. Of course using the fixed size API removes the
888     ability to automatically resize a buffer if not enough memory is provided so
889     you have to take over the resizing. While being a fixed sized buffer sounds
890     quite limiting, it is very effective in this library since the actual memory
891     consumption is quite stable and has a fixed upper bound for a lot of cases.
892  
893     If you don't want to think about how much memory the library should allocate
894     at all time or have a very dynamic UI with unpredictable memory consumption
895     habits but still want control over memory allocation you can use the dynamic
896     allocator based API. The allocator consists of two callbacks for allocating
897     and freeing memory and optional userdata so you can plugin your own allocator.
898  
899     The final and easiest way can be used by defining
900     NK_INCLUDE_DEFAULT_ALLOCATOR which uses the standard library memory
901     allocation functions malloc and free and takes over complete control over
902     memory in this library.
903 */
904 struct nk_memory_status {
905     void *memory;
906     unsigned int type;
907     nk_size size;
908     nk_size allocated;
909     nk_size needed;
910     nk_size calls;
911 };
912  
913 enum nk_allocation_type {
914     NK_BUFFER_FIXED,
915     NK_BUFFER_DYNAMIC
916 };
917  
918 enum nk_buffer_allocation_type {
919     NK_BUFFER_FRONT,
920     NK_BUFFER_BACK,
921     NK_BUFFER_MAX
922 };
923  
924 struct nk_buffer_marker {
925     int active;
926     nk_size offset;
927 };
928  
929 struct nk_memory {void *ptr;nk_size size;};
930 struct nk_buffer {
931     struct nk_buffer_marker marker[NK_BUFFER_MAX];
932     /* buffer marker to free a buffer to a certain offset */
933     struct nk_allocator pool;
934     /* allocator callback for dynamic buffers */
935     enum nk_allocation_type type;
936     /* memory management type */
937     struct nk_memory memory;
938     /* memory and size of the current memory block */
939     float grow_factor;
940     /* growing factor for dynamic memory management */
941     nk_size allocated;
942     /* total amount of memory allocated */
943     nk_size needed;
944     /* totally consumed memory given that enough memory is present */
945     nk_size calls;
946     /* number of allocation calls */
947     nk_size size;
948     /* current size of the buffer */
949 };
950  
951 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
952 NK_API void nk_buffer_init_default(struct nk_buffer*);
953 #endif
954 NK_API void nk_buffer_init(struct nk_buffer*, const struct nk_allocator*, nk_size size);
955 NK_API void nk_buffer_init_fixed(struct nk_buffer*, void *memory, nk_size size);
956 NK_API void nk_buffer_info(struct nk_memory_status*, struct nk_buffer*);
957 NK_API void nk_buffer_push(struct nk_buffer*, enum nk_buffer_allocation_type type,
958                             void *memory, nk_size size, nk_size align);
959 NK_API void nk_buffer_mark(struct nk_buffer*, enum nk_buffer_allocation_type type);
960 NK_API void nk_buffer_reset(struct nk_buffer*, enum nk_buffer_allocation_type type);
961 NK_API void nk_buffer_clear(struct nk_buffer*);
962 NK_API void nk_buffer_free(struct nk_buffer*);
963 NK_API void *nk_buffer_memory(struct nk_buffer*);
964 NK_API const void *nk_buffer_memory_const(const struct nk_buffer*);
965 NK_API nk_size nk_buffer_total(struct nk_buffer*);
966  
967 /* ==============================================================
968  *
969  *                          STRING
970  *
971  * ===============================================================*/
972 /*  Basic string buffer which is only used in context with the text editor
973  *  to manage and manipulate dynamic or fixed size string content. This is _NOT_
974  *  the default string handling method.*/
975 struct nk_str {
976     struct nk_buffer buffer;
977     int len; /* in codepoints/runes/glyphs */
978 };
979  
980 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
981 NK_API void nk_str_init_default(struct nk_str*);
982 #endif
983 NK_API void nk_str_init(struct nk_str*, const struct nk_allocator*, nk_size size);
984 NK_API void nk_str_init_fixed(struct nk_str*, void *memory, nk_size size);
985 NK_API void nk_str_clear(struct nk_str*);
986 NK_API void nk_str_free(struct nk_str*);
987  
988 NK_API int nk_str_append_text_char(struct nk_str*, const char*, int);
989 NK_API int nk_str_append_str_char(struct nk_str*, const char*);
990 NK_API int nk_str_append_text_utf8(struct nk_str*, const char*, int);
991 NK_API int nk_str_append_str_utf8(struct nk_str*, const char*);
992 NK_API int nk_str_append_text_runes(struct nk_str*, const nk_rune*, int);
993 NK_API int nk_str_append_str_runes(struct nk_str*, const nk_rune*);
994  
995 NK_API int nk_str_insert_at_char(struct nk_str*, int pos, const char*, int);
996 NK_API int nk_str_insert_at_rune(struct nk_str*, int pos, const char*, int);
997  
998 NK_API int nk_str_insert_text_char(struct nk_str*, int pos, const char*, int);
999 NK_API int nk_str_insert_str_char(struct nk_str*, int pos, const char*);
1000 NK_API int nk_str_insert_text_utf8(struct nk_str*, int pos, const char*, int);
1001 NK_API int nk_str_insert_str_utf8(struct nk_str*, int pos, const char*);
1002 NK_API int nk_str_insert_text_runes(struct nk_str*, int pos, const nk_rune*, int);
1003 NK_API int nk_str_insert_str_runes(struct nk_str*, int pos, const nk_rune*);
1004  
1005 NK_API void nk_str_remove_chars(struct nk_str*, int len);
1006 NK_API void nk_str_remove_runes(struct nk_str *str, int len);
1007 NK_API void nk_str_delete_chars(struct nk_str*, int pos, int len);
1008 NK_API void nk_str_delete_runes(struct nk_str*, int pos, int len);
1009  
1010 NK_API char *nk_str_at_char(struct nk_str*, int pos);
1011 NK_API char *nk_str_at_rune(struct nk_str*, int pos, nk_rune *unicode, int *len);
1012 NK_API nk_rune nk_str_rune_at(const struct nk_str*, int pos);
1013 NK_API const char *nk_str_at_char_const(const struct nk_str*, int pos);
1014 NK_API const char *nk_str_at_const(const struct nk_str*, int pos, nk_rune *unicode, int *len);
1015  
1016 NK_API char *nk_str_get(struct nk_str*);
1017 NK_API const char *nk_str_get_const(const struct nk_str*);
1018 NK_API int nk_str_len(struct nk_str*);
1019 NK_API int nk_str_len_char(struct nk_str*);
1020  
1021 /*===============================================================
1022  *
1023  *                      TEXT EDITOR
1024  *
1025  * ===============================================================*/
1026 /* Editing text in this library is handled by either `nk_edit_string` or
1027  * `nk_edit_buffer`. But like almost everything in this library there are multiple
1028  * ways of doing it and a balance between control and ease of use with memory
1029  * as well as functionality controlled by flags.
1030  *
1031  * This library generally allows three different levels of memory control:
1032  * First of is the most basic way of just providing a simple char array with
1033  * string length. This method is probably the easiest way of handling simple
1034  * user text input. Main upside is complete control over memory while the biggest
1035  * downside in comparsion with the other two approaches is missing undo/redo.
1036  *
1037  * For UIs that require undo/redo the second way was created. It is based on
1038  * a fixed size nk_text_edit struct, which has an internal undo/redo stack.
1039  * This is mainly useful if you want something more like a text editor but don't want
1040  * to have a dynamically growing buffer.
1041  *
1042  * The final ways is using a dynamically growing nk_text_edit struct, which
1043  * has both a default version if you don't care were memory comes from and a
1044  * allocator version if you do. While the text editor is quite powerful for its
1045  * complexity I would not recommend editing gigabytes of data with it.
1046  * It is rather designed for uses cases which make sense for a GUI library not for
1047  * an full blown text editor.
1048  */
1049 #ifndef NK_TEXTEDIT_UNDOSTATECOUNT
1050 #define NK_TEXTEDIT_UNDOSTATECOUNT     99
1051 #endif
1052  
1053 #ifndef NK_TEXTEDIT_UNDOCHARCOUNT
1054 #define NK_TEXTEDIT_UNDOCHARCOUNT      999
1055 #endif
1056  
1057 struct nk_text_edit;
1058 struct nk_clipboard {
1059     nk_handle userdata;
1060     nk_paste_f paste;
1061     nk_copy_f copy;
1062 };
1063  
1064 struct nk_text_undo_record {
1065    int where;
1066    short insert_length;
1067    short delete_length;
1068    short char_storage;
1069 };
1070  
1071 struct nk_text_undo_state {
1072    struct nk_text_undo_record undo_rec[NK_TEXTEDIT_UNDOSTATECOUNT];
1073    nk_rune undo_char[NK_TEXTEDIT_UNDOCHARCOUNT];
1074    short undo_point;
1075    short redo_point;
1076    short undo_char_point;
1077    short redo_char_point;
1078 };
1079  
1080 enum nk_text_edit_type {
1081     NK_TEXT_EDIT_SINGLE_LINE,
1082     NK_TEXT_EDIT_MULTI_LINE
1083 };
1084  
1085 struct nk_text_edit {
1086     struct nk_clipboard clip;
1087     struct nk_str string;
1088     nk_filter filter;
1089     struct nk_vec2 scrollbar;
1090  
1091     int cursor;
1092     int select_start;
1093     int select_end;
1094     unsigned char insert_mode;
1095     unsigned char cursor_at_end_of_line;
1096     unsigned char initialized;
1097     unsigned char has_preferred_x;
1098     unsigned char single_line;
1099     unsigned char active;
1100     unsigned char padding1;
1101     float preferred_x;
1102     struct nk_text_undo_state undo;
1103 };
1104  
1105 /* filter function */
1106 NK_API int nk_filter_default(const struct nk_text_edit*, nk_rune unicode);
1107 NK_API int nk_filter_ascii(const struct nk_text_edit*, nk_rune unicode);
1108 NK_API int nk_filter_float(const struct nk_text_edit*, nk_rune unicode);
1109 NK_API int nk_filter_decimal(const struct nk_text_edit*, nk_rune unicode);
1110 NK_API int nk_filter_hex(const struct nk_text_edit*, nk_rune unicode);
1111 NK_API int nk_filter_oct(const struct nk_text_edit*, nk_rune unicode);
1112 NK_API int nk_filter_binary(const struct nk_text_edit*, nk_rune unicode);
1113  
1114 /* text editor */
1115 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
1116 NK_API void nk_textedit_init_default(struct nk_text_edit*);
1117 #endif
1118 NK_API void nk_textedit_init(struct nk_text_edit*, struct nk_allocator*, nk_size size);
1119 NK_API void nk_textedit_init_fixed(struct nk_text_edit*, void *memory, nk_size size);
1120 NK_API void nk_textedit_free(struct nk_text_edit*);
1121 NK_API void nk_textedit_text(struct nk_text_edit*, const char*, int total_len);
1122 NK_API void nk_textedit_delete(struct nk_text_edit*, int where, int len);
1123 NK_API void nk_textedit_delete_selection(struct nk_text_edit*);
1124 NK_API void nk_textedit_select_all(struct nk_text_edit*);
1125 NK_API int nk_textedit_cut(struct nk_text_edit*);
1126 NK_API int nk_textedit_paste(struct nk_text_edit*, char const*, int len);
1127 NK_API void nk_textedit_undo(struct nk_text_edit*);
1128 NK_API void nk_textedit_redo(struct nk_text_edit*);
1129  
1130 /* ===============================================================
1131  *
1132  *                          FONT
1133  *
1134  * ===============================================================*/
1135 /*  Font handling in this library was designed to be quite customizable and lets
1136     you decide what you want to use and what you want to provide. In this sense
1137     there are four different degrees between control and ease of use and two
1138     different drawing APIs to provide for.
1139  
1140     So first of the easiest way to do font handling is by just providing a
1141     `nk_user_font` struct which only requires the height in pixel of the used
1142     font and a callback to calculate the width of a string. This way of handling
1143     fonts is best fitted for using the normal draw shape command API were you
1144     do all the text drawing yourself and the library does not require any kind
1145     of deeper knowledge about which font handling mechanism you use.
1146  
1147     While the first approach works fine if you don't want to use the optional
1148     vertex buffer output it is not enough if you do. To get font handling working
1149     for these cases you have to provide two additional parameter inside the
1150     `nk_user_font`. First a texture atlas handle used to draw text as subimages
1151     of a bigger font atlas texture and a callback to query a characters glyph
1152     information (offset, size, ...). So it is still possible to provide your own
1153     font and use the vertex buffer output.
1154  
1155     The final approach if you do not have a font handling functionality or don't
1156     want to use it in this library is by using the optional font baker. This API
1157     is divided into a high- and low-level API with different priorities between
1158     ease of use and control. Both API's can be used to create a font and
1159     font atlas texture and can even be used with or without the vertex buffer
1160     output. So it still uses the `nk_user_font` struct and the two different
1161     approaches previously stated still work.
1162     Now to the difference between the low level API and the high level API. The low
1163     level API provides a lot of control over the baking process of the font and
1164     provides total control over memory. It consists of a number of functions that
1165     need to be called from begin to end and each step requires some additional
1166     configuration, so it is a lot more complex than the high-level API.
1167     If you don't want to do all the work required for using the low-level API
1168     you can use the font atlas API. It provides the same functionality as the
1169     low-level API but takes away some configuration and all of memory control and
1170     in term provides a easier to use API.
1171 */
1172 struct nk_user_font_glyph;
1173 typedef float(*nk_text_width_f)(nk_handle, float h, const char*, int len);
1174 typedef void(*nk_query_font_glyph_f)(nk_handle handle, float font_height,
1175                                     struct nk_user_font_glyph *glyph,
1176                                     nk_rune codepoint, nk_rune next_codepoint);
1177  
1178 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
1179 struct nk_user_font_glyph {
1180     struct nk_vec2 uv[2];
1181     /* texture coordinates */
1182     struct nk_vec2 offset;
1183     /* offset between top left and glyph */
1184     float width, height;
1185     /* size of the glyph  */
1186     float xadvance;
1187     /* offset to the next glyph */
1188 };
1189 #endif
1190  
1191 struct nk_user_font {
1192     nk_handle userdata;
1193     /* user provided font handle */
1194     float height;
1195     /* max height of the font */
1196     nk_text_width_f width;
1197     /* font string width in pixel callback */
1198 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
1199     nk_query_font_glyph_f query;
1200     /* font glyph callback to query drawing info */
1201     nk_handle texture;
1202     /* texture handle to the used font atlas or texture */
1203 #endif
1204 };
1205  
1206 #ifdef NK_INCLUDE_FONT_BAKING
1207 enum nk_font_coord_type {
1208     NK_COORD_UV,
1209     /* texture coordinates inside font glyphs are clamped between 0-1 */
1210     NK_COORD_PIXEL
1211     /* texture coordinates inside font glyphs are in absolute pixel */
1212 };
1213  
1214 struct nk_baked_font {
1215     float height;
1216     /* height of the font  */
1217     float ascent, descent;
1218     /* font glyphs ascent and descent  */
1219     nk_rune glyph_offset;
1220     /* glyph array offset inside the font glyph baking output array  */
1221     nk_rune glyph_count;
1222     /* number of glyphs of this font inside the glyph baking array output */
1223     const nk_rune *ranges;
1224     /* font codepoint ranges as pairs of (from/to) and 0 as last element */
1225 };
1226  
1227 struct nk_font_config {
1228     void *ttf_blob;
1229     /* pointer to loaded TTF file memory block.
1230      * NOTE: not needed for nk_font_atlas_add_from_memory and nk_font_atlas_add_from_file. */
1231     nk_size ttf_size;
1232     /* size of the loaded TTF file memory block
1233      * NOTE: not needed for nk_font_atlas_add_from_memory and nk_font_atlas_add_from_file. */
1234  
1235     unsigned char ttf_data_owned_by_atlas;
1236     /* used inside font atlas: default to: 0*/
1237     unsigned char merge_mode;
1238     /* merges this font into the last font */
1239     unsigned char pixel_snap;
1240     /* align very character to pixel boundary (if true set oversample (1,1)) */
1241     unsigned char oversample_v, oversample_h;
1242     /* rasterize at hight quality for sub-pixel position */
1243     unsigned char padding[3];
1244  
1245     float size;
1246     /* baked pixel height of the font */
1247     enum nk_font_coord_type coord_type;
1248     /* texture coordinate format with either pixel or UV coordinates */
1249     struct nk_vec2 spacing;
1250     /* extra pixel spacing between glyphs  */
1251     const nk_rune *range;
1252     /* list of unicode ranges (2 values per range, zero terminated) */
1253     struct nk_baked_font *font;
1254     /* font to setup in the baking process: NOTE: not needed for font atlas */
1255     nk_rune fallback_glyph;
1256     /* fallback glyph to use if a given rune is not found */
1257 };
1258  
1259 struct nk_font_glyph {
1260     nk_rune codepoint;
1261     float xadvance;
1262     float x0, y0, x1, y1, w, h;
1263     float u0, v0, u1, v1;
1264 };
1265  
1266 struct nk_font {
1267     struct nk_user_font handle;
1268     struct nk_baked_font info;
1269     float scale;
1270     struct nk_font_glyph *glyphs;
1271     const struct nk_font_glyph *fallback;
1272     nk_rune fallback_codepoint;
1273     nk_handle texture;
1274     int config;
1275 };
1276  
1277 enum nk_font_atlas_format {
1278     NK_FONT_ATLAS_ALPHA8,
1279     NK_FONT_ATLAS_RGBA32
1280 };
1281  
1282 struct nk_font_atlas {
1283     void *pixel;
1284     int tex_width;
1285     int tex_height;
1286     struct nk_allocator alloc;
1287     struct nk_recti custom;
1288  
1289     int glyph_count;
1290     struct nk_font *default_font;
1291     struct nk_font_glyph *glyphs;
1292     struct nk_font **fonts;
1293     struct nk_font_config *config;
1294     int font_num, font_cap;
1295 };
1296  
1297 /* some language glyph codepoint ranges */
1298 NK_API const nk_rune *nk_font_default_glyph_ranges(void);
1299 NK_API const nk_rune *nk_font_chinese_glyph_ranges(void);
1300 NK_API const nk_rune *nk_font_cyrillic_glyph_ranges(void);
1301 NK_API const nk_rune *nk_font_korean_glyph_ranges(void);
1302  
1303 /* Font Atlas
1304  * ---------------------------------------------------------------
1305  * This is the high level font baking and handling API to generate an image
1306  * out of font glyphs used to draw text onto the screen. This API takes away
1307  * some control over the baking process like fine grained memory control and
1308  * custom baking data but provides additional functionality and easier to
1309  * use and manage data structures and functions. */
1310 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
1311 NK_API void nk_font_atlas_init_default(struct nk_font_atlas*);
1312 #endif
1313 NK_API void nk_font_atlas_init(struct nk_font_atlas*, struct nk_allocator*);
1314  
1315 NK_API void nk_font_atlas_begin(struct nk_font_atlas*);
1316 NK_API struct nk_font_config nk_font_config(float pixel_height);
1317 NK_API struct nk_font *nk_font_atlas_add(struct nk_font_atlas*, const struct nk_font_config*);
1318 #ifdef NK_INCLUDE_DEFAULT_FONT
1319 NK_API struct nk_font* nk_font_atlas_add_default(struct nk_font_atlas*, float height,
1320                                                 const struct nk_font_config*);
1321 #endif
1322 NK_API struct nk_font* nk_font_atlas_add_from_memory(struct nk_font_atlas *atlas,
1323                                                     void *memory, nk_size size, float height,
1324                                                     const struct nk_font_config *config);
1325 #ifdef NK_INCLUDE_STANDARD_IO
1326 NK_API struct nk_font* nk_font_atlas_add_from_file(struct nk_font_atlas *atlas,
1327                                                 const char *file_path, float height,
1328                                                 const struct nk_font_config*);
1329 #endif
1330 NK_API struct nk_font *nk_font_atlas_add_compressed(struct nk_font_atlas*,
1331                                                 void *memory, nk_size size, float height,
1332                                                 const struct nk_font_config*);
1333 NK_API struct nk_font* nk_font_atlas_add_compressed_base85(struct nk_font_atlas*,
1334                                                 const char *data, float height,
1335                                                 const struct nk_font_config *config);
1336 NK_API const void* nk_font_atlas_bake(struct nk_font_atlas*, int *width, int *height,
1337                                 enum nk_font_atlas_format);
1338 NK_API void nk_font_atlas_end(struct nk_font_atlas*, nk_handle tex,
1339                                 struct nk_draw_null_texture*);
1340 NK_API void nk_font_atlas_clear(struct nk_font_atlas*);
1341  
1342 /* Font
1343  * -----------------------------------------------------------------
1344  * The font structure is just a simple container to hold the output of a baking
1345  * process in the low level API. */
1346 NK_API void nk_font_init(struct nk_font*, float pixel_height, nk_rune fallback_codepoint,
1347                     struct nk_font_glyph*, const struct nk_baked_font*,
1348                     nk_handle atlas);
1349 NK_API const struct nk_font_glyph* nk_font_find_glyph(struct nk_font*, nk_rune unicode);
1350  
1351 /* Font baking (needs to be called sequentially top to bottom)
1352  * --------------------------------------------------------------------
1353  * This is a low level API to bake font glyphs into an image and is more
1354  * complex than the atlas API but provides more control over the baking
1355  * process with custom bake data and memory management. */
1356 NK_API void nk_font_bake_memory(nk_size *temporary_memory, int *glyph_count,
1357                             struct nk_font_config*, int count);
1358 NK_API int nk_font_bake_pack(nk_size *img_memory, int *img_width, int *img_height,
1359                             struct nk_recti *custom_space,
1360                             void *temporary_memory, nk_size temporary_size,
1361                             const struct nk_font_config*, int font_count,
1362                             struct nk_allocator *alloc);
1363 NK_API void nk_font_bake(void *image_memory, int image_width, int image_height,
1364                         void *temporary_memory, nk_size temporary_memory_size,
1365                         struct nk_font_glyph*, int glyphs_count,
1366                         const struct nk_font_config*, int font_count);
1367 NK_API void nk_font_bake_custom_data(void *img_memory, int img_width, int img_height,
1368                                 struct nk_recti img_dst, const char *image_data_mask,
1369                                 int tex_width, int tex_height,char white,char black);
1370 NK_API void nk_font_bake_convert(void *out_memory, int image_width, int image_height,
1371                                 const void *in_memory);
1372  
1373 #endif
1374  
1375 /* ===============================================================
1376  *
1377  *                          DRAWING
1378  *
1379  * ===============================================================*/
1380 /*  This library was designed to be render backend agnostic so it does
1381     not draw anything to screen. Instead all drawn shapes, widgets
1382     are made of, are buffered into memory and make up a command queue.
1383     Each frame therefore fills the command buffer with draw commands
1384     that then need to be executed by the user and his own render backend.
1385     After that the command buffer needs to be cleared and a new frame can be
1386     started. It is probably important to note that the command buffer is the main
1387     drawing API and the optional vertex buffer API only takes this format and
1388     converts it into a hardware accessible format.
1389  
1390     Draw commands are divided into filled shapes and shape outlines but only
1391     filled shapes as well as line, curves and scissor are required to be provided.
1392     All other shape drawing commands can be used but are not required. This was
1393     done to allow the maximum number of render backends to be able to use this
1394     library without you having to do additional work.
1395 */
1396 enum nk_command_type {
1397     NK_COMMAND_NOP,
1398     NK_COMMAND_SCISSOR,
1399     NK_COMMAND_LINE,
1400     NK_COMMAND_CURVE,
1401     NK_COMMAND_RECT,
1402     NK_COMMAND_RECT_FILLED,
1403     NK_COMMAND_RECT_MULTI_COLOR,
1404     NK_COMMAND_CIRCLE,
1405     NK_COMMAND_CIRCLE_FILLED,
1406     NK_COMMAND_ARC,
1407     NK_COMMAND_ARC_FILLED,
1408     NK_COMMAND_TRIANGLE,
1409     NK_COMMAND_TRIANGLE_FILLED,
1410     NK_COMMAND_POLYGON,
1411     NK_COMMAND_POLYGON_FILLED,
1412     NK_COMMAND_POLYLINE,
1413     NK_COMMAND_TEXT,
1414     NK_COMMAND_IMAGE
1415 };
1416  
1417 /* command base and header of every command inside the buffer */
1418 struct nk_command {
1419     enum nk_command_type type;
1420     nk_size next;
1421 #ifdef NK_INCLUDE_COMMAND_USERDATA
1422     nk_handle userdata;
1423 #endif
1424 };
1425  
1426 struct nk_command_scissor {
1427     struct nk_command header;
1428     short x, y;
1429     unsigned short w, h;
1430 };
1431  
1432 struct nk_command_line {
1433     struct nk_command header;
1434     unsigned short line_thickness;
1435     struct nk_vec2i begin;
1436     struct nk_vec2i end;
1437     struct nk_color color;
1438 };
1439  
1440 struct nk_command_curve {
1441     struct nk_command header;
1442     unsigned short line_thickness;
1443     struct nk_vec2i begin;
1444     struct nk_vec2i end;
1445     struct nk_vec2i ctrl[2];
1446     struct nk_color color;
1447 };
1448  
1449 struct nk_command_rect {
1450     struct nk_command header;
1451     unsigned short rounding;
1452     unsigned short line_thickness;
1453     short x, y;
1454     unsigned short w, h;
1455     struct nk_color color;
1456 };
1457  
1458 struct nk_command_rect_filled {
1459     struct nk_command header;
1460     unsigned short rounding;
1461     short x, y;
1462     unsigned short w, h;
1463     struct nk_color color;
1464 };
1465  
1466 struct nk_command_rect_multi_color {
1467     struct nk_command header;
1468     short x, y;
1469     unsigned short w, h;
1470     struct nk_color left;
1471     struct nk_color top;
1472     struct nk_color bottom;
1473     struct nk_color right;
1474 };
1475  
1476 struct nk_command_triangle {
1477     struct nk_command header;
1478     unsigned short line_thickness;
1479     struct nk_vec2i a;
1480     struct nk_vec2i b;
1481     struct nk_vec2i c;
1482     struct nk_color color;
1483 };
1484  
1485 struct nk_command_triangle_filled {
1486     struct nk_command header;
1487     struct nk_vec2i a;
1488     struct nk_vec2i b;
1489     struct nk_vec2i c;
1490     struct nk_color color;
1491 };
1492  
1493 struct nk_command_circle {
1494     struct nk_command header;
1495     short x, y;
1496     unsigned short line_thickness;
1497     unsigned short w, h;
1498     struct nk_color color;
1499 };
1500  
1501 struct nk_command_circle_filled {
1502     struct nk_command header;
1503     short x, y;
1504     unsigned short w, h;
1505     struct nk_color color;
1506 };
1507  
1508 struct nk_command_arc {
1509     struct nk_command header;
1510     short cx, cy;
1511     unsigned short r;
1512     unsigned short line_thickness;
1513     float a[2];
1514     struct nk_color color;
1515 };
1516  
1517 struct nk_command_arc_filled {
1518     struct nk_command header;
1519     short cx, cy;
1520     unsigned short r;
1521     float a[2];
1522     struct nk_color color;
1523 };
1524  
1525 struct nk_command_polygon {
1526     struct nk_command header;
1527     struct nk_color color;
1528     unsigned short line_thickness;
1529     unsigned short point_count;
1530     struct nk_vec2i points[1];
1531 };
1532  
1533 struct nk_command_polygon_filled {
1534     struct nk_command header;
1535     struct nk_color color;
1536     unsigned short point_count;
1537     struct nk_vec2i points[1];
1538 };
1539  
1540 struct nk_command_polyline {
1541     struct nk_command header;
1542     struct nk_color color;
1543     unsigned short line_thickness;
1544     unsigned short point_count;
1545     struct nk_vec2i points[1];
1546 };
1547  
1548 struct nk_command_image {
1549     struct nk_command header;
1550     short x, y;
1551     unsigned short w, h;
1552     struct nk_image img;
1553 };
1554  
1555 struct nk_command_text {
1556     struct nk_command header;
1557     const struct nk_user_font *font;
1558     struct nk_color background;
1559     struct nk_color foreground;
1560     short x, y;
1561     unsigned short w, h;
1562     float height;
1563     int length;
1564     char string[1];
1565 };
1566  
1567 enum nk_command_clipping {
1568     NK_CLIPPING_OFF = nk_false,
1569     NK_CLIPPING_ON = nk_true
1570 };
1571  
1572 struct nk_command_buffer {
1573     struct nk_buffer *base;
1574     struct nk_rect clip;
1575     int use_clipping;
1576     nk_handle userdata;
1577     nk_size begin, end, last;
1578 };
1579  
1580 /* shape outlines */
1581 NK_API void nk_stroke_line(struct nk_command_buffer *b, float x0, float y0,
1582                         float x1, float y1, float line_thickness, struct nk_color);
1583 NK_API void nk_stroke_curve(struct nk_command_buffer*, float, float, float, float,
1584                         float, float, float, float, float line_thickness, struct nk_color);
1585 NK_API void nk_stroke_rect(struct nk_command_buffer*, struct nk_rect, float rounding,
1586                         float line_thickness, struct nk_color);
1587 NK_API void nk_stroke_circle(struct nk_command_buffer*, struct nk_rect,
1588                             float line_thickness, struct nk_color);
1589 NK_API void nk_stroke_arc(struct nk_command_buffer*, float cx, float cy, float radius,
1590                         float a_min, float a_max, float line_thickness, struct nk_color);
1591 NK_API void nk_stroke_triangle(struct nk_command_buffer*, float, float,
1592                                 float, float, float, float, float line_thichness,
1593                                 struct nk_color);
1594 NK_API void nk_stroke_polyline(struct nk_command_buffer*, float *points, int point_count,
1595                                 float line_thickness, struct nk_color col);
1596 NK_API void nk_stroke_polygon(struct nk_command_buffer*, float*, int point_count,
1597                                 float line_thickness, struct nk_color);
1598  
1599 /* filled shades */
1600 NK_API void nk_fill_rect(struct nk_command_buffer*, struct nk_rect, float rounding,
1601                         struct nk_color);
1602 NK_API void nk_fill_rect_multi_color(struct nk_command_buffer*, struct nk_rect,
1603                                 struct nk_color left, struct nk_color top,
1604                                 struct nk_color right, struct nk_color bottom);
1605 NK_API void nk_fill_circle(struct nk_command_buffer*, struct nk_rect, struct nk_color);
1606 NK_API void nk_fill_arc(struct nk_command_buffer*, float cx, float cy, float radius,
1607                         float a_min, float a_max, struct nk_color);
1608 NK_API void nk_fill_triangle(struct nk_command_buffer*, float x0, float y0,
1609                             float x1, float y1, float x2, float y2, struct nk_color);
1610 NK_API void nk_fill_polygon(struct nk_command_buffer*, float*, int point_count,
1611                             struct nk_color);
1612 /* misc */
1613 NK_API void nk_push_scissor(struct nk_command_buffer*, struct nk_rect);
1614 NK_API void nk_draw_image(struct nk_command_buffer*, struct nk_rect, const struct nk_image*);
1615 NK_API void nk_draw_text(struct nk_command_buffer*, struct nk_rect,
1616                     const char *text, int len, const struct nk_user_font*,
1617                     struct nk_color, struct nk_color);
1618  
1619 NK_API const struct nk_command* nk__next(struct nk_context*, const struct nk_command*);
1620 NK_API const struct nk_command* nk__begin(struct nk_context*);
1621  
1622 /* ===============================================================
1623  *
1624  *                          INPUT
1625  *
1626  * ===============================================================*/
1627 struct nk_mouse_button {
1628     int down;
1629     unsigned int clicked;
1630     struct nk_vec2 clicked_pos;
1631 };
1632  
1633 struct nk_mouse {
1634     struct nk_mouse_button buttons[NK_BUTTON_MAX];
1635     struct nk_vec2 pos;
1636     struct nk_vec2 prev;
1637     struct nk_vec2 delta;
1638     float scroll_delta;
1639 };
1640  
1641 struct nk_key {
1642     int down;
1643     unsigned int clicked;
1644 };
1645  
1646 struct nk_keyboard {
1647     struct nk_key keys[NK_KEY_MAX];
1648     char text[NK_INPUT_MAX];
1649     int text_len;
1650 };
1651  
1652 struct nk_input {
1653     struct nk_keyboard keyboard;
1654     struct nk_mouse mouse;
1655 };
1656  
1657 NK_API int nk_input_has_mouse_click_in_rect(const struct nk_input*,
1658                                     enum nk_buttons, struct nk_rect);
1659 NK_API int nk_input_has_mouse_click_down_in_rect(const struct nk_input*, enum nk_buttons,
1660                                         struct nk_rect, int down);
1661 NK_API int nk_input_is_mouse_click_in_rect(const struct nk_input*,
1662                                     enum nk_buttons, struct nk_rect);
1663 NK_API int nk_input_is_mouse_click_down_in_rect(const struct nk_input *i, enum nk_buttons id,
1664                                         struct nk_rect b, int down);
1665 NK_API int nk_input_any_mouse_click_in_rect(const struct nk_input*, struct nk_rect);
1666 NK_API int nk_input_is_mouse_prev_hovering_rect(const struct nk_input*, struct nk_rect);
1667 NK_API int nk_input_is_mouse_hovering_rect(const struct nk_input*, struct nk_rect);
1668 NK_API int nk_input_mouse_clicked(const struct nk_input*, enum nk_buttons, struct nk_rect);
1669 NK_API int nk_input_is_mouse_down(const struct nk_input*, enum nk_buttons);
1670 NK_API int nk_input_is_mouse_pressed(const struct nk_input*, enum nk_buttons);
1671 NK_API int nk_input_is_mouse_released(const struct nk_input*, enum nk_buttons);
1672 NK_API int nk_input_is_key_pressed(const struct nk_input*, enum nk_keys);
1673 NK_API int nk_input_is_key_released(const struct nk_input*, enum nk_keys);
1674 NK_API int nk_input_is_key_down(const struct nk_input*, enum nk_keys);
1675  
1676  
1677 /* ===============================================================
1678  *
1679  *                          DRAW LIST
1680  *
1681  * ===============================================================*/
1682 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
1683 /*  The optional vertex buffer draw list provides a 2D drawing context
1684     with antialiasing functionality which takes basic filled or outlined shapes
1685     or a path and outputs vertexes, elements and draw commands.
1686     The actual draw list API is not required to be used directly while using this
1687     library since converting the default library draw command output is done by
1688     just calling `nk_convert` but I decided to still make this library accessible
1689     since it can be useful.
1690  
1691     The draw list is based on a path buffering and polygon and polyline
1692     rendering API which allows a lot of ways to draw 2D content to screen.
1693     In fact it is probably more powerful than needed but allows even more crazy
1694     things than this library provides by default.
1695 */
1696 typedef unsigned short nk_draw_index;
1697 typedef nk_uint nk_draw_vertex_color;
1698  
1699 enum nk_draw_list_stroke {
1700     NK_STROKE_OPEN = nk_false,
1701     /* build up path has no connection back to the beginning */
1702     NK_STROKE_CLOSED = nk_true
1703     /* build up path has a connection back to the beginning */
1704 };
1705  
1706 struct nk_draw_vertex {
1707     struct nk_vec2 position;
1708     struct nk_vec2 uv;
1709     nk_draw_vertex_color col;
1710 };
1711  
1712 struct nk_draw_command {
1713     unsigned int elem_count;
1714     /* number of elements in the current draw batch */
1715     struct nk_rect clip_rect;
1716     /* current screen clipping rectangle */
1717     nk_handle texture;
1718     /* current texture to set */
1719 #ifdef NK_INCLUDE_COMMAND_USERDATA
1720     nk_handle userdata;
1721 #endif
1722 };
1723  
1724 struct nk_draw_list {
1725     float global_alpha;
1726     enum nk_anti_aliasing shape_AA;
1727     enum nk_anti_aliasing line_AA;
1728     struct nk_draw_null_texture null;
1729     struct nk_rect clip_rect;
1730     struct nk_buffer *buffer;
1731     struct nk_buffer *vertices;
1732     struct nk_buffer *elements;
1733     unsigned int element_count;
1734     unsigned int vertex_count;
1735     nk_size cmd_offset;
1736     unsigned int cmd_count;
1737     unsigned int path_count;
1738     unsigned int path_offset;
1739     struct nk_vec2 circle_vtx[12];
1740 #ifdef NK_INCLUDE_COMMAND_USERDATA
1741     nk_handle userdata;
1742 #endif
1743 };
1744  
1745 /* draw list */
1746 NK_API void nk_draw_list_init(struct nk_draw_list*);
1747 NK_API void nk_draw_list_setup(struct nk_draw_list*, float global_alpha,
1748                     enum nk_anti_aliasing line_AA, enum nk_anti_aliasing shape_AA,
1749                     struct nk_draw_null_texture, struct nk_buffer *cmds,
1750                     struct nk_buffer *vertices, struct nk_buffer *elements);
1751 NK_API void nk_draw_list_clear(struct nk_draw_list*);
1752  
1753 /* drawing */
1754 #define nk_draw_list_foreach(cmd, can, b)\
1755     for((cmd)=nk__draw_list_begin(can, b); (cmd)!=0; (cmd)=nk__draw_list_next(cmd, b, can))
1756 NK_API const struct nk_draw_command* nk__draw_list_begin(const struct nk_draw_list*,
1757                                                         const struct nk_buffer*);
1758 NK_API const struct nk_draw_command* nk__draw_list_next(const struct nk_draw_command*,
1759                                                 const struct nk_buffer*,
1760                                                 const struct nk_draw_list*);
1761 NK_API const struct nk_draw_command* nk__draw_begin(const struct nk_context*,
1762                                                     const struct nk_buffer*);
1763 NK_API const struct nk_draw_command* nk__draw_next(const struct nk_draw_command*,
1764                                                     const struct nk_buffer*,
1765                                                     const struct nk_context*);
1766  
1767 /* path */
1768 NK_API void nk_draw_list_path_clear(struct nk_draw_list*);
1769 NK_API void nk_draw_list_path_line_to(struct nk_draw_list *list, struct nk_vec2 pos);
1770 NK_API void nk_draw_list_path_arc_to_fast(struct nk_draw_list*, struct nk_vec2 center,
1771                                 float radius, int a_min, int a_max);
1772 NK_API void nk_draw_list_path_arc_to(struct nk_draw_list*, struct nk_vec2 center,
1773                             float radius, float a_min, float a_max,
1774                             unsigned int segments);
1775 NK_API void nk_draw_list_path_rect_to(struct nk_draw_list*, struct nk_vec2 a,
1776                                 struct nk_vec2 b, float rounding);
1777 NK_API void nk_draw_list_path_curve_to(struct nk_draw_list*, struct nk_vec2 p2,
1778                             struct nk_vec2 p3, struct nk_vec2 p4,
1779                             unsigned int num_segments);
1780 NK_API void nk_draw_list_path_fill(struct nk_draw_list*, struct nk_color);
1781 NK_API void nk_draw_list_path_stroke(struct nk_draw_list*, struct nk_color,
1782                             enum nk_draw_list_stroke closed, float thickness);
1783 /* stroke */
1784 NK_API void nk_draw_list_stroke_line(struct nk_draw_list*, struct nk_vec2 a, struct nk_vec2 b,
1785                             struct nk_color, float thickness);
1786 NK_API void nk_draw_list_stroke_rect(struct nk_draw_list*, struct nk_rect rect, struct nk_color,
1787                             float rounding, float thickness);
1788 NK_API void nk_draw_list_stroke_triangle(struct nk_draw_list*, struct nk_vec2 a, struct nk_vec2 b,
1789                                 struct nk_vec2 c, struct nk_color, float thickness);
1790 NK_API void nk_draw_list_stroke_circle(struct nk_draw_list*, struct nk_vec2 center, float radius,
1791                             struct nk_color, unsigned int segs, float thickness);
1792 NK_API void nk_draw_list_stroke_curve(struct nk_draw_list*, struct nk_vec2 p0, struct nk_vec2 cp0,
1793                             struct nk_vec2 cp1, struct nk_vec2 p1, struct nk_color,
1794                             unsigned int segments, float thickness);
1795 NK_API void nk_draw_list_stroke_poly_line(struct nk_draw_list*, const struct nk_vec2 *points,
1796                                 const unsigned int count, struct nk_color,
1797                                 enum nk_draw_list_stroke closed, float thickness,
1798                                 enum nk_anti_aliasing aliasing);
1799 /* fill */
1800 NK_API void nk_draw_list_fill_rect(struct nk_draw_list*, struct nk_rect rect,
1801                                     struct nk_color, float rounding);
1802 NK_API void nk_draw_list_fill_rect_multi_color(struct nk_draw_list *list,
1803                                             struct nk_rect rect, struct nk_color left,
1804                                             struct nk_color top, struct nk_color right,
1805                                             struct nk_color bottom);
1806 NK_API void nk_draw_list_fill_triangle(struct nk_draw_list*, struct nk_vec2 a,
1807                                     struct nk_vec2 b, struct nk_vec2 c, struct nk_color);
1808 NK_API void nk_draw_list_fill_circle(struct nk_draw_list*, struct nk_vec2 center,
1809                                 float radius, struct nk_color col, unsigned int segs);
1810 NK_API void nk_draw_list_fill_poly_convex(struct nk_draw_list*, const struct nk_vec2 *points,
1811                                         const unsigned int count, struct nk_color,
1812                                         enum nk_anti_aliasing aliasing);
1813 /* misc */
1814 NK_API void nk_draw_list_add_image(struct nk_draw_list*, struct nk_image texture,
1815                             struct nk_rect rect, struct nk_color);
1816 NK_API void nk_draw_list_add_text(struct nk_draw_list*, const struct nk_user_font*,
1817                                 struct nk_rect, const char *text, int len,
1818                                 float font_height, struct nk_color);
1819 #ifdef NK_INCLUDE_COMMAND_USERDATA
1820 NK_API void nk_draw_list_push_userdata(struct nk_draw_list*, nk_handle userdata);
1821 #endif
1822  
1823 #endif
1824  
1825 /* ===============================================================
1826  *
1827  *                          GUI
1828  *
1829  * ===============================================================*/
1830 enum nk_style_item_type {
1831     NK_STYLE_ITEM_COLOR,
1832     NK_STYLE_ITEM_IMAGE
1833 };
1834  
1835 union nk_style_item_data {
1836     struct nk_image image;
1837     struct nk_color color;
1838 };
1839  
1840 struct nk_style_item {
1841     enum nk_style_item_type type;
1842     union nk_style_item_data data;
1843 };
1844  
1845 struct nk_style_text {
1846     struct nk_color color;
1847     struct nk_vec2 padding;
1848 };
1849  
1850 struct nk_style_button;
1851 struct nk_style_custom_button_drawing {
1852     void(*button_text)(struct nk_command_buffer*,
1853         const struct nk_rect *background, const struct nk_rect*,
1854         nk_flags state, const struct nk_style_button*,
1855         const char*, int len, nk_flags text_alignment,
1856         const struct nk_user_font*);
1857     void(*button_symbol)(struct nk_command_buffer*,
1858         const struct nk_rect *background, const struct nk_rect*,
1859         nk_flags state, const struct nk_style_button*,
1860         enum nk_symbol_type, const struct nk_user_font*);
1861     void(*button_image)(struct nk_command_buffer*,
1862         const struct nk_rect *background, const struct nk_rect*,
1863         nk_flags state, const struct nk_style_button*,
1864         const struct nk_image *img);
1865     void(*button_text_symbol)(struct nk_command_buffer*,
1866         const struct nk_rect *background, const struct nk_rect*,
1867         const struct nk_rect *symbol, nk_flags state,
1868         const struct nk_style_button*,
1869         const char *text, int len, enum nk_symbol_type,
1870         const struct nk_user_font*);
1871     void(*button_text_image)(struct nk_command_buffer*,
1872         const struct nk_rect *background, const struct nk_rect*,
1873         const struct nk_rect *image, nk_flags state,
1874         const struct nk_style_button*,
1875         const char *text, int len, const struct nk_user_font*,
1876         const struct nk_image *img);
1877 };
1878  
1879 struct nk_style_button {
1880     /* background */
1881     struct nk_style_item normal;
1882     struct nk_style_item hover;
1883     struct nk_style_item active;
1884     struct nk_color border_color;
1885  
1886     /* text */
1887     struct nk_color text_background;
1888     struct nk_color text_normal;
1889     struct nk_color text_hover;
1890     struct nk_color text_active;
1891     nk_flags text_alignment;
1892  
1893     /* properties */
1894     float border;
1895     float rounding;
1896     struct nk_vec2 padding;
1897     struct nk_vec2 image_padding;
1898     struct nk_vec2 touch_padding;
1899  
1900     /* optional user callbacks */
1901     nk_handle userdata;
1902     void(*draw_begin)(struct nk_command_buffer*, nk_handle userdata);
1903     struct nk_style_custom_button_drawing draw;
1904     void(*draw_end)(struct nk_command_buffer*, nk_handle userdata);
1905 };
1906  
1907 struct nk_style_toggle;
1908 union nk_style_custom_toggle_drawing {
1909     void(*radio)(struct nk_command_buffer*, nk_flags state,
1910         const struct nk_style_toggle *toggle, int active,
1911         const struct nk_rect *label, const struct nk_rect *selector,
1912         const struct nk_rect *cursor, const char *string, int len,
1913         const struct nk_user_font *font);
1914     void(*checkbox)(struct nk_command_buffer*, nk_flags state,
1915         const struct nk_style_toggle *toggle, int active,
1916         const struct nk_rect *label, const struct nk_rect *selector,
1917         const struct nk_rect *cursor, const char *string, int len,
1918         const struct nk_user_font *font);
1919 };
1920  
1921 struct nk_style_toggle {
1922     /* background */
1923     struct nk_style_item normal;
1924     struct nk_style_item hover;
1925     struct nk_style_item active;
1926  
1927     /* cursor */
1928     struct nk_style_item cursor_normal;
1929     struct nk_style_item cursor_hover;
1930  
1931     /* text */
1932     struct nk_color text_normal;
1933     struct nk_color text_hover;
1934     struct nk_color text_active;
1935     struct nk_color text_background;
1936     nk_flags text_alignment;
1937  
1938     /* properties */
1939     struct nk_vec2 padding;
1940     struct nk_vec2 touch_padding;
1941  
1942     /* optional user callbacks */
1943     nk_handle userdata;
1944     void(*draw_begin)(struct nk_command_buffer*, nk_handle);
1945     union nk_style_custom_toggle_drawing draw;
1946     void(*draw_end)(struct nk_command_buffer*, nk_handle);
1947 };
1948  
1949 struct nk_style_selectable {
1950     /* background (inactive) */
1951     struct nk_style_item normal;
1952     struct nk_style_item hover;
1953     struct nk_style_item pressed;
1954  
1955     /* background (active) */
1956     struct nk_style_item normal_active;
1957     struct nk_style_item hover_active;
1958     struct nk_style_item pressed_active;
1959  
1960     /* text color (inactive) */
1961     struct nk_color text_normal;
1962     struct nk_color text_hover;
1963     struct nk_color text_pressed;
1964  
1965     /* text color (active) */
1966     struct nk_color text_normal_active;
1967     struct nk_color text_hover_active;
1968     struct nk_color text_pressed_active;
1969     struct nk_color text_background;
1970     nk_flags text_alignment;
1971  
1972     /* properties */
1973     float rounding;
1974     struct nk_vec2 padding;
1975     struct nk_vec2 touch_padding;
1976  
1977     /* optional user callbacks */
1978     nk_handle userdata;
1979     void(*draw_begin)(struct nk_command_buffer*, nk_handle);
1980     void(*draw)(struct nk_command_buffer*,
1981         nk_flags state, const struct nk_style_selectable*, int active,
1982         const struct nk_rect*, const char *string, int len,
1983         nk_flags align, const struct nk_user_font*);
1984     void(*draw_end)(struct nk_command_buffer*, nk_handle);
1985 };
1986  
1987 struct nk_style_slider {
1988     /* background */
1989     struct nk_style_item normal;
1990     struct nk_style_item hover;
1991     struct nk_style_item active;
1992     struct nk_color border_color;
1993  
1994     /* background bar */
1995     struct nk_color bar_normal;
1996     struct nk_color bar_hover;
1997     struct nk_color bar_active;
1998     struct nk_color bar_filled;
1999  
2000     /* cursor */
2001     struct nk_style_item cursor_normal;
2002     struct nk_style_item cursor_hover;
2003     struct nk_style_item cursor_active;
2004  
2005     /* properties */
2006     float border;
2007     float rounding;
2008     float bar_height;
2009     struct nk_vec2 padding;
2010     struct nk_vec2 spacing;
2011     struct nk_vec2 cursor_size;
2012  
2013     /* optional buttons */
2014     int show_buttons;
2015     struct nk_style_button inc_button;
2016     struct nk_style_button dec_button;
2017     enum nk_symbol_type inc_symbol;
2018     enum nk_symbol_type dec_symbol;
2019  
2020     /* optional user callbacks */
2021     nk_handle userdata;
2022     void(*draw_begin)(struct nk_command_buffer*, nk_handle);
2023     void(*draw)(struct nk_command_buffer*, nk_flags state,
2024         const struct nk_style_slider*, const struct nk_rect *bar,
2025         const struct nk_rect *cursor, float min, float value, float max);
2026     void(*draw_end)(struct nk_command_buffer*, nk_handle);
2027 };
2028  
2029 struct nk_style_progress {
2030     /* background */
2031     struct nk_style_item normal;
2032     struct nk_style_item hover;
2033     struct nk_style_item active;
2034  
2035     /* cursor */
2036     struct nk_style_item cursor_normal;
2037     struct nk_style_item cursor_hover;
2038     struct nk_style_item cursor_active;
2039  
2040     /* properties */
2041     float rounding;
2042     struct nk_vec2 padding;
2043  
2044     /* optional user callbacks */
2045     nk_handle userdata;
2046     void(*draw_begin)(struct nk_command_buffer*, nk_handle);
2047     void(*draw)(struct nk_command_buffer*, nk_flags state,
2048         const struct nk_style_progress*, const struct nk_rect *bounds,
2049         const struct nk_rect *cursor, nk_size value, nk_size max);
2050     void(*draw_end)(struct nk_command_buffer*, nk_handle);
2051 };
2052  
2053 struct nk_style_scrollbar {
2054     /* background */
2055     struct nk_style_item normal;
2056     struct nk_style_item hover;
2057     struct nk_style_item active;
2058     struct nk_color border_color;
2059  
2060     /* cursor */
2061     struct nk_style_item cursor_normal;
2062     struct nk_style_item cursor_hover;
2063     struct nk_style_item cursor_active;
2064  
2065     /* properties */
2066     float border;
2067     float rounding;
2068     struct nk_vec2 padding;
2069  
2070     /* optional buttons */
2071     int show_buttons;
2072     struct nk_style_button inc_button;
2073     struct nk_style_button dec_button;
2074     enum nk_symbol_type inc_symbol;
2075     enum nk_symbol_type dec_symbol;
2076  
2077     /* optional user callbacks */
2078     nk_handle userdata;
2079     void(*draw_begin)(struct nk_command_buffer*, nk_handle);
2080     void(*draw)(struct nk_command_buffer*, nk_flags state,
2081         const struct nk_style_scrollbar*, const struct nk_rect *scroll,
2082         const struct nk_rect *cursor);
2083     void(*draw_end)(struct nk_command_buffer*, nk_handle);
2084 };
2085  
2086 struct nk_style_edit {
2087     /* background */
2088     struct nk_style_item normal;
2089     struct nk_style_item hover;
2090     struct nk_style_item active;
2091     struct nk_color border_color;
2092     struct nk_style_scrollbar scrollbar;
2093  
2094     /* cursor  */
2095     struct nk_color cursor_normal;
2096     struct nk_color cursor_hover;
2097     struct nk_color cursor_text_normal;
2098     struct nk_color cursor_text_hover;
2099  
2100     /* text (unselected) */
2101     struct nk_color text_normal;
2102     struct nk_color text_hover;
2103     struct nk_color text_active;
2104  
2105     /* text (selected) */
2106     struct nk_color selected_normal;
2107     struct nk_color selected_hover;
2108     struct nk_color selected_text_normal;
2109     struct nk_color selected_text_hover;
2110  
2111     /* properties */
2112     float border;
2113     float rounding;
2114     float cursor_size;
2115     struct nk_vec2 scrollbar_size;
2116     struct nk_vec2 padding;
2117     float row_padding;
2118 };
2119  
2120 struct nk_style_property {
2121     /* background */
2122     struct nk_style_item normal;
2123     struct nk_style_item hover;
2124     struct nk_style_item active;
2125     struct nk_color border_color;
2126  
2127     /* text */
2128     struct nk_color label_normal;
2129     struct nk_color label_hover;
2130     struct nk_color label_active;
2131  
2132     /* symbols */
2133     enum nk_symbol_type sym_left;
2134     enum nk_symbol_type sym_right;
2135  
2136     /* properties */
2137     float border;
2138     float rounding;
2139     struct nk_vec2 padding;
2140  
2141     struct nk_style_edit edit;
2142     struct nk_style_button inc_button;
2143     struct nk_style_button dec_button;
2144  
2145     /* optional user callbacks */
2146     nk_handle userdata;
2147     void(*draw_begin)(struct nk_command_buffer*, nk_handle);
2148     void(*draw)(struct nk_command_buffer*, const struct nk_style_property*,
2149         const struct nk_rect*, const struct nk_rect *label, nk_flags state,
2150         const char *name, int len, const struct nk_user_font*);
2151     void(*draw_end)(struct nk_command_buffer*, nk_handle);
2152 };
2153  
2154 struct nk_style_chart {
2155     /* colors */
2156     struct nk_style_item background;
2157     struct nk_color border_color;
2158     struct nk_color selected_color;
2159     struct nk_color color;
2160  
2161     /* properties */
2162     float border;
2163     float rounding;
2164     struct nk_vec2 padding;
2165 };
2166  
2167 struct nk_style_combo {
2168     /* background */
2169     struct nk_style_item normal;
2170     struct nk_style_item hover;
2171     struct nk_style_item active;
2172     struct nk_color border_color;
2173  
2174     /* label */
2175     struct nk_color label_normal;
2176     struct nk_color label_hover;
2177     struct nk_color label_active;
2178  
2179     /* symbol */
2180     struct nk_color symbol_normal;
2181     struct nk_color symbol_hover;
2182     struct nk_color symbol_active;
2183  
2184     /* button */
2185     struct nk_style_button button;
2186     enum nk_symbol_type sym_normal;
2187     enum nk_symbol_type sym_hover;
2188     enum nk_symbol_type sym_active;
2189  
2190     /* properties */
2191     float border;
2192     float rounding;
2193     struct nk_vec2 content_padding;
2194     struct nk_vec2 button_padding;
2195     struct nk_vec2 spacing;
2196 };
2197  
2198 struct nk_style_tab {
2199     /* background */
2200     struct nk_style_item background;
2201     struct nk_color border_color;
2202     struct nk_color text;
2203  
2204     /* button */
2205     struct nk_style_button tab_button;
2206     struct nk_style_button node_button;
2207     enum nk_symbol_type sym_minimize;
2208     enum nk_symbol_type sym_maximize;
2209  
2210     /* properties */
2211     float border;
2212     float rounding;
2213     struct nk_vec2 padding;
2214     struct nk_vec2 spacing;
2215 };
2216  
2217 enum nk_style_header_align {
2218     NK_HEADER_LEFT,
2219     NK_HEADER_RIGHT
2220 };
2221  
2222 struct nk_style_window_header {
2223     /* background */
2224     struct nk_style_item normal;
2225     struct nk_style_item hover;
2226     struct nk_style_item active;
2227  
2228     /* button */
2229     struct nk_style_button close_button;
2230     struct nk_style_button minimize_button;
2231     enum nk_symbol_type close_symbol;
2232     enum nk_symbol_type minimize_symbol;
2233     enum nk_symbol_type maximize_symbol;
2234  
2235     /* title */
2236     struct nk_color label_normal;
2237     struct nk_color label_hover;
2238     struct nk_color label_active;
2239  
2240     /* properties */
2241     enum nk_style_header_align align;
2242     struct nk_vec2 padding;
2243     struct nk_vec2 label_padding;
2244     struct nk_vec2 spacing;
2245 };
2246  
2247 struct nk_style_window {
2248     struct nk_style_window_header header;
2249     struct nk_style_item fixed_background;
2250     struct nk_color background;
2251  
2252     struct nk_color border_color;
2253     struct nk_color combo_border_color;
2254     struct nk_color contextual_border_color;
2255     struct nk_color menu_border_color;
2256     struct nk_color group_border_color;
2257     struct nk_color tooltip_border_color;
2258  
2259     struct nk_style_item scaler;
2260     struct nk_vec2 footer_padding;
2261  
2262     float border;
2263     float combo_border;
2264     float contextual_border;
2265     float menu_border;
2266     float group_border;
2267     float tooltip_border;
2268  
2269     float rounding;
2270     struct nk_vec2 scaler_size;
2271     struct nk_vec2 padding;
2272     struct nk_vec2 spacing;
2273     struct nk_vec2 scrollbar_size;
2274     struct nk_vec2 min_size;
2275 };
2276  
2277 struct nk_style {
2278     struct nk_user_font font;
2279     struct nk_style_text text;
2280     struct nk_style_button button;
2281     struct nk_style_button contextual_button;
2282     struct nk_style_button menu_button;
2283     struct nk_style_toggle option;
2284     struct nk_style_toggle checkbox;
2285     struct nk_style_selectable selectable;
2286     struct nk_style_slider slider;
2287     struct nk_style_progress progress;
2288     struct nk_style_property property;
2289     struct nk_style_edit edit;
2290     struct nk_style_chart line_chart;
2291     struct nk_style_chart column_chart;
2292     struct nk_style_scrollbar scrollh;
2293     struct nk_style_scrollbar scrollv;
2294     struct nk_style_tab tab;
2295     struct nk_style_combo combo;
2296     struct nk_style_window window;
2297 };
2298  
2299 NK_API struct nk_style_item nk_style_item_image(struct nk_image img);
2300 NK_API struct nk_style_item nk_style_item_color(struct nk_color);
2301 NK_API struct nk_style_item nk_style_item_hide(void);
2302  
2303 /*==============================================================
2304  *                          PANEL
2305  * =============================================================*/
2306 struct nk_chart {
2307     const struct nk_style_chart *style;
2308     enum nk_chart_type type;
2309     float x, y, w, h;
2310     float min, max, range;
2311     struct nk_vec2 last;
2312     int index;
2313     int count;
2314 };
2315  
2316 struct nk_row_layout {
2317     int type;
2318     int index;
2319     float height;
2320     int columns;
2321     const float *ratio;
2322     float item_width, item_height;
2323     float item_offset;
2324     float filled;
2325     struct nk_rect item;
2326     int tree_depth;
2327 };
2328  
2329 struct nk_popup_buffer {
2330     nk_size begin;
2331     nk_size parent;
2332     nk_size last;
2333     nk_size end;
2334     int active;
2335 };
2336  
2337 struct nk_menu_state {
2338     float x, y, w, h;
2339     struct nk_scroll offset;
2340 };
2341  
2342 struct nk_panel {
2343     nk_flags flags;
2344     struct nk_rect bounds;
2345     struct nk_scroll *offset;
2346     float at_x, at_y, max_x;
2347     float width, height;
2348     float footer_h;
2349     float header_h;
2350     float border;
2351     struct nk_rect clip;
2352     struct nk_menu_state menu;
2353     struct nk_row_layout row;
2354     struct nk_chart chart;
2355     struct nk_popup_buffer popup_buffer;
2356     struct nk_command_buffer *buffer;
2357     struct nk_panel *parent;
2358 };
2359  
2360 /*==============================================================
2361  *                          WINDOW
2362  * =============================================================*/
2363 struct nk_table;
2364  
2365 enum nk_window_flags {
2366     NK_WINDOW_PRIVATE       = NK_FLAG(9),
2367     /* dummy flag which mark the beginning of the private window flag part */
2368     NK_WINDOW_ROM           = NK_FLAG(10),
2369     /* sets the window into a read only mode and does not allow input changes */
2370     NK_WINDOW_HIDDEN        = NK_FLAG(11),
2371     /* Hides the window and stops any window interaction and drawing can be set
2372      * by user input or by closing the window */
2373     NK_WINDOW_MINIMIZED     = NK_FLAG(12),
2374     /* marks the window as minimized */
2375     NK_WINDOW_SUB           = NK_FLAG(13),
2376     /* Marks the window as subwindow of another window*/
2377     NK_WINDOW_GROUP         = NK_FLAG(14),
2378     /* Marks the window as window widget group */
2379     NK_WINDOW_POPUP         = NK_FLAG(15),
2380     /* Marks the window as a popup window */
2381     NK_WINDOW_NONBLOCK      = NK_FLAG(16),
2382     /* Marks the window as a nonblock popup window */
2383     NK_WINDOW_CONTEXTUAL    = NK_FLAG(17),
2384     /* Marks the window as a combo box or menu */
2385     NK_WINDOW_COMBO         = NK_FLAG(18),
2386     /* Marks the window as a combo box */
2387     NK_WINDOW_MENU          = NK_FLAG(19),
2388     /* Marks the window as a menu */
2389     NK_WINDOW_TOOLTIP       = NK_FLAG(20),
2390     /* Marks the window as a menu */
2391     NK_WINDOW_REMOVE_ROM    = NK_FLAG(21)
2392     /* Removes the read only mode at the end of the window */
2393 };
2394  
2395 struct nk_popup_state {
2396     struct nk_window *win;
2397     enum nk_window_flags type;
2398     nk_hash name;
2399     int active;
2400     unsigned combo_count;
2401     unsigned con_count, con_old;
2402     unsigned active_con;
2403 };
2404  
2405 struct nk_edit_state {
2406     nk_hash name;
2407     unsigned int seq;
2408     unsigned int old;
2409     int active, prev;
2410     int cursor;
2411     int sel_start;
2412     int sel_end;
2413     struct nk_scroll scrollbar;
2414     unsigned char insert_mode;
2415     unsigned char single_line;
2416 };
2417  
2418 struct nk_property_state {
2419     int active, prev;
2420     char buffer[NK_MAX_NUMBER_BUFFER];
2421     int length;
2422     int cursor;
2423     nk_hash name;
2424     unsigned int seq;
2425     unsigned int old;
2426     int state;
2427 };
2428  
2429 struct nk_window {
2430     nk_hash name;
2431     nk_flags flags;
2432     unsigned int seq;
2433     struct nk_rect bounds;
2434     struct nk_scroll scrollbar;
2435     struct nk_command_buffer buffer;
2436     struct nk_panel *layout;
2437  
2438     /* persistent widget state */
2439     struct nk_property_state property;
2440     struct nk_popup_state popup;
2441     struct nk_edit_state edit;
2442  
2443     struct nk_table *tables;
2444     unsigned short table_count;
2445     unsigned short table_size;
2446  
2447     /* window list hooks */
2448     struct nk_window *next;
2449     struct nk_window *prev;
2450     struct nk_window *parent;
2451 };
2452  
2453 /*==============================================================
2454  *                          CONTEXT
2455  * =============================================================*/
2456 struct nk_context {
2457 /* public: can be accessed freely */
2458     struct nk_input input;
2459     struct nk_style style;
2460     struct nk_buffer memory;
2461     struct nk_clipboard clip;
2462     nk_flags last_widget_state;
2463  
2464 /* private:
2465     should only be accessed if you
2466     know what you are doing */
2467 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT
2468     struct nk_draw_list draw_list;
2469 #endif
2470 #ifdef NK_INCLUDE_COMMAND_USERDATA
2471     nk_handle userdata;
2472 #endif
2473  
2474     /* text editor objects are quite big because they have a internal
2475      * undo/redo stack. It therefore does not make sense to have one for
2476      * each window for temporary use cases, so I only provide *one* instance
2477      * for all windows. This works because the content is cleared anyway */
2478     struct nk_text_edit text_edit;
2479  
2480     /* windows */
2481     int build;
2482     void *pool;
2483     struct nk_window *begin;
2484     struct nk_window *end;
2485     struct nk_window *active;
2486     struct nk_window *current;
2487     struct nk_window *freelist;
2488     unsigned int count;
2489     unsigned int seq;
2490 };
2491  
2492 #ifdef __cplusplus
2493 }
2494 #endif
2495 #endif /* NK_H_ */
2496  
2497 /*
2498  * ==============================================================
2499  *
2500  *                          IMPLEMENTATION
2501  *
2502  * ===============================================================
2503  */
2504 #ifdef NK_IMPLEMENTATION
2505  
2506 #ifndef NK_POOL_DEFAULT_CAPACITY
2507 #define NK_POOL_DEFAULT_CAPACITY 16
2508 #endif
2509  
2510 #ifndef NK_VALUE_PAGE_CAPACITY
2511 #define NK_VALUE_PAGE_CAPACITY 32
2512 #endif
2513  
2514 #ifndef NK_DEFAULT_COMMAND_BUFFER_SIZE
2515 #define NK_DEFAULT_COMMAND_BUFFER_SIZE (4*1024)
2516 #endif
2517  
2518 #ifndef NK_BUFFER_DEFAULT_INITIAL_SIZE
2519 #define NK_BUFFER_DEFAULT_INITIAL_SIZE (4*1024)
2520 #endif
2521  
2522 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
2523 #include <stdlib.h> /* malloc, free */
2524 #endif
2525 #ifdef NK_INCLUDE_STANDARD_IO
2526 #include <stdio.h> /* fopen, fclose,... */
2527 #include <stdarg.h>
2528 #endif
2529  
2530 #ifndef NK_ASSERT
2531 #include <assert.h>
2532 #define NK_ASSERT(expr) assert(expr)
2533 #endif
2534  
2535 #ifndef NK_MEMSET
2536 #define NK_MEMSET nk_memset
2537 #endif
2538 #ifndef NK_MEMCPY
2539 #define NK_MEMCPY nk_memcopy
2540 #endif
2541 #ifndef NK_SQRT
2542 #define NK_SQRT nk_sqrt
2543 #endif
2544 #ifndef NK_SIN
2545 #define NK_SIN nk_sin
2546 #endif
2547 #ifndef NK_COS
2548 #define NK_COS nk_cos
2549 #endif
2550  
2551 /* ==============================================================
2552  *                          MATH
2553  * =============================================================== */
2554 #define NK_MIN(a,b) ((a) < (b) ? (a) : (b))
2555 #define NK_MAX(a,b) ((a) < (b) ? (b) : (a))
2556 #define NK_CLAMP(i,v,x) (NK_MAX(NK_MIN(v,x), i))
2557  
2558 #define NK_PI 3.141592654f
2559 #define NK_UTF_INVALID 0xFFFD
2560 #define NK_MAX_FLOAT_PRECISION 2
2561  
2562 #define NK_UNUSED(x) ((void)(x))
2563 #define NK_SATURATE(x) (NK_MAX(0, NK_MIN(1.0f, x)))
2564 #define NK_LEN(a) (sizeof(a)/sizeof(a)[0])
2565 #define NK_ABS(a) (((a) < 0) ? -(a) : (a))
2566 #define NK_BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
2567 #define NK_INBOX(px, py, x, y, w, h)\
2568     (NK_BETWEEN(px,x,x+w) && NK_BETWEEN(py,y,y+h))
2569 #define NK_INTERSECT(x0, y0, w0, h0, x1, y1, w1, h1) \
2570     (!(((x1 > (x0 + w0)) || ((x1 + w1) < x0) || (y1 > (y0 + h0)) || (y1 + h1) < y0)))
2571 #define NK_CONTAINS(x, y, w, h, bx, by, bw, bh)\
2572     (NK_INBOX(x,y, bx, by, bw, bh) && NK_INBOX(x+w,y+h, bx, by, bw, bh))
2573  
2574 #define nk_vec2_sub(a, b) nk_vec2((a).x - (b).x, (a).y - (b).y)
2575 #define nk_vec2_add(a, b) nk_vec2((a).x + (b).x, (a).y + (b).y)
2576 #define nk_vec2_len_sqr(a) ((a).x*(a).x+(a).y*(a).y)
2577 #define nk_vec2_muls(a, t) nk_vec2((a).x * (t), (a).y * (t))
2578  
2579 #define nk_ptr_add(t, p, i) ((t*)((void*)((nk_byte*)(p) + (i))))
2580 #define nk_ptr_add_const(t, p, i) ((const t*)((const void*)((const nk_byte*)(p) + (i))))
2581 #define nk_zero_struct(s) nk_zero(&s, sizeof(s))
2582  
2583 /* ==============================================================
2584  *                          ALIGNMENT
2585  * =============================================================== */
2586 /* Pointer to Integer type conversion for pointer alignment */
2587 #if defined(__PTRDIFF_TYPE__) /* This case should work for GCC*/
2588 # define NK_UINT_TO_PTR(x) ((void*)(__PTRDIFF_TYPE__)(x))
2589 # define NK_PTR_TO_UINT(x) ((nk_size)(__PTRDIFF_TYPE__)(x))
2590 #elif !defined(__GNUC__) /* works for compilers other than LLVM */
2591 # define NK_UINT_TO_PTR(x) ((void*)&((char*)0)[x])
2592 # define NK_PTR_TO_UINT(x) ((nk_size)(((char*)x)-(char*)0))
2593 #elif defined(NK_USE_FIXED_TYPES) /* used if we have <stdint.h> */
2594 # define NK_UINT_TO_PTR(x) ((void*)(uintptr_t)(x))
2595 # define NK_PTR_TO_UINT(x) ((uintptr_t)(x))
2596 #else /* generates warning but works */
2597 # define NK_UINT_TO_PTR(x) ((void*)(x))
2598 # define NK_PTR_TO_UINT(x) ((nk_size)(x))
2599 #endif
2600  
2601 #define NK_ALIGN_PTR(x, mask)\
2602     (NK_UINT_TO_PTR((NK_PTR_TO_UINT((nk_byte*)(x) + (mask-1)) & ~(mask-1))))
2603 #define NK_ALIGN_PTR_BACK(x, mask)\
2604     (NK_UINT_TO_PTR((NK_PTR_TO_UINT((nk_byte*)(x)) & ~(mask-1))))
2605  
2606 #ifdef __cplusplus
2607 template<typename T> struct nk_alignof;
2608 template<typename T, int size_diff> struct nk_helper{enum {value = size_diff};};
2609 template<typename T> struct nk_helper<T,0>{enum {value = nk_alignof<T>::value};};
2610 template<typename T> struct nk_alignof{struct Big {T x; char c;}; enum {
2611     diff = sizeof(Big) - sizeof(T), value = nk_helper<Big, diff>::value};};
2612 #define NK_ALIGNOF(t) (nk_alignof<t>::value);
2613 #else
2614 #define NK_ALIGNOF(t) ((char*)(&((struct {char c; t _h;}*)0)->_h) - (char*)0)
2615 #endif
2616  
2617 /* make sure correct type size */
2618 typedef int nk__check_size[(sizeof(nk_size) >= sizeof(void*)) ? 1 : -1];
2619 typedef int nk__check_ptr[(sizeof(nk_ptr) == sizeof(void*)) ? 1 : -1];
2620 typedef int nk__check_flags[(sizeof(nk_flags) >= 4) ? 1 : -1];
2621 typedef int nk__check_rune[(sizeof(nk_rune) >= 4) ? 1 : -1];
2622 typedef int nk__check_ushort[(sizeof(nk_ushort) == 2) ? 1 : -1];
2623 typedef int nk__check_short[(sizeof(nk_short) == 2) ? 1 : -1];
2624 typedef int nk__check_uint[(sizeof(nk_uint) == 4) ? 1 : -1];
2625 typedef int nk__check_int[(sizeof(nk_int) == 4) ? 1 : -1];
2626 typedef int nk__check_byte[(sizeof(nk_byte) == 1) ? 1 : -1];
2627  
2628 NK_GLOBAL const struct nk_rect nk_null_rect = {-8192.0f, -8192.0f, 16384, 16384};
2629 NK_GLOBAL const float NK_FLOAT_PRECISION = 0.00000000000001f;
2630 /*
2631  * ==============================================================
2632  *
2633  *                          MATH
2634  *
2635  * ===============================================================
2636  */
2637 /*  Since nuklear is supposed to work on all systems providing floating point
2638     math without any dependencies I also had to implement my own math functions
2639     for sqrt, sin and cos. Since the actual highly accurate implementations for
2640     the standard library functions are quite complex and I do not need high
2641     precision for my use cases I use approximations.
2642  
2643     Sqrt
2644     ----
2645     For square root nuklear uses the famous fast inverse square root:
2646     https://en.wikipedia.org/wiki/Fast_inverse_square_root with
2647     slightly tweaked magic constant. While on todays hardware it is
2648     probably not faster it is still fast and accurate enough for
2649     nuklear's use cases. IMPORTANT: this requires float format IEEE 754
2650  
2651     Sine/Cosine
2652     -----------
2653     All constants inside both function are generated Remez's minimax
2654     approximations for value range 0...2*PI. The reason why I decided to
2655     approximate exactly that range is that nuklear only needs sine and
2656     cosine to generate circles which only requires that exact range.
2657     In addition I used Remez instead of Taylor for additional precision:
2658     www.lolengine.net/blog/2011/12/21/better-function-approximatations.
2659  
2660     The tool I used to generate constants for both sine and cosine
2661     (it can actually approximate a lot more functions) can be
2662     found here: www.lolengine.net/wiki/oss/lolremez
2663 */
2664 NK_INTERN float
2665 nk_inv_sqrt(float number)
2666 {
2667     float x2;
2668     const float threehalfs = 1.5f;
2669     union {nk_uint i; float f;} conv = {0};
2670     conv.f = number;
2671     x2 = number * 0.5f;
2672     conv.i = 0x5f375A84 - (conv.i >> 1);
2673     conv.f = conv.f * (threehalfs - (x2 * conv.f * conv.f));
2674     return conv.f;
2675 }
2676  
2677 NK_INTERN float
2678 nk_sqrt(float x)
2679 {
2680     return x * nk_inv_sqrt(x);
2681 }
2682  
2683 NK_INTERN float
2684 nk_sin(float x)
2685 {
2686     NK_STORAGE const float a0 = +1.91059300966915117e-31f;
2687     NK_STORAGE const float a1 = +1.00086760103908896f;
2688     NK_STORAGE const float a2 = -1.21276126894734565e-2f;
2689     NK_STORAGE const float a3 = -1.38078780785773762e-1f;
2690     NK_STORAGE const float a4 = -2.67353392911981221e-2f;
2691     NK_STORAGE const float a5 = +2.08026600266304389e-2f;
2692     NK_STORAGE const float a6 = -3.03996055049204407e-3f;
2693     NK_STORAGE const float a7 = +1.38235642404333740e-4f;
2694     return a0 + x*(a1 + x*(a2 + x*(a3 + x*(a4 + x*(a5 + x*(a6 + x*a7))))));
2695 }
2696  
2697 NK_INTERN float
2698 nk_cos(float x)
2699 {
2700     NK_STORAGE const float a0 = +1.00238601909309722f;
2701     NK_STORAGE const float a1 = -3.81919947353040024e-2f;
2702     NK_STORAGE const float a2 = -3.94382342128062756e-1f;
2703     NK_STORAGE const float a3 = -1.18134036025221444e-1f;
2704     NK_STORAGE const float a4 = +1.07123798512170878e-1f;
2705     NK_STORAGE const float a5 = -1.86637164165180873e-2f;
2706     NK_STORAGE const float a6 = +9.90140908664079833e-4f;
2707     NK_STORAGE const float a7 = -5.23022132118824778e-14f;
2708     return a0 + x*(a1 + x*(a2 + x*(a3 + x*(a4 + x*(a5 + x*(a6 + x*a7))))));
2709 }
2710  
2711 NK_INTERN nk_uint
2712 nk_round_up_pow2(nk_uint v)
2713 {
2714     v--;
2715     v |= v >> 1;
2716     v |= v >> 2;
2717     v |= v >> 4;
2718     v |= v >> 8;
2719     v |= v >> 16;
2720     v++;
2721     return v;
2722 }
2723  
2724 NK_API struct nk_rect
2725 nk_get_null_rect(void)
2726 {
2727     return nk_null_rect;
2728 }
2729  
2730 NK_API struct nk_rect
2731 nk_rect(float x, float y, float w, float h)
2732 {
2733     struct nk_rect r;
2734     r.x = x, r.y = y;
2735     r.w = w, r.h = h;
2736     return r;
2737 }
2738  
2739 NK_API struct nk_rect
2740 nk_recti(int x, int y, int w, int h)
2741 {
2742     struct nk_rect r;
2743     r.x = (float)x;
2744     r.y = (float)y;
2745     r.w = (float)w;
2746     r.h = (float)h;
2747     return r;
2748 }
2749  
2750 NK_API struct nk_rect
2751 nk_recta(struct nk_vec2 pos, struct nk_vec2 size)
2752 {
2753     return nk_rect(pos.x, pos.y, size.x, size.y);
2754 }
2755  
2756 NK_API struct nk_rect
2757 nk_rectv(const float *r)
2758 {
2759     return nk_rect(r[0], r[1], r[2], r[3]);
2760 }
2761  
2762 NK_API struct nk_rect
2763 nk_rectiv(const int *r)
2764 {
2765     return nk_recti(r[0], r[1], r[2], r[3]);
2766 }
2767  
2768 NK_INTERN struct nk_rect
2769 nk_shrink_rect(struct nk_rect r, float amount)
2770 {
2771     struct nk_rect res;
2772     r.w = NK_MAX(r.w, 2 * amount);
2773     r.h = NK_MAX(r.h, 2 * amount);
2774     res.x = r.x + amount;
2775     res.y = r.y + amount;
2776     res.w = r.w - 2 * amount;
2777     res.h = r.h - 2 * amount;
2778     return res;
2779 }
2780  
2781 NK_INTERN struct nk_rect
2782 nk_pad_rect(struct nk_rect r, struct nk_vec2 pad)
2783 {
2784     r.w = NK_MAX(r.w, 2 * pad.x);
2785     r.h = NK_MAX(r.h, 2 * pad.y);
2786     r.x += pad.x; r.y += pad.y;
2787     r.w -= 2 * pad.x;
2788     r.h -= 2 * pad.y;
2789     return r;
2790 }
2791  
2792 NK_API struct nk_vec2
2793 nk_vec2(float x, float y)
2794 {
2795     struct nk_vec2 ret;
2796     ret.x = x; ret.y = y;
2797     return ret;
2798 }
2799  
2800 NK_API struct nk_vec2
2801 nk_vec2i(int x, int y)
2802 {
2803     struct nk_vec2 ret;
2804     ret.x = (float)x;
2805     ret.y = (float)y;
2806     return ret;
2807 }
2808  
2809 NK_API struct nk_vec2
2810 nk_vec2v(const float *v)
2811 {
2812     return nk_vec2(v[0], v[1]);
2813 }
2814  
2815 NK_API struct nk_vec2
2816 nk_vec2iv(const int *v)
2817 {
2818     return nk_vec2i(v[0], v[1]);
2819 }
2820 /*
2821  * ==============================================================
2822  *
2823  *                          UTIL
2824  *
2825  * ===============================================================
2826  */
2827 NK_INTERN int nk_str_match_here(const char *regexp, const char *text);
2828 NK_INTERN int nk_str_match_star(int c, const char *regexp, const char *text);
2829 NK_INTERN int nk_is_lower(int c) {return (c >= 'a' && c <= 'z') || (c >= 0xE0 && c <= 0xFF);}
2830 NK_INTERN int nk_is_upper(int c){return (c >= 'A' && c <= 'Z') || (c >= 0xC0 && c <= 0xDF);}
2831 NK_INTERN int nk_to_upper(int c) {return (c >= 'a' && c <= 'z') ? (c - ('a' - 'A')) : c;}
2832 NK_INTERN int nk_to_lower(int c) {return (c >= 'A' && c <= 'Z') ? (c - ('a' + 'A')) : c;}
2833  
2834 NK_INTERN void*
2835 nk_memcopy(void *dst0, const void *src0, nk_size length)
2836 {
2837     nk_ptr t;
2838     char *dst = (char*)dst0;
2839     const char *src = (const char*)src0;
2840     if (length == 0 || dst == src)
2841         goto done;
2842  
2843     #define nk_word int
2844     #define nk_wsize sizeof(nk_word)
2845     #define nk_wmask (nk_wsize-1)
2846     #define NK_TLOOP(s) if (t) NK_TLOOP1(s)
2847     #define NK_TLOOP1(s) do { s; } while (--t)
2848  
2849     if (dst < src) {
2850         t = (nk_ptr)src; /* only need low bits */
2851         if ((t | (nk_ptr)dst) & nk_wmask) {
2852             if ((t ^ (nk_ptr)dst) & nk_wmask || length < nk_wsize)
2853                 t = length;
2854             else
2855                 t = nk_wsize - (t & nk_wmask);
2856             length -= t;
2857             NK_TLOOP1(*dst++ = *src++);
2858         }
2859         t = length / nk_wsize;
2860         NK_TLOOP(*(nk_word*)(void*)dst = *(const nk_word*)(const void*)src;
2861             src += nk_wsize; dst += nk_wsize);
2862         t = length & nk_wmask;
2863         NK_TLOOP(*dst++ = *src++);
2864     } else {
2865         src += length;
2866         dst += length;
2867         t = (nk_ptr)src;
2868         if ((t | (nk_ptr)dst) & nk_wmask) {
2869             if ((t ^ (nk_ptr)dst) & nk_wmask || length <= nk_wsize)
2870                 t = length;
2871             else
2872                 t &= nk_wmask;
2873             length -= t;
2874             NK_TLOOP1(*--dst = *--src);
2875         }
2876         t = length / nk_wsize;
2877         NK_TLOOP(src -= nk_wsize; dst -= nk_wsize;
2878             *(nk_word*)(void*)dst = *(const nk_word*)(const void*)src);
2879         t = length & nk_wmask;
2880         NK_TLOOP(*--dst = *--src);
2881     }
2882     #undef nk_word
2883     #undef nk_wsize
2884     #undef nk_wmask
2885     #undef NK_TLOOP
2886     #undef NK_TLOOP1
2887 done:
2888     return (dst0);
2889 }
2890  
2891 NK_INTERN void
2892 nk_memset(void *ptr, int c0, nk_size size)
2893 {
2894     #define nk_word unsigned
2895     #define nk_wsize sizeof(nk_word)
2896     #define nk_wmask (nk_wsize - 1)
2897     nk_byte *dst = (nk_byte*)ptr;
2898     unsigned c = 0;
2899     nk_size t = 0;
2900  
2901     if ((c = (nk_byte)c0) != 0) {
2902         c = (c << 8) | c; /* at least 16-bits  */
2903         if (sizeof(unsigned int) > 2)
2904             c = (c << 16) | c; /* at least 32-bits*/
2905     }
2906  
2907     /* too small of a word count */
2908     dst = (nk_byte*)ptr;
2909     if (size < 3 * nk_wsize) {
2910         while (size--) *dst++ = (nk_byte)c0;
2911         return;
2912     }
2913  
2914     /* align destination */
2915     if ((t = NK_PTR_TO_UINT(dst) & nk_wmask) != 0) {
2916         t = nk_wsize -t;
2917         size -= t;
2918         do {
2919             *dst++ = (nk_byte)c0;
2920         } while (--t != 0);
2921     }
2922  
2923     /* fill word */
2924     t = size / nk_wsize;
2925     do {
2926         *(nk_word*)((void*)dst) = c;
2927         dst += nk_wsize;
2928     } while (--t != 0);
2929  
2930     /* fill trailing bytes */
2931     t = (size & nk_wmask);
2932     if (t != 0) {
2933         do {
2934             *dst++ = (nk_byte)c0;
2935         } while (--t != 0);
2936     }
2937  
2938     #undef nk_word
2939     #undef nk_wsize
2940     #undef nk_wmask
2941 }
2942  
2943 NK_INTERN void
2944 nk_zero(void *ptr, nk_size size)
2945 {
2946     NK_ASSERT(ptr);
2947     NK_MEMSET(ptr, 0, size);
2948 }
2949  
2950 NK_API int
2951 nk_strlen(const char *str)
2952 {
2953     int siz =