4 #ifndef NK_POOL_DEFAULT_CAPACITY
5 #define NK_POOL_DEFAULT_CAPACITY 16
8 #ifndef NK_DEFAULT_COMMAND_BUFFER_SIZE
9 #define NK_DEFAULT_COMMAND_BUFFER_SIZE (4*1024)
12 #ifndef NK_BUFFER_DEFAULT_INITIAL_SIZE
13 #define NK_BUFFER_DEFAULT_INITIAL_SIZE (4*1024)
17 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
20 #ifdef NK_INCLUDE_STANDARD_IO
23 #ifdef NK_INCLUDE_STANDARD_VARARGS
28 #define NK_ASSERT(expr) assert(expr)
31 #define NK_DEFAULT (-1)
38 #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) ||\
39 (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
40 (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)) ||\
41 (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 500)) ||\
42 defined(_ISOC99_SOURCE) || defined(_BSD_SOURCE)
43 #define NK_VSNPRINTF(s,n,f,a) vsnprintf(s,n,f,a)
45 #define NK_VSNPRINTF(s,n,f,a) vsprintf(s,f,a)
49 #define NK_SCHAR_MIN (-127)
50 #define NK_SCHAR_MAX 127
51 #define NK_UCHAR_MIN 0
52 #define NK_UCHAR_MAX 256
53 #define NK_SSHORT_MIN (-32767)
54 #define NK_SSHORT_MAX 32767
55 #define NK_USHORT_MIN 0
56 #define NK_USHORT_MAX 65535
57 #define NK_SINT_MIN (-2147483647)
58 #define NK_SINT_MAX 2147483647
60 #define NK_UINT_MAX 4294967295u
65 NK_STATIC_ASSERT(
sizeof(nk_size) >=
sizeof(
void*));
66 NK_STATIC_ASSERT(
sizeof(nk_ptr) ==
sizeof(
void*));
67 NK_STATIC_ASSERT(
sizeof(nk_flags) >= 4);
68 NK_STATIC_ASSERT(
sizeof(nk_rune) >= 4);
69 NK_STATIC_ASSERT(
sizeof(nk_ushort) == 2);
70 NK_STATIC_ASSERT(
sizeof(nk_short) == 2);
71 NK_STATIC_ASSERT(
sizeof(nk_uint) == 4);
72 NK_STATIC_ASSERT(
sizeof(nk_int) == 4);
73 NK_STATIC_ASSERT(
sizeof(nk_byte) == 1);
74 #ifdef NK_INCLUDE_STANDARD_BOOL
75 NK_STATIC_ASSERT(
sizeof(nk_bool) ==
sizeof(
bool));
77 NK_STATIC_ASSERT(
sizeof(nk_bool) == 4);
80 NK_GLOBAL
const struct nk_rect nk_null_rect = {-8192.0f, -8192.0f, 16384, 16384};
81 #define NK_FLOAT_PRECISION 0.00000000000001
83 NK_GLOBAL
const struct nk_color nk_red = {255,0,0,255};
84 NK_GLOBAL
const struct nk_color nk_green = {0,255,0,255};
85 NK_GLOBAL
const struct nk_color nk_blue = {0,0,255,255};
86 NK_GLOBAL
const struct nk_color nk_white = {255,255,255,255};
87 NK_GLOBAL
const struct nk_color nk_black = {0,0,0,255};
88 NK_GLOBAL
const struct nk_color nk_yellow = {255,255,0,255};
91 #define nk_widget_state_reset(s)\
92 if ((*(s)) & NK_WIDGET_STATE_MODIFIED)\
93 (*(s)) = NK_WIDGET_STATE_INACTIVE|NK_WIDGET_STATE_MODIFIED;\
94 else (*(s)) = NK_WIDGET_STATE_INACTIVE;
98 NK_LIB
float nk_inv_sqrt(
float n);
101 NK_LIB
float nk_sin(
float x);
104 NK_LIB
float nk_cos(
float x);
107 NK_LIB
float nk_atan(
float x);
110 NK_LIB
float nk_atan2(
float y,
float x);
112 NK_LIB nk_uint nk_round_up_pow2(nk_uint v);
113 NK_LIB
struct nk_rect nk_shrink_rect(struct
nk_rect r, float amount);
115 NK_LIB
void nk_unify(
struct nk_rect *clip,
const struct nk_rect *a,
float x0,
float y0,
float x1,
float y1);
116 NK_LIB
double nk_pow(
double x,
int n);
117 NK_LIB
int nk_ifloord(
double x);
118 NK_LIB
int nk_ifloorf(
float x);
119 NK_LIB
int nk_iceilf(
float x);
120 NK_LIB
int nk_log10(
double n);
121 NK_LIB
float nk_roundf(
float x);
124 enum {NK_DO_NOT_STOP_ON_NEW_LINE, NK_STOP_ON_NEW_LINE};
125 NK_LIB nk_bool nk_is_lower(
int c);
126 NK_LIB nk_bool nk_is_upper(
int c);
127 NK_LIB
int nk_to_upper(
int c);
128 NK_LIB
int nk_to_lower(
int c);
131 NK_LIB
void* nk_memcopy(
void *dst,
const void *src, nk_size n);
134 NK_LIB
void nk_memset(
void *ptr,
int c0, nk_size size);
136 NK_LIB
void nk_zero(
void *ptr, nk_size size);
137 NK_LIB
char *nk_itoa(
char *s,
long n);
138 NK_LIB
int nk_string_float_limit(
char *
string,
int prec);
140 NK_LIB
char *nk_dtoa(
char *s,
double n);
142 NK_LIB
int nk_text_clamp(
const struct nk_user_font *font,
const char *text,
int text_len,
float space,
int *glyphs,
float *text_width, nk_rune *sep_list,
int sep_count);
143 NK_LIB
struct nk_vec2 nk_text_calculate_text_bounds(const struct
nk_user_font *font,
const char *begin,
int byte_len,
float row_height,
const char **remaining,
struct nk_vec2 *out_offset,
int *glyphs,
int op);
144 #ifdef NK_INCLUDE_STANDARD_VARARGS
145 NK_LIB
int nk_strfmt(
char *buf,
int buf_size,
const char *fmt, va_list args);
147 #ifdef NK_INCLUDE_STANDARD_IO
148 NK_LIB
char *nk_file_load(
const char* path, nk_size* siz,
const struct nk_allocator *alloc);
152 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
153 NK_LIB
void* nk_malloc(
nk_handle unused,
void *old,nk_size size);
154 NK_LIB
void nk_mfree(
nk_handle unused,
void *ptr);
156 NK_LIB
void* nk_buffer_align(
void *unaligned, nk_size align, nk_size *alignment,
enum nk_buffer_allocation_type type);
157 NK_LIB
void* nk_buffer_alloc(
struct nk_buffer *b,
enum nk_buffer_allocation_type type, nk_size size, nk_size align);
158 NK_LIB
void* nk_buffer_realloc(
struct nk_buffer *b, nk_size capacity, nk_size *size);
163 NK_LIB
void* nk_command_buffer_push(
struct nk_command_buffer* b,
enum nk_command_type t, nk_size size);
176 NK_LIB
void nk_textedit_clear_state(
struct nk_text_edit *state,
enum nk_text_edit_type type, nk_plugin_filter filter);
177 NK_LIB
void nk_textedit_click(
struct nk_text_edit *state,
float x,
float y,
const struct nk_user_font *font,
float row_height);
178 NK_LIB
void nk_textedit_drag(
struct nk_text_edit *state,
float x,
float y,
const struct nk_user_font *font,
float row_height);
179 NK_LIB
void nk_textedit_key(
struct nk_text_edit *state,
enum nk_keys key,
int shift_mod,
const struct nk_user_font *font,
float row_height);
182 enum nk_window_insert_location {
186 NK_LIB
void *nk_create_window(
struct nk_context *ctx);
189 NK_LIB
struct nk_window *nk_find_window(
const struct nk_context *ctx, nk_hash hash,
const char *name);
190 NK_LIB
void nk_insert_window(
struct nk_context *ctx,
struct nk_window *win,
enum nk_window_insert_location loc);
193 NK_LIB
void nk_pool_init(
struct nk_pool *pool,
const struct nk_allocator *alloc,
unsigned int capacity);
194 NK_LIB
void nk_pool_free(
struct nk_pool *pool);
195 NK_LIB
void nk_pool_init_fixed(
struct nk_pool *pool,
void *memory, nk_size size);
208 NK_LIB nk_uint *nk_add_value(
struct nk_context *ctx,
struct nk_window *win, nk_hash name, nk_uint value);
209 NK_LIB nk_uint *nk_find_value(
const struct nk_window *win, nk_hash name);
212 NK_LIB
void *nk_create_panel(
struct nk_context *ctx);
214 NK_LIB nk_bool nk_panel_has_header(nk_flags flags,
const char *title);
215 NK_LIB
struct nk_vec2 nk_panel_get_padding(const struct
nk_style *style,
enum nk_panel_type type);
216 NK_LIB
float nk_panel_get_border(
const struct nk_style *style, nk_flags flags,
enum nk_panel_type type);
217 NK_LIB
struct nk_color nk_panel_get_border_color(const struct
nk_style *style,
enum nk_panel_type type);
218 NK_LIB nk_bool nk_panel_is_sub(
enum nk_panel_type type);
219 NK_LIB nk_bool nk_panel_is_nonblock(
enum nk_panel_type type);
220 NK_LIB nk_bool nk_panel_begin(
struct nk_context *ctx,
const char *title,
enum nk_panel_type panel_type);
221 NK_LIB
void nk_panel_end(
struct nk_context *ctx);
224 NK_LIB
float nk_layout_row_calculate_usable_space(
const struct nk_style *style,
enum nk_panel_type type,
float total_space,
int columns);
225 NK_LIB
void nk_panel_layout(
const struct nk_context *ctx,
struct nk_window *win,
float height,
int cols);
226 NK_LIB
void nk_row_layout(
struct nk_context *ctx,
enum nk_layout_format fmt,
float height,
int cols,
int width);
229 NK_LIB
void nk_panel_alloc_space(
struct nk_rect *bounds,
const struct nk_context *ctx);
230 NK_LIB
void nk_layout_peek(
struct nk_rect *bounds,
const struct nk_context *ctx);
233 NK_LIB nk_bool nk_nonblock_begin(
struct nk_context *ctx, nk_flags flags,
struct nk_rect body,
struct nk_rect header,
enum nk_panel_type panel_type);
245 NK_LIB nk_bool nk_button_behavior(nk_flags *state,
struct nk_rect r,
const struct nk_input *i,
enum nk_button_behavior behavior);
255 NK_LIB nk_bool nk_do_button_text_symbol(nk_flags *state,
struct nk_command_buffer *out,
struct nk_rect bounds,
enum nk_symbol_type symbol,
const char *str,
int len, nk_flags align,
enum nk_button_behavior behavior,
const struct nk_style_button *style,
const struct nk_user_font *font,
const struct nk_input *in);
257 NK_LIB nk_bool nk_do_button_text_image(nk_flags *state,
struct nk_command_buffer *out,
struct nk_rect bounds,
struct nk_image img,
const char* str,
int len, nk_flags align,
enum nk_button_behavior behavior,
const struct nk_style_button *style,
const struct nk_user_font *font,
const struct nk_input *in);
260 enum nk_toggle_type {
264 NK_LIB nk_bool nk_toggle_behavior(
const struct nk_input *in,
struct nk_rect select, nk_flags *state, nk_bool active);
265 NK_LIB
void nk_draw_checkbox(
struct nk_command_buffer *out, nk_flags state,
const struct nk_style_toggle *style, nk_bool active,
const struct nk_rect *label,
const struct nk_rect *selector,
const struct nk_rect *cursors,
const char *
string,
int len,
const struct nk_user_font *font, nk_flags text_alignment);
266 NK_LIB
void nk_draw_option(
struct nk_command_buffer *out, nk_flags state,
const struct nk_style_toggle *style, nk_bool active,
const struct nk_rect *label,
const struct nk_rect *selector,
const struct nk_rect *cursors,
const char *
string,
int len,
const struct nk_user_font *font, nk_flags text_alignment);
267 NK_LIB nk_bool nk_do_toggle(nk_flags *state,
struct nk_command_buffer *out,
struct nk_rect r, nk_bool *active,
const char *str,
int len,
enum nk_toggle_type type,
const struct nk_style_toggle *style,
const struct nk_input *in,
const struct nk_user_font *font, nk_flags widget_alignment, nk_flags text_alignment);
270 NK_LIB nk_size nk_progress_behavior(nk_flags *state,
struct nk_input *in,
struct nk_rect r,
struct nk_rect cursor, nk_size max, nk_size value, nk_bool modifiable);
275 NK_LIB
float nk_slider_behavior(nk_flags *state,
struct nk_rect *logical_cursor,
struct nk_rect *visual_cursor,
struct nk_input *in,
struct nk_rect bounds,
float slider_min,
float slider_max,
float slider_value,
float slider_step,
float slider_steps);
280 NK_LIB
float nk_scrollbar_behavior(nk_flags *state,
struct nk_input *in,
int has_scrolling,
const struct nk_rect *scroll,
const struct nk_rect *cursor,
const struct nk_rect *empty0,
const struct nk_rect *empty1,
float scroll_offset,
float target,
float scroll_step,
enum nk_orientation o);
282 NK_LIB
float nk_do_scrollbarv(nk_flags *state,
struct nk_command_buffer *out,
struct nk_rect scroll,
int has_scrolling,
float offset,
float target,
float step,
float button_pixel_inc,
const struct nk_style_scrollbar *style,
struct nk_input *in,
const struct nk_user_font *font);
283 NK_LIB
float nk_do_scrollbarh(nk_flags *state,
struct nk_command_buffer *out,
struct nk_rect scroll,
int has_scrolling,
float offset,
float target,
float step,
float button_pixel_inc,
const struct nk_style_scrollbar *style,
struct nk_input *in,
const struct nk_user_font *font);
286 NK_LIB
void nk_draw_selectable(
struct nk_command_buffer *out, nk_flags state,
const struct nk_style_selectable *style, nk_bool active,
const struct nk_rect *bounds,
const struct nk_rect *icon,
const struct nk_image *img,
enum nk_symbol_type sym,
const char *
string,
int len, nk_flags align,
const struct nk_user_font *font);
288 NK_LIB nk_bool nk_do_selectable_image(nk_flags *state,
struct nk_command_buffer *out,
struct nk_rect bounds,
const char *str,
int len, nk_flags align, nk_bool *value,
const struct nk_image *img,
const struct nk_style_selectable *style,
const struct nk_input *in,
const struct nk_user_font *font);
291 NK_LIB
void nk_edit_draw_text(
struct nk_command_buffer *out,
const struct nk_style_edit *style,
float pos_x,
float pos_y,
float x_offset,
const char *text,
int byte_len,
float row_height,
const struct nk_user_font *font,
struct nk_color background,
struct nk_color foreground, nk_bool is_selected);
295 NK_LIB nk_bool nk_color_picker_behavior(nk_flags *state,
const struct nk_rect *bounds,
const struct nk_rect *matrix,
const struct nk_rect *hue_bar,
const struct nk_rect *alpha_bar,
struct nk_colorf *color,
const struct nk_input *in);
300 enum nk_property_status {
305 enum nk_property_filter {
309 enum nk_property_kind {
320 enum nk_property_kind kind;
326 NK_LIB
struct nk_property_variant nk_property_variant_int(int value, int min_value, int max_value, int step);
327 NK_LIB
struct nk_property_variant nk_property_variant_float(float value, float min_value, float max_value, float step);
328 NK_LIB
struct nk_property_variant nk_property_variant_double(double value, double min_value, double max_value, double step);
333 NK_LIB
void nk_do_property(nk_flags *ws,
struct nk_command_buffer *out,
struct nk_rect property,
const char *name,
struct nk_property_variant *variant,
float inc_per_pixel,
char *buffer,
int *len,
int *state,
int *cursor,
int *select_begin,
int *select_end,
const struct nk_style_property *style,
enum nk_property_filter filter,
struct nk_input *in,
const struct nk_user_font *font,
struct nk_text_edit *text_edit,
enum nk_button_behavior behavior);
336 #ifdef NK_INCLUDE_FONT_BAKING
343 #ifndef NK_NO_STB_RECT_PACK_IMPLEMENTATION
344 #define STB_RECT_PACK_IMPLEMENTATION
352 #ifndef NK_NO_STB_TRUETYPE_IMPLEMENTATION
353 #define STB_TRUETYPE_IMPLEMENTATION
359 nk_stbtt_malloc(nk_size size,
void *user_data) {
361 return alloc->alloc(alloc->userdata, 0, size);
365 nk_stbtt_free(
void *ptr,
void *user_data) {
367 alloc->free(alloc->userdata, ptr);
370 #define STBTT_malloc(x,u) nk_stbtt_malloc(x,u)
371 #define STBTT_free(x,u) nk_stbtt_free(x,u)