diff --git a/Readme.md b/Readme.md index 2abbd9cfd..a65d2bc5c 100644 --- a/Readme.md +++ b/Readme.md @@ -59,37 +59,55 @@ This is very important; not doing it either leads to compiler errors, or even wo struct nk_context ctx; nk_init_fixed(&ctx, calloc(1, MAX_MEMORY), MAX_MEMORY, &font); -enum {EASY, HARD}; -static int op = EASY; +enum { EASY, NORMAL, HARD }; +static int op = EASY, active[3]{ 1, 0, 1 }, selected{}; static float value = 0.6f; static int i = 20; - -if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220), - NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) { - /* fixed widget pixel width */ - nk_layout_row_static(&ctx, 30, 80, 1); - if (nk_button_label(&ctx, "button")) { - /* event handling */ - } - - /* fixed widget window ratio width */ - nk_layout_row_dynamic(&ctx, 30, 2); - if (nk_option_label(&ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(&ctx, "hard", op == HARD)) op = HARD; - - /* custom widget pixel width */ - nk_layout_row_begin(&ctx, NK_STATIC, 30, 2); - { - nk_layout_row_push(&ctx, 50); - nk_label(&ctx, "Volume:", NK_TEXT_LEFT); - nk_layout_row_push(&ctx, 110); - nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f); - } - nk_layout_row_end(&ctx); +static size_t test{}; + +static char const * biomes[] = { + "Large biome", + "Small biome" +}; + +static int biomeCount = int(sizeof(biomes) / sizeof(biomes[0])); + +if (nk_begin(&ctx, "Show", nk_rect(50, 50, 300, 350), + NK_WINDOW_BORDER|NK_WINDOW_SCALABLE|NK_WINDOW_MOVABLE|NK_WINDOW_TITLE)) { + + // fixed widget pixel width + nk_layout_row_static(&ctx, 30, 150, 1); + if (nk_button_label(&ctx, "Play")) + myPlayFunction(); + + // fixed widget window ratio width + nk_layout_row_dynamic(&ctx, 30, 2); + if (nk_option_label(&ctx, "Easy", op == EASY)) op = EASY; + if (nk_option_label(&ctx, "Normal", op == NORMAL)) op = NORMAL; + if (nk_option_label(&ctx, "Hard", op == HARD)) op = HARD; + + nk_layout_row_dynamic(ctx, 30, 2); + nk_checkbox_label(&ctx, "Silver", active); + nk_checkbox_label(&ctx, "Bronze", active + 1); + nk_checkbox_label(&ctx, "Gold", active + 2); + + nk_layout_row_dynamic(&ctx, 30, 2); + nk_combobox(&ctx, names, biome_count, &selected, 30, nk_vec2(150, 200)); + + // custom widget pixel width + nk_layout_row_begin(&ctx, NK_STATIC, 30, 2); + { + nk_layout_row_push(&ctx, 50); + nk_label(&ctx, "Volume:", NK_TEXT_LEFT); + nk_layout_row_push(&ctx, 110); + nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f); + nk_progress(&ctx, &test, 100, 1); + } + nk_layout_row_end(&ctx); } nk_end(&ctx); ``` -![example](https://cloud.githubusercontent.com/assets/8057201/10187981/584ecd68-675c-11e5-897c-822ef534a876.png) +![example](img/test%20window.png) ## Bindings There are a number of nuklear bindings for different languges created by other authors. diff --git a/img/test window.png b/img/test window.png new file mode 100644 index 000000000..d6b6b2062 Binary files /dev/null and b/img/test window.png differ diff --git a/nuklear.h b/nuklear.h index 94939bdbe..482a4d2e9 100644 --- a/nuklear.h +++ b/nuklear.h @@ -4610,6 +4610,7 @@ struct nk_mouse { unsigned char grab; unsigned char grabbed; unsigned char ungrab; + unsigned char clicked; }; struct nk_key { @@ -5716,9 +5717,11 @@ template struct nk_alignof{struct Big {T x; char c;}; enum { #ifndef NK_MEMSET #define NK_MEMSET nk_memset +#define NK_MEMSET_BUILTIN #endif #ifndef NK_MEMCPY #define NK_MEMCPY nk_memcopy +#define NK_MEMCPY_BUILTIN #endif #ifndef NK_SQRT #define NK_SQRT nk_sqrt @@ -5817,8 +5820,15 @@ NK_LIB int nk_is_lower(int c); NK_LIB int nk_is_upper(int c); NK_LIB int nk_to_upper(int c); NK_LIB int nk_to_lower(int c); + +#ifdef NK_MEMCPY_BUILTIN NK_LIB void* nk_memcopy(void *dst, const void *src, nk_size n); +#endif + +#ifdef NK_MEMSET_BUILTIN NK_LIB void nk_memset(void *ptr, int c0, nk_size size); +#endif + NK_LIB void nk_zero(void *ptr, nk_size size); NK_LIB char *nk_itoa(char *s, long n); NK_LIB int nk_string_float_limit(char *string, int prec); @@ -5926,29 +5936,29 @@ NK_LIB void nk_widget_text(struct nk_command_buffer *o, struct nk_rect b, const NK_LIB void nk_widget_text_wrap(struct nk_command_buffer *o, struct nk_rect b, const char *string, int len, const struct nk_text *t, const struct nk_user_font *f); /* button */ -NK_LIB int nk_button_behavior(nk_flags *state, struct nk_rect r, const struct nk_input *i, enum nk_button_behavior behavior); +NK_LIB int nk_button_behavior(nk_flags *state, struct nk_rect r, struct nk_input *i, enum nk_button_behavior behavior); NK_LIB const struct nk_style_item* nk_draw_button(struct nk_command_buffer *out, const struct nk_rect *bounds, nk_flags state, const struct nk_style_button *style); -NK_LIB int nk_do_button(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r, const struct nk_style_button *style, const struct nk_input *in, enum nk_button_behavior behavior, struct nk_rect *content); +NK_LIB int nk_do_button(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r, const struct nk_style_button *style, struct nk_input *in, enum nk_button_behavior behavior, struct nk_rect *content); NK_LIB void nk_draw_button_text(struct nk_command_buffer *out, const struct nk_rect *bounds, const struct nk_rect *content, nk_flags state, const struct nk_style_button *style, const char *txt, int len, nk_flags text_alignment, const struct nk_user_font *font); -NK_LIB int nk_do_button_text(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *string, int len, nk_flags align, enum nk_button_behavior behavior, const struct nk_style_button *style, const struct nk_input *in, const struct nk_user_font *font); +NK_LIB int nk_do_button_text(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *string, int len, nk_flags align, enum nk_button_behavior behavior, const struct nk_style_button *style, struct nk_input *in, const struct nk_user_font *font); NK_LIB void nk_draw_button_symbol(struct nk_command_buffer *out, const struct nk_rect *bounds, const struct nk_rect *content, nk_flags state, const struct nk_style_button *style, enum nk_symbol_type type, const struct nk_user_font *font); -NK_LIB int nk_do_button_symbol(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, enum nk_symbol_type symbol, enum nk_button_behavior behavior, const struct nk_style_button *style, const struct nk_input *in, const struct nk_user_font *font); +NK_LIB int nk_do_button_symbol(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, enum nk_symbol_type symbol, enum nk_button_behavior behavior, const struct nk_style_button *style, struct nk_input *in, const struct nk_user_font *font); NK_LIB void nk_draw_button_image(struct nk_command_buffer *out, const struct nk_rect *bounds, const struct nk_rect *content, nk_flags state, const struct nk_style_button *style, const struct nk_image *img); -NK_LIB int nk_do_button_image(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, struct nk_image img, enum nk_button_behavior b, const struct nk_style_button *style, const struct nk_input *in); +NK_LIB int nk_do_button_image(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, struct nk_image img, enum nk_button_behavior b, const struct nk_style_button *style, struct nk_input *in); NK_LIB void nk_draw_button_text_symbol(struct nk_command_buffer *out, const struct nk_rect *bounds, const struct nk_rect *label, const struct nk_rect *symbol, nk_flags state, const struct nk_style_button *style, const char *str, int len, enum nk_symbol_type type, const struct nk_user_font *font); -NK_LIB int 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); +NK_LIB int 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, struct nk_input *in); NK_LIB void nk_draw_button_text_image(struct nk_command_buffer *out, const struct nk_rect *bounds, const struct nk_rect *label, const struct nk_rect *image, nk_flags state, const struct nk_style_button *style, const char *str, int len, const struct nk_user_font *font, const struct nk_image *img); -NK_LIB int 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); +NK_LIB int 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, struct nk_input *in); /* toggle */ enum nk_toggle_type { NK_TOGGLE_CHECK, NK_TOGGLE_OPTION }; -NK_LIB int nk_toggle_behavior(const struct nk_input *in, struct nk_rect select, nk_flags *state, int active); +NK_LIB int nk_toggle_behavior(struct nk_input *in, struct nk_rect select, nk_flags *state, int active); NK_LIB void nk_draw_checkbox(struct nk_command_buffer *out, nk_flags state, const struct nk_style_toggle *style, int 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_LIB void nk_draw_option(struct nk_command_buffer *out, nk_flags state, const struct nk_style_toggle *style, int 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_LIB int nk_do_toggle(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r, int *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_LIB int nk_do_toggle(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r, int *active, const char *str, int len, enum nk_toggle_type type, const struct nk_style_toggle *style, struct nk_input *in, const struct nk_user_font *font); /* progress */ 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, int modifiable); @@ -5968,17 +5978,17 @@ NK_LIB float nk_do_scrollbarh(nk_flags *state, struct nk_command_buffer *out, st /* selectable */ NK_LIB void nk_draw_selectable(struct nk_command_buffer *out, nk_flags state, const struct nk_style_selectable *style, int 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); -NK_LIB int nk_do_selectable(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *str, int len, nk_flags align, int *value, const struct nk_style_selectable *style, const struct nk_input *in, const struct nk_user_font *font); -NK_LIB int nk_do_selectable_image(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *str, int len, nk_flags align, int *value, const struct nk_image *img, const struct nk_style_selectable *style, const struct nk_input *in, const struct nk_user_font *font); +NK_LIB int nk_do_selectable(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *str, int len, nk_flags align, int *value, const struct nk_style_selectable *style, struct nk_input *in, const struct nk_user_font *font); +NK_LIB int nk_do_selectable_image(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *str, int len, nk_flags align, int *value, const struct nk_image *img, const struct nk_style_selectable *style, struct nk_input *in, const struct nk_user_font *font); /* edit */ 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, int is_selected); NK_LIB nk_flags nk_do_edit(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, nk_flags flags, nk_plugin_filter filter, struct nk_text_edit *edit, const struct nk_style_edit *style, struct nk_input *in, const struct nk_user_font *font); /* color-picker */ -NK_LIB int 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); +NK_LIB int 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, struct nk_input *in); NK_LIB void nk_draw_color_picker(struct nk_command_buffer *o, const struct nk_rect *matrix, const struct nk_rect *hue_bar, const struct nk_rect *alpha_bar, struct nk_colorf col); -NK_LIB int nk_do_color_picker(nk_flags *state, struct nk_command_buffer *out, struct nk_colorf *col, enum nk_color_format fmt, struct nk_rect bounds, struct nk_vec2 padding, const struct nk_input *in, const struct nk_user_font *font); +NK_LIB int nk_do_color_picker(nk_flags *state, struct nk_command_buffer *out, struct nk_colorf *col, enum nk_color_format fmt, struct nk_rect bounds, struct nk_vec2 padding, struct nk_input *in, const struct nk_user_font *font); /* property */ enum nk_property_status { @@ -6011,8 +6021,8 @@ NK_LIB struct nk_property_variant nk_property_variant_int(int value, int min_val NK_LIB struct nk_property_variant nk_property_variant_float(float value, float min_value, float max_value, float step); NK_LIB struct nk_property_variant nk_property_variant_double(double value, double min_value, double max_value, double step); -NK_LIB void nk_drag_behavior(nk_flags *state, const struct nk_input *in, struct nk_rect drag, struct nk_property_variant *variant, float inc_per_pixel); -NK_LIB void nk_property_behavior(nk_flags *ws, const struct nk_input *in, struct nk_rect property, struct nk_rect label, struct nk_rect edit, struct nk_rect empty, int *state, struct nk_property_variant *variant, float inc_per_pixel); +NK_LIB void nk_drag_behavior(nk_flags *state, struct nk_input *in, struct nk_rect drag, struct nk_property_variant *variant, float inc_per_pixel); +NK_LIB void nk_property_behavior(nk_flags *ws, struct nk_input *in, struct nk_rect property, struct nk_rect label, struct nk_rect edit, struct nk_rect empty, int *state, struct nk_property_variant *variant, float inc_per_pixel); NK_LIB void nk_draw_property(struct nk_command_buffer *out, const struct nk_style_property *style, const struct nk_rect *bounds, const struct nk_rect *label, nk_flags state, const char *name, int len, const struct nk_user_font *font); 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); NK_LIB void nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant *variant, float inc_per_pixel, const enum nk_property_filter filter); @@ -6334,6 +6344,8 @@ NK_LIB int nk_is_upper(int c){return (c >= 'A' && c <= 'Z') || (c >= 0xC0 && c < NK_LIB int nk_to_upper(int c) {return (c >= 'a' && c <= 'z') ? (c - ('a' - 'A')) : c;} NK_LIB int nk_to_lower(int c) {return (c >= 'A' && c <= 'Z') ? (c - ('a' + 'A')) : c;} +#ifdef NK_MEMCPY_BUILTIN + NK_LIB void* nk_memcopy(void *dst0, const void *src0, nk_size length) { @@ -6390,6 +6402,11 @@ nk_memcopy(void *dst0, const void *src0, nk_size length) done: return (dst0); } + +#endif + +#ifdef NK_MEMSET_BUILTIN + NK_LIB void nk_memset(void *ptr, int c0, nk_size size) { @@ -6441,6 +6458,9 @@ nk_memset(void *ptr, int c0, nk_size size) #undef nk_wsize #undef nk_wmask } + +#endif + NK_LIB void nk_zero(void *ptr, nk_size size) { @@ -9437,6 +9457,8 @@ nk_draw_list_alloc_vertices(struct nk_draw_list *list, nk_size count) if (!vtx) return 0; list->vertex_count += (unsigned int)count; + #ifndef NK_UINT_DRAW_INDEX + /* This assert triggers because your are drawing a lot of stuff and nuklear * defined `nk_draw_index` as `nk_ushort` to safe space be default. * @@ -9446,8 +9468,11 @@ nk_draw_list_alloc_vertices(struct nk_draw_list *list, nk_size count) * backend (OpenGL, DirectX, ...). For example in OpenGL for `glDrawElements` * instead of specifing `GL_UNSIGNED_SHORT` you have to define `GL_UNSIGNED_INT`. * Sorry for the inconvenience. */ - if(sizeof(nk_draw_index)==2) NK_ASSERT((list->vertex_count < NK_USHORT_MAX && + NK_ASSERT((list->vertex_count < NK_USHORT_MAX && "To many verticies for 16-bit vertex indicies. Please read comment above on how to solve this problem")); + + #endif + return vtx; } NK_INTERN nk_draw_index* @@ -13959,6 +13984,11 @@ nk_input_begin(struct nk_context *ctx) in->mouse.prev.y = in->mouse.pos.y; in->mouse.delta.x = 0; in->mouse.delta.y = 0; + + #if defined(NK_KEYSTATE_BASED_INPUT) || defined(NK_BUTTON_TRIGGER_ON_RELEASE) + in->mouse.clicked = 0; + #endif + for (i = 0; i < NK_KEY_MAX; i++) in->keyboard.keys[i].clicked = 0; } @@ -14015,6 +14045,14 @@ nk_input_button(struct nk_context *ctx, enum nk_buttons id, int x, int y, int do if (in->mouse.buttons[id].down == down) return; btn = &in->mouse.buttons[id]; + + #ifndef NK_BUTTON_TRIGGER_ON_RELEASE + + if(id == NK_BUTTON_LEFT && !down) + in->mouse.clicked = 0; + + #endif + btn->clicked_pos.x = (float)x; btn->clicked_pos.y = (float)y; btn->down = down; @@ -14077,7 +14115,7 @@ nk_input_has_mouse_click_in_rect(const struct nk_input *i, enum nk_buttons id, struct nk_rect b) { const struct nk_mouse_button *btn; - if (!i) return nk_false; + if (!i || i->mouse.clicked) return nk_false; btn = &i->mouse.buttons[id]; if (!NK_INBOX(btn->clicked_pos.x,btn->clicked_pos.y,b.x,b.y,b.w,b.h)) return nk_false; @@ -14151,7 +14189,7 @@ nk_input_is_mouse_pressed(const struct nk_input *i, enum nk_buttons id) const struct nk_mouse_button *b; if (!i) return nk_false; b = &i->mouse.buttons[id]; - if (b->down && b->clicked) + if (b->down && b->clicked && !i->mouse.clicked) return nk_true; return nk_false; } @@ -14159,7 +14197,7 @@ NK_API int nk_input_is_mouse_released(const struct nk_input *i, enum nk_buttons id) { if (!i) return nk_false; - return (!i->mouse.buttons[id].down && i->mouse.buttons[id].clicked); + return (!i->mouse.buttons[id].down && !(i->mouse.buttons[id].clicked && !i->mouse.clicked)); } NK_API int nk_input_is_key_pressed(const struct nk_input *i, enum nk_keys key) @@ -17129,7 +17167,7 @@ nk_contextual_item_text(struct nk_context *ctx, const char *text, int len, nk_flags alignment) { struct nk_window *win; - const struct nk_input *in; + struct nk_input *in; const struct nk_style *style; struct nk_rect bounds; @@ -17164,7 +17202,7 @@ nk_contextual_item_image_text(struct nk_context *ctx, struct nk_image img, const char *text, int len, nk_flags align) { struct nk_window *win; - const struct nk_input *in; + struct nk_input *in; const struct nk_style *style; struct nk_rect bounds; @@ -17200,7 +17238,7 @@ nk_contextual_item_symbol_text(struct nk_context *ctx, enum nk_symbol_type symbo const char *text, int len, nk_flags align) { struct nk_window *win; - const struct nk_input *in; + struct nk_input *in; const struct nk_style *style; struct nk_rect bounds; @@ -17393,7 +17431,7 @@ nk_menu_begin_text(struct nk_context *ctx, const char *title, int len, nk_flags align, struct nk_vec2 size) { struct nk_window *win; - const struct nk_input *in; + struct nk_input *in; struct nk_rect header; int is_clicked = nk_false; nk_flags state; @@ -17424,7 +17462,7 @@ nk_menu_begin_image(struct nk_context *ctx, const char *id, struct nk_image img, { struct nk_window *win; struct nk_rect header; - const struct nk_input *in; + struct nk_input *in; int is_clicked = nk_false; nk_flags state; @@ -17448,7 +17486,7 @@ nk_menu_begin_symbol(struct nk_context *ctx, const char *id, enum nk_symbol_type sym, struct nk_vec2 size) { struct nk_window *win; - const struct nk_input *in; + struct nk_input *in; struct nk_rect header; int is_clicked = nk_false; nk_flags state; @@ -17474,7 +17512,7 @@ nk_menu_begin_image_text(struct nk_context *ctx, const char *title, int len, { struct nk_window *win; struct nk_rect header; - const struct nk_input *in; + struct nk_input *in; int is_clicked = nk_false; nk_flags state; @@ -17506,7 +17544,7 @@ nk_menu_begin_symbol_text(struct nk_context *ctx, const char *title, int len, { struct nk_window *win; struct nk_rect header; - const struct nk_input *in; + struct nk_input *in; int is_clicked = nk_false; nk_flags state; @@ -18357,7 +18395,7 @@ nk_tree_state_base(struct nk_context *ctx, enum nk_tree_type type, struct nk_panel *layout; const struct nk_style *style; struct nk_command_buffer *out; - const struct nk_input *in; + struct nk_input *in; const struct nk_style_button *button; enum nk_symbol_type symbol; float row_height; @@ -18538,7 +18576,7 @@ nk_tree_element_image_push_hashed_base(struct nk_context *ctx, enum nk_tree_type struct nk_panel *layout; const struct nk_style *style; struct nk_command_buffer *out; - const struct nk_input *in; + struct nk_input *in; const struct nk_style_button *button; enum nk_symbol_type symbol; float row_height; @@ -18685,7 +18723,6 @@ nk_tree_element_pop(struct nk_context *ctx) - /* =============================================================== * * GROUP @@ -19747,7 +19784,7 @@ nk_draw_symbol(struct nk_command_buffer *out, enum nk_symbol_type type, } NK_LIB int nk_button_behavior(nk_flags *state, struct nk_rect r, - const struct nk_input *i, enum nk_button_behavior behavior) + struct nk_input *i, enum nk_button_behavior behavior) { int ret = 0; nk_widget_state_reset(state); @@ -19764,6 +19801,8 @@ nk_button_behavior(nk_flags *state, struct nk_rect r, #else nk_input_is_mouse_pressed(i, NK_BUTTON_LEFT); #endif + if (ret) + i->mouse.clicked = 1; } } if (*state & NK_WIDGET_STATE_HOVER && !nk_input_is_mouse_prev_hovering_rect(i, r)) @@ -19794,7 +19833,7 @@ nk_draw_button(struct nk_command_buffer *out, } NK_LIB int nk_do_button(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r, - const struct nk_style_button *style, const struct nk_input *in, + const struct nk_style_button *style, struct nk_input *in, enum nk_button_behavior behavior, struct nk_rect *content) { struct nk_rect bounds; @@ -19844,7 +19883,7 @@ NK_LIB int nk_do_button_text(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *string, int len, nk_flags align, enum nk_button_behavior behavior, - const struct nk_style_button *style, const struct nk_input *in, + const struct nk_style_button *style, struct nk_input *in, const struct nk_user_font *font) { struct nk_rect content; @@ -19890,7 +19929,7 @@ NK_LIB int nk_do_button_symbol(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, enum nk_symbol_type symbol, enum nk_button_behavior behavior, - const struct nk_style_button *style, const struct nk_input *in, + const struct nk_style_button *style, struct nk_input *in, const struct nk_user_font *font) { int ret; @@ -19921,7 +19960,7 @@ NK_LIB int nk_do_button_image(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, struct nk_image img, enum nk_button_behavior b, - const struct nk_style_button *style, const struct nk_input *in) + const struct nk_style_button *style, struct nk_input *in) { int ret; struct nk_rect content; @@ -19981,7 +20020,7 @@ 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) + const struct nk_user_font *font, struct nk_input *in) { int ret; struct nk_rect tri = {0,0,0,0}; @@ -20038,7 +20077,7 @@ 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) + const struct nk_user_font *font, struct nk_input *in) { int ret; struct nk_rect icon; @@ -20120,7 +20159,7 @@ nk_button_text_styled(struct nk_context *ctx, { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; struct nk_rect bounds; enum nk_widget_layout_states state; @@ -20162,7 +20201,7 @@ nk_button_color(struct nk_context *ctx, struct nk_color color) { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; struct nk_style_button button; int ret = 0; @@ -20198,7 +20237,7 @@ nk_button_symbol_styled(struct nk_context *ctx, { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; struct nk_rect bounds; enum nk_widget_layout_states state; @@ -20230,7 +20269,7 @@ nk_button_image_styled(struct nk_context *ctx, const struct nk_style_button *sty { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; struct nk_rect bounds; enum nk_widget_layout_states state; @@ -20264,7 +20303,7 @@ nk_button_symbol_text_styled(struct nk_context *ctx, { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; struct nk_rect bounds; enum nk_widget_layout_states state; @@ -20311,7 +20350,7 @@ nk_button_image_text_styled(struct nk_context *ctx, { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; struct nk_rect bounds; enum nk_widget_layout_states state; @@ -20360,7 +20399,7 @@ NK_API int nk_button_image_label_styled(struct nk_context *ctx, * * ===============================================================*/ NK_LIB int -nk_toggle_behavior(const struct nk_input *in, struct nk_rect select, +nk_toggle_behavior(struct nk_input *in, struct nk_rect select, nk_flags *state, int active) { nk_widget_state_reset(state); @@ -20405,6 +20444,7 @@ nk_draw_checkbox(struct nk_command_buffer *out, nk_fill_rect(out, *selector, 0, style->border_color); nk_fill_rect(out, nk_shrink_rect(*selector, style->border), 0, background->data.color); } else nk_draw_image(out, *selector, &background->data.image, nk_white); + if (active) { if (cursor->type == NK_STYLE_ITEM_IMAGE) nk_draw_image(out, *cursors, &cursor->data.image, nk_white); @@ -20444,13 +20484,13 @@ nk_draw_option(struct nk_command_buffer *out, /* draw background and cursor */ if (background->type == NK_STYLE_ITEM_COLOR) { - nk_fill_circle(out, *selector, style->border_color); - nk_fill_circle(out, nk_shrink_rect(*selector, style->border), background->data.color); + nk_stroke_circle(out, *selector, 1, background->data.color); } else nk_draw_image(out, *selector, &background->data.image, nk_white); + if (active) { if (cursor->type == NK_STYLE_ITEM_IMAGE) nk_draw_image(out, *cursors, &cursor->data.image, nk_white); - else nk_fill_circle(out, *cursors, cursor->data.color); + else nk_fill_circle(out, *cursors, background->data.color); } text.padding.x = 0; @@ -20462,7 +20502,7 @@ NK_LIB int nk_do_toggle(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r, int *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_style_toggle *style, struct nk_input *in, const struct nk_user_font *font) { int was_active; @@ -20530,7 +20570,7 @@ nk_check_text(struct nk_context *ctx, const char *text, int len, int active) { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; const struct nk_style *style; struct nk_rect bounds; @@ -20625,7 +20665,7 @@ nk_option_text(struct nk_context *ctx, const char *text, int len, int is_active) { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; const struct nk_style *style; struct nk_rect bounds; @@ -20732,7 +20772,7 @@ nk_draw_selectable(struct nk_command_buffer *out, NK_LIB int nk_do_selectable(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *str, int len, nk_flags align, int *value, - const struct nk_style_selectable *style, const struct nk_input *in, + const struct nk_style_selectable *style, struct nk_input *in, const struct nk_user_font *font) { int old_value; @@ -20769,7 +20809,7 @@ NK_LIB int nk_do_selectable_image(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *str, int len, nk_flags align, int *value, const struct nk_image *img, const struct nk_style_selectable *style, - const struct nk_input *in, const struct nk_user_font *font) + struct nk_input *in, const struct nk_user_font *font) { int old_value; struct nk_rect touch; @@ -20816,7 +20856,7 @@ NK_LIB int nk_do_selectable_symbol(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *str, int len, nk_flags align, int *value, enum nk_symbol_type sym, const struct nk_style_selectable *style, - const struct nk_input *in, const struct nk_user_font *font) + struct nk_input *in, const struct nk_user_font *font) { int old_value; struct nk_rect touch; @@ -20866,7 +20906,7 @@ nk_selectable_text(struct nk_context *ctx, const char *str, int len, { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; const struct nk_style *style; enum nk_widget_layout_states state; @@ -20895,7 +20935,7 @@ nk_selectable_image_text(struct nk_context *ctx, struct nk_image img, { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; const struct nk_style *style; enum nk_widget_layout_states state; @@ -20924,7 +20964,7 @@ nk_selectable_symbol_text(struct nk_context *ctx, enum nk_symbol_type sym, { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; const struct nk_style *style; enum nk_widget_layout_states state; @@ -23536,7 +23576,7 @@ nk_edit_string_zero_terminated(struct nk_context *ctx, nk_flags flags, * * ===============================================================*/ NK_LIB void -nk_drag_behavior(nk_flags *state, const struct nk_input *in, +nk_drag_behavior(nk_flags *state, struct nk_input *in, struct nk_rect drag, struct nk_property_variant *variant, float inc_per_pixel) { @@ -23575,7 +23615,7 @@ nk_drag_behavior(nk_flags *state, const struct nk_input *in, *state |= NK_WIDGET_STATE_LEFT; } NK_LIB void -nk_property_behavior(nk_flags *ws, const struct nk_input *in, +nk_property_behavior(nk_flags *ws, struct nk_input *in, struct nk_rect property, struct nk_rect label, struct nk_rect edit, struct nk_rect empty, int *state, struct nk_property_variant *variant, float inc_per_pixel) @@ -24132,7 +24172,7 @@ nk_chart_push_line(struct nk_context *ctx, struct nk_window *win, struct nk_chart *g, float value, int slot) { struct nk_panel *layout = win->layout; - const struct nk_input *i = &ctx->input; + struct nk_input *i = &ctx->input; struct nk_command_buffer *out = &win->buffer; nk_flags ret = 0; @@ -24354,7 +24394,7 @@ NK_LIB int 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) + struct nk_colorf *color, struct nk_input *in) { float hsva[4]; int value_changed = 0; @@ -24465,7 +24505,7 @@ NK_LIB int nk_do_color_picker(nk_flags *state, struct nk_command_buffer *out, struct nk_colorf *col, enum nk_color_format fmt, struct nk_rect bounds, - struct nk_vec2 padding, const struct nk_input *in, + struct nk_vec2 padding, struct nk_input *in, const struct nk_user_font *font) { int ret = 0; @@ -24514,7 +24554,7 @@ nk_color_pick(struct nk_context * ctx, struct nk_colorf *color, struct nk_window *win; struct nk_panel *layout; const struct nk_style *config; - const struct nk_input *in; + struct nk_input *in; enum nk_widget_layout_states state; struct nk_rect bounds; @@ -24590,7 +24630,7 @@ NK_API int nk_combo_begin_text(struct nk_context *ctx, const char *selected, int len, struct nk_vec2 size) { - const struct nk_input *in; + struct nk_input *in; struct nk_window *win; struct nk_style *style; @@ -24685,7 +24725,7 @@ nk_combo_begin_color(struct nk_context *ctx, struct nk_color color, struct nk_ve { struct nk_window *win; struct nk_style *style; - const struct nk_input *in; + struct nk_input *in; struct nk_rect header; int is_clicked = nk_false; @@ -24762,7 +24802,7 @@ nk_combo_begin_symbol(struct nk_context *ctx, enum nk_symbol_type symbol, struct { struct nk_window *win; struct nk_style *style; - const struct nk_input *in; + struct nk_input *in; struct nk_rect header; int is_clicked = nk_false; @@ -24945,7 +24985,7 @@ nk_combo_begin_image(struct nk_context *ctx, struct nk_image img, struct nk_vec2 { struct nk_window *win; struct nk_style *style; - const struct nk_input *in; + struct nk_input *in; struct nk_rect header; int is_clicked = nk_false; @@ -25321,7 +25361,7 @@ nk_tooltip_begin(struct nk_context *ctx, float width) { int x,y,w,h; struct nk_window *win; - const struct nk_input *in; + struct nk_input *in; struct nk_rect bounds; int ret; @@ -25476,6 +25516,11 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// - [yy]: Minor version with non-breaking API and library changes /// - [zz]: Bug fix version with no direct changes to API /// +/// - 2019/12/05 (4.01.8) - Fixed radio buttons' style. +/// - 2019/12/05 (4.01.7) - Fixed click cascading through multiple buttons; it should only click the upper button. +/// - 2019/12/11 (4.01.6) - Strict c++17 now compiles: only declaring memset, memcpy if they are used. +/// Only asserting index range if ushorts are used for indices. +/// Made paq.sh identical to paq.bat (outputs to nuklear.h). /// - 2019/12/10 (4.01.5) - Fix off-by-one error in NK_INTERSECT /// - 2019/10/09 (4.01.4) - Fix bug for autoscrolling in nk_do_edit /// - 2019/09/20 (4.01.3) - Fixed a bug wherein combobox cannot be closed by clicking the header diff --git a/package.json b/package.json index 27d698731..321b5f64e 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,14 @@ { "name": "nuklear", - "version": "4.01.5", + "version": "4.01.8", "repo": "Immediate-Mode-UI/Nuklear", "description": "A small ANSI C gui toolkit", - "keywords": ["gl", "ui", "toolkit"], - "src": ["nuklear.h"] + "keywords": [ + "gl", + "ui", + "toolkit" + ], + "src": [ + "nuklear.h" + ] } diff --git a/src/CHANGELOG b/src/CHANGELOG index 05a65d80c..8803d62b2 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -8,6 +8,11 @@ /// - [yy]: Minor version with non-breaking API and library changes /// - [zz]: Bug fix version with no direct changes to API /// +/// - 2019/12/05 (4.01.8) - Fixed radio buttons' style. +/// - 2019/12/05 (4.01.7) - Fixed click cascading through multiple buttons; it should only click the upper button. +/// - 2019/12/11 (4.01.6) - Strict c++17 now compiles: only declaring memset, memcpy if they are used. +/// Only asserting index range if ushorts are used for indices. +/// Made paq.sh identical to paq.bat (outputs to nuklear.h). /// - 2019/12/10 (4.01.5) - Fix off-by-one error in NK_INTERSECT /// - 2019/10/09 (4.01.4) - Fix bug for autoscrolling in nk_do_edit /// - 2019/09/20 (4.01.3) - Fixed a bug wherein combobox cannot be closed by clicking the header diff --git a/src/Readme.md b/src/Readme.md index 6a6f284ef..052906ceb 100644 --- a/src/Readme.md +++ b/src/Readme.md @@ -1,5 +1,5 @@ File Packer: ------------ - [Click to generate nuklear.h](http://apoorvaj.io/single-header-packer.html?macro=NK&pre=https://raw.githubusercontent.com/vurtun/nuklear/master/src/HEADER&pub=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear.h&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_internal.h&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_math.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_util.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_color.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_utf8.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_buffer.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_string.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_draw.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_vertex.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_font.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_input.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_style.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_context.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_pool.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_page_element.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_table.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_panel.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_window.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_popup.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_contextual.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_menu.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_layout.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_tree.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_group.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_list_view.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_widget.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_text.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_image.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_button.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_toggle.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_selectable.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_slider.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_progress.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_scrollbar.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_text_editor.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_edit.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_property.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_chart.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_color_picker.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_combo.c&priv=https://raw.githubusercontent.com/vurtun/nuklear/master/src/nuklear_tooltip.c&post=https://raw.githubusercontent.com/vurtun/nuklear/master/src/LICENSE&post=https://raw.githubusercontent.com/vurtun/nuklear/master/src/CHANGELOG&post=https://raw.githubusercontent.com/vurtun/nuklear/master/src/CREDITS) -- On Linux/Mac just run ./paq > ../nuklear.h +- On Linux/Mac just run ./paq.sh - On Windows just run paq.bat diff --git a/src/build.py b/src/build.py index aec4e2271..f0524b26b 100644 --- a/src/build.py +++ b/src/build.py @@ -1,7 +1,9 @@ import fnmatch import os.path -import sys +import sys, io + +sys.stdout = io.TextIOWrapper(sys.stdout.buffer, newline='\n' ) def print_help(): print( diff --git a/src/nuklear.h b/src/nuklear.h index 2a9f45d62..214f8dd09 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -4391,6 +4391,7 @@ struct nk_mouse { unsigned char grab; unsigned char grabbed; unsigned char ungrab; + unsigned char clicked; }; struct nk_key { diff --git a/src/nuklear_button.c b/src/nuklear_button.c index e40b2526e..de2a7788d 100644 --- a/src/nuklear_button.c +++ b/src/nuklear_button.c @@ -61,7 +61,7 @@ nk_draw_symbol(struct nk_command_buffer *out, enum nk_symbol_type type, } NK_LIB int nk_button_behavior(nk_flags *state, struct nk_rect r, - const struct nk_input *i, enum nk_button_behavior behavior) + struct nk_input *i, enum nk_button_behavior behavior) { int ret = 0; nk_widget_state_reset(state); @@ -78,6 +78,8 @@ nk_button_behavior(nk_flags *state, struct nk_rect r, #else nk_input_is_mouse_pressed(i, NK_BUTTON_LEFT); #endif + if (ret) + i->mouse.clicked = 1; } } if (*state & NK_WIDGET_STATE_HOVER && !nk_input_is_mouse_prev_hovering_rect(i, r)) @@ -108,7 +110,7 @@ nk_draw_button(struct nk_command_buffer *out, } NK_LIB int nk_do_button(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r, - const struct nk_style_button *style, const struct nk_input *in, + const struct nk_style_button *style, struct nk_input *in, enum nk_button_behavior behavior, struct nk_rect *content) { struct nk_rect bounds; @@ -158,7 +160,7 @@ NK_LIB int nk_do_button_text(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *string, int len, nk_flags align, enum nk_button_behavior behavior, - const struct nk_style_button *style, const struct nk_input *in, + const struct nk_style_button *style, struct nk_input *in, const struct nk_user_font *font) { struct nk_rect content; @@ -204,7 +206,7 @@ NK_LIB int nk_do_button_symbol(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, enum nk_symbol_type symbol, enum nk_button_behavior behavior, - const struct nk_style_button *style, const struct nk_input *in, + const struct nk_style_button *style, struct nk_input *in, const struct nk_user_font *font) { int ret; @@ -235,7 +237,7 @@ NK_LIB int nk_do_button_image(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, struct nk_image img, enum nk_button_behavior b, - const struct nk_style_button *style, const struct nk_input *in) + const struct nk_style_button *style, struct nk_input *in) { int ret; struct nk_rect content; @@ -295,7 +297,7 @@ 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) + const struct nk_user_font *font, struct nk_input *in) { int ret; struct nk_rect tri = {0,0,0,0}; @@ -352,7 +354,7 @@ 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) + const struct nk_user_font *font, struct nk_input *in) { int ret; struct nk_rect icon; @@ -434,7 +436,7 @@ nk_button_text_styled(struct nk_context *ctx, { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; struct nk_rect bounds; enum nk_widget_layout_states state; @@ -476,7 +478,7 @@ nk_button_color(struct nk_context *ctx, struct nk_color color) { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; struct nk_style_button button; int ret = 0; @@ -512,7 +514,7 @@ nk_button_symbol_styled(struct nk_context *ctx, { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; struct nk_rect bounds; enum nk_widget_layout_states state; @@ -544,7 +546,7 @@ nk_button_image_styled(struct nk_context *ctx, const struct nk_style_button *sty { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; struct nk_rect bounds; enum nk_widget_layout_states state; @@ -578,7 +580,7 @@ nk_button_symbol_text_styled(struct nk_context *ctx, { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; struct nk_rect bounds; enum nk_widget_layout_states state; @@ -625,7 +627,7 @@ nk_button_image_text_styled(struct nk_context *ctx, { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; struct nk_rect bounds; enum nk_widget_layout_states state; diff --git a/src/nuklear_chart.c b/src/nuklear_chart.c index bb5574f7a..acb6e9661 100644 --- a/src/nuklear_chart.c +++ b/src/nuklear_chart.c @@ -107,7 +107,7 @@ nk_chart_push_line(struct nk_context *ctx, struct nk_window *win, struct nk_chart *g, float value, int slot) { struct nk_panel *layout = win->layout; - const struct nk_input *i = &ctx->input; + struct nk_input *i = &ctx->input; struct nk_command_buffer *out = &win->buffer; nk_flags ret = 0; diff --git a/src/nuklear_color_picker.c b/src/nuklear_color_picker.c index 719748785..2b55355c5 100644 --- a/src/nuklear_color_picker.c +++ b/src/nuklear_color_picker.c @@ -10,7 +10,7 @@ NK_LIB int 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) + struct nk_colorf *color, struct nk_input *in) { float hsva[4]; int value_changed = 0; @@ -121,7 +121,7 @@ NK_LIB int nk_do_color_picker(nk_flags *state, struct nk_command_buffer *out, struct nk_colorf *col, enum nk_color_format fmt, struct nk_rect bounds, - struct nk_vec2 padding, const struct nk_input *in, + struct nk_vec2 padding, struct nk_input *in, const struct nk_user_font *font) { int ret = 0; @@ -170,7 +170,7 @@ nk_color_pick(struct nk_context * ctx, struct nk_colorf *color, struct nk_window *win; struct nk_panel *layout; const struct nk_style *config; - const struct nk_input *in; + struct nk_input *in; enum nk_widget_layout_states state; struct nk_rect bounds; diff --git a/src/nuklear_combo.c b/src/nuklear_combo.c index 26bf7e93e..1592d8ca3 100644 --- a/src/nuklear_combo.c +++ b/src/nuklear_combo.c @@ -44,7 +44,7 @@ NK_API int nk_combo_begin_text(struct nk_context *ctx, const char *selected, int len, struct nk_vec2 size) { - const struct nk_input *in; + struct nk_input *in; struct nk_window *win; struct nk_style *style; @@ -139,7 +139,7 @@ nk_combo_begin_color(struct nk_context *ctx, struct nk_color color, struct nk_ve { struct nk_window *win; struct nk_style *style; - const struct nk_input *in; + struct nk_input *in; struct nk_rect header; int is_clicked = nk_false; @@ -216,7 +216,7 @@ nk_combo_begin_symbol(struct nk_context *ctx, enum nk_symbol_type symbol, struct { struct nk_window *win; struct nk_style *style; - const struct nk_input *in; + struct nk_input *in; struct nk_rect header; int is_clicked = nk_false; @@ -399,7 +399,7 @@ nk_combo_begin_image(struct nk_context *ctx, struct nk_image img, struct nk_vec2 { struct nk_window *win; struct nk_style *style; - const struct nk_input *in; + struct nk_input *in; struct nk_rect header; int is_clicked = nk_false; diff --git a/src/nuklear_contextual.c b/src/nuklear_contextual.c index 5c88c2e2c..50202d76c 100644 --- a/src/nuklear_contextual.c +++ b/src/nuklear_contextual.c @@ -70,7 +70,7 @@ nk_contextual_item_text(struct nk_context *ctx, const char *text, int len, nk_flags alignment) { struct nk_window *win; - const struct nk_input *in; + struct nk_input *in; const struct nk_style *style; struct nk_rect bounds; @@ -105,7 +105,7 @@ nk_contextual_item_image_text(struct nk_context *ctx, struct nk_image img, const char *text, int len, nk_flags align) { struct nk_window *win; - const struct nk_input *in; + struct nk_input *in; const struct nk_style *style; struct nk_rect bounds; @@ -141,7 +141,7 @@ nk_contextual_item_symbol_text(struct nk_context *ctx, enum nk_symbol_type symbo const char *text, int len, nk_flags align) { struct nk_window *win; - const struct nk_input *in; + struct nk_input *in; const struct nk_style *style; struct nk_rect bounds; diff --git a/src/nuklear_input.c b/src/nuklear_input.c index 563b5decb..b3dded068 100644 --- a/src/nuklear_input.c +++ b/src/nuklear_input.c @@ -23,6 +23,11 @@ nk_input_begin(struct nk_context *ctx) in->mouse.prev.y = in->mouse.pos.y; in->mouse.delta.x = 0; in->mouse.delta.y = 0; + + #if defined(NK_KEYSTATE_BASED_INPUT) || defined(NK_BUTTON_TRIGGER_ON_RELEASE) + in->mouse.clicked = 0; + #endif + for (i = 0; i < NK_KEY_MAX; i++) in->keyboard.keys[i].clicked = 0; } @@ -79,6 +84,14 @@ nk_input_button(struct nk_context *ctx, enum nk_buttons id, int x, int y, int do if (in->mouse.buttons[id].down == down) return; btn = &in->mouse.buttons[id]; + + #ifndef NK_BUTTON_TRIGGER_ON_RELEASE + + if(id == NK_BUTTON_LEFT && !down) + in->mouse.clicked = 0; + + #endif + btn->clicked_pos.x = (float)x; btn->clicked_pos.y = (float)y; btn->down = down; @@ -141,7 +154,7 @@ nk_input_has_mouse_click_in_rect(const struct nk_input *i, enum nk_buttons id, struct nk_rect b) { const struct nk_mouse_button *btn; - if (!i) return nk_false; + if (!i || i->mouse.clicked) return nk_false; btn = &i->mouse.buttons[id]; if (!NK_INBOX(btn->clicked_pos.x,btn->clicked_pos.y,b.x,b.y,b.w,b.h)) return nk_false; @@ -215,7 +228,7 @@ nk_input_is_mouse_pressed(const struct nk_input *i, enum nk_buttons id) const struct nk_mouse_button *b; if (!i) return nk_false; b = &i->mouse.buttons[id]; - if (b->down && b->clicked) + if (b->down && b->clicked && !i->mouse.clicked) return nk_true; return nk_false; } @@ -223,7 +236,7 @@ NK_API int nk_input_is_mouse_released(const struct nk_input *i, enum nk_buttons id) { if (!i) return nk_false; - return (!i->mouse.buttons[id].down && i->mouse.buttons[id].clicked); + return (!i->mouse.buttons[id].down && !(i->mouse.buttons[id].clicked && !i->mouse.clicked)); } NK_API int nk_input_is_key_pressed(const struct nk_input *i, enum nk_keys key) diff --git a/src/nuklear_internal.h b/src/nuklear_internal.h index 5aac1708c..ab3c9abb7 100644 --- a/src/nuklear_internal.h +++ b/src/nuklear_internal.h @@ -30,9 +30,11 @@ #ifndef NK_MEMSET #define NK_MEMSET nk_memset +#define NK_MEMSET_BUILTIN #endif #ifndef NK_MEMCPY #define NK_MEMCPY nk_memcopy +#define NK_MEMCPY_BUILTIN #endif #ifndef NK_SQRT #define NK_SQRT nk_sqrt @@ -131,8 +133,15 @@ NK_LIB int nk_is_lower(int c); NK_LIB int nk_is_upper(int c); NK_LIB int nk_to_upper(int c); NK_LIB int nk_to_lower(int c); + +#ifdef NK_MEMCPY_BUILTIN NK_LIB void* nk_memcopy(void *dst, const void *src, nk_size n); +#endif + +#ifdef NK_MEMSET_BUILTIN NK_LIB void nk_memset(void *ptr, int c0, nk_size size); +#endif + NK_LIB void nk_zero(void *ptr, nk_size size); NK_LIB char *nk_itoa(char *s, long n); NK_LIB int nk_string_float_limit(char *string, int prec); @@ -240,29 +249,29 @@ NK_LIB void nk_widget_text(struct nk_command_buffer *o, struct nk_rect b, const NK_LIB void nk_widget_text_wrap(struct nk_command_buffer *o, struct nk_rect b, const char *string, int len, const struct nk_text *t, const struct nk_user_font *f); /* button */ -NK_LIB int nk_button_behavior(nk_flags *state, struct nk_rect r, const struct nk_input *i, enum nk_button_behavior behavior); +NK_LIB int nk_button_behavior(nk_flags *state, struct nk_rect r, struct nk_input *i, enum nk_button_behavior behavior); NK_LIB const struct nk_style_item* nk_draw_button(struct nk_command_buffer *out, const struct nk_rect *bounds, nk_flags state, const struct nk_style_button *style); -NK_LIB int nk_do_button(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r, const struct nk_style_button *style, const struct nk_input *in, enum nk_button_behavior behavior, struct nk_rect *content); +NK_LIB int nk_do_button(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r, const struct nk_style_button *style, struct nk_input *in, enum nk_button_behavior behavior, struct nk_rect *content); NK_LIB void nk_draw_button_text(struct nk_command_buffer *out, const struct nk_rect *bounds, const struct nk_rect *content, nk_flags state, const struct nk_style_button *style, const char *txt, int len, nk_flags text_alignment, const struct nk_user_font *font); -NK_LIB int nk_do_button_text(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *string, int len, nk_flags align, enum nk_button_behavior behavior, const struct nk_style_button *style, const struct nk_input *in, const struct nk_user_font *font); +NK_LIB int nk_do_button_text(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *string, int len, nk_flags align, enum nk_button_behavior behavior, const struct nk_style_button *style, struct nk_input *in, const struct nk_user_font *font); NK_LIB void nk_draw_button_symbol(struct nk_command_buffer *out, const struct nk_rect *bounds, const struct nk_rect *content, nk_flags state, const struct nk_style_button *style, enum nk_symbol_type type, const struct nk_user_font *font); -NK_LIB int nk_do_button_symbol(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, enum nk_symbol_type symbol, enum nk_button_behavior behavior, const struct nk_style_button *style, const struct nk_input *in, const struct nk_user_font *font); +NK_LIB int nk_do_button_symbol(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, enum nk_symbol_type symbol, enum nk_button_behavior behavior, const struct nk_style_button *style, struct nk_input *in, const struct nk_user_font *font); NK_LIB void nk_draw_button_image(struct nk_command_buffer *out, const struct nk_rect *bounds, const struct nk_rect *content, nk_flags state, const struct nk_style_button *style, const struct nk_image *img); -NK_LIB int nk_do_button_image(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, struct nk_image img, enum nk_button_behavior b, const struct nk_style_button *style, const struct nk_input *in); +NK_LIB int nk_do_button_image(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, struct nk_image img, enum nk_button_behavior b, const struct nk_style_button *style, struct nk_input *in); NK_LIB void nk_draw_button_text_symbol(struct nk_command_buffer *out, const struct nk_rect *bounds, const struct nk_rect *label, const struct nk_rect *symbol, nk_flags state, const struct nk_style_button *style, const char *str, int len, enum nk_symbol_type type, const struct nk_user_font *font); -NK_LIB int 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); +NK_LIB int 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, struct nk_input *in); NK_LIB void nk_draw_button_text_image(struct nk_command_buffer *out, const struct nk_rect *bounds, const struct nk_rect *label, const struct nk_rect *image, nk_flags state, const struct nk_style_button *style, const char *str, int len, const struct nk_user_font *font, const struct nk_image *img); -NK_LIB int 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); +NK_LIB int 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, struct nk_input *in); /* toggle */ enum nk_toggle_type { NK_TOGGLE_CHECK, NK_TOGGLE_OPTION }; -NK_LIB int nk_toggle_behavior(const struct nk_input *in, struct nk_rect select, nk_flags *state, int active); +NK_LIB int nk_toggle_behavior(struct nk_input *in, struct nk_rect select, nk_flags *state, int active); NK_LIB void nk_draw_checkbox(struct nk_command_buffer *out, nk_flags state, const struct nk_style_toggle *style, int 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_LIB void nk_draw_option(struct nk_command_buffer *out, nk_flags state, const struct nk_style_toggle *style, int 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_LIB int nk_do_toggle(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r, int *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_LIB int nk_do_toggle(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r, int *active, const char *str, int len, enum nk_toggle_type type, const struct nk_style_toggle *style, struct nk_input *in, const struct nk_user_font *font); /* progress */ 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, int modifiable); @@ -282,17 +291,17 @@ NK_LIB float nk_do_scrollbarh(nk_flags *state, struct nk_command_buffer *out, st /* selectable */ NK_LIB void nk_draw_selectable(struct nk_command_buffer *out, nk_flags state, const struct nk_style_selectable *style, int 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); -NK_LIB int nk_do_selectable(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *str, int len, nk_flags align, int *value, const struct nk_style_selectable *style, const struct nk_input *in, const struct nk_user_font *font); -NK_LIB int nk_do_selectable_image(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *str, int len, nk_flags align, int *value, const struct nk_image *img, const struct nk_style_selectable *style, const struct nk_input *in, const struct nk_user_font *font); +NK_LIB int nk_do_selectable(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *str, int len, nk_flags align, int *value, const struct nk_style_selectable *style, struct nk_input *in, const struct nk_user_font *font); +NK_LIB int nk_do_selectable_image(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *str, int len, nk_flags align, int *value, const struct nk_image *img, const struct nk_style_selectable *style, struct nk_input *in, const struct nk_user_font *font); /* edit */ 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, int is_selected); NK_LIB nk_flags nk_do_edit(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, nk_flags flags, nk_plugin_filter filter, struct nk_text_edit *edit, const struct nk_style_edit *style, struct nk_input *in, const struct nk_user_font *font); /* color-picker */ -NK_LIB int 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); +NK_LIB int 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, struct nk_input *in); NK_LIB void nk_draw_color_picker(struct nk_command_buffer *o, const struct nk_rect *matrix, const struct nk_rect *hue_bar, const struct nk_rect *alpha_bar, struct nk_colorf col); -NK_LIB int nk_do_color_picker(nk_flags *state, struct nk_command_buffer *out, struct nk_colorf *col, enum nk_color_format fmt, struct nk_rect bounds, struct nk_vec2 padding, const struct nk_input *in, const struct nk_user_font *font); +NK_LIB int nk_do_color_picker(nk_flags *state, struct nk_command_buffer *out, struct nk_colorf *col, enum nk_color_format fmt, struct nk_rect bounds, struct nk_vec2 padding, struct nk_input *in, const struct nk_user_font *font); /* property */ enum nk_property_status { @@ -325,8 +334,8 @@ NK_LIB struct nk_property_variant nk_property_variant_int(int value, int min_val NK_LIB struct nk_property_variant nk_property_variant_float(float value, float min_value, float max_value, float step); NK_LIB struct nk_property_variant nk_property_variant_double(double value, double min_value, double max_value, double step); -NK_LIB void nk_drag_behavior(nk_flags *state, const struct nk_input *in, struct nk_rect drag, struct nk_property_variant *variant, float inc_per_pixel); -NK_LIB void nk_property_behavior(nk_flags *ws, const struct nk_input *in, struct nk_rect property, struct nk_rect label, struct nk_rect edit, struct nk_rect empty, int *state, struct nk_property_variant *variant, float inc_per_pixel); +NK_LIB void nk_drag_behavior(nk_flags *state, struct nk_input *in, struct nk_rect drag, struct nk_property_variant *variant, float inc_per_pixel); +NK_LIB void nk_property_behavior(nk_flags *ws, struct nk_input *in, struct nk_rect property, struct nk_rect label, struct nk_rect edit, struct nk_rect empty, int *state, struct nk_property_variant *variant, float inc_per_pixel); NK_LIB void nk_draw_property(struct nk_command_buffer *out, const struct nk_style_property *style, const struct nk_rect *bounds, const struct nk_rect *label, nk_flags state, const char *name, int len, const struct nk_user_font *font); 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); NK_LIB void nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant *variant, float inc_per_pixel, const enum nk_property_filter filter); diff --git a/src/nuklear_menu.c b/src/nuklear_menu.c index 5b2879e0c..6e7a88e22 100644 --- a/src/nuklear_menu.c +++ b/src/nuklear_menu.c @@ -112,7 +112,7 @@ nk_menu_begin_text(struct nk_context *ctx, const char *title, int len, nk_flags align, struct nk_vec2 size) { struct nk_window *win; - const struct nk_input *in; + struct nk_input *in; struct nk_rect header; int is_clicked = nk_false; nk_flags state; @@ -143,7 +143,7 @@ nk_menu_begin_image(struct nk_context *ctx, const char *id, struct nk_image img, { struct nk_window *win; struct nk_rect header; - const struct nk_input *in; + struct nk_input *in; int is_clicked = nk_false; nk_flags state; @@ -167,7 +167,7 @@ nk_menu_begin_symbol(struct nk_context *ctx, const char *id, enum nk_symbol_type sym, struct nk_vec2 size) { struct nk_window *win; - const struct nk_input *in; + struct nk_input *in; struct nk_rect header; int is_clicked = nk_false; nk_flags state; @@ -193,7 +193,7 @@ nk_menu_begin_image_text(struct nk_context *ctx, const char *title, int len, { struct nk_window *win; struct nk_rect header; - const struct nk_input *in; + struct nk_input *in; int is_clicked = nk_false; nk_flags state; @@ -225,7 +225,7 @@ nk_menu_begin_symbol_text(struct nk_context *ctx, const char *title, int len, { struct nk_window *win; struct nk_rect header; - const struct nk_input *in; + struct nk_input *in; int is_clicked = nk_false; nk_flags state; diff --git a/src/nuklear_property.c b/src/nuklear_property.c index e7c33df07..2110a6186 100644 --- a/src/nuklear_property.c +++ b/src/nuklear_property.c @@ -7,7 +7,7 @@ * * ===============================================================*/ NK_LIB void -nk_drag_behavior(nk_flags *state, const struct nk_input *in, +nk_drag_behavior(nk_flags *state, struct nk_input *in, struct nk_rect drag, struct nk_property_variant *variant, float inc_per_pixel) { @@ -46,7 +46,7 @@ nk_drag_behavior(nk_flags *state, const struct nk_input *in, *state |= NK_WIDGET_STATE_LEFT; } NK_LIB void -nk_property_behavior(nk_flags *ws, const struct nk_input *in, +nk_property_behavior(nk_flags *ws, struct nk_input *in, struct nk_rect property, struct nk_rect label, struct nk_rect edit, struct nk_rect empty, int *state, struct nk_property_variant *variant, float inc_per_pixel) diff --git a/src/nuklear_selectable.c b/src/nuklear_selectable.c index 0d00acd14..890aab204 100644 --- a/src/nuklear_selectable.c +++ b/src/nuklear_selectable.c @@ -58,7 +58,7 @@ nk_draw_selectable(struct nk_command_buffer *out, NK_LIB int nk_do_selectable(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *str, int len, nk_flags align, int *value, - const struct nk_style_selectable *style, const struct nk_input *in, + const struct nk_style_selectable *style, struct nk_input *in, const struct nk_user_font *font) { int old_value; @@ -95,7 +95,7 @@ NK_LIB int nk_do_selectable_image(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *str, int len, nk_flags align, int *value, const struct nk_image *img, const struct nk_style_selectable *style, - const struct nk_input *in, const struct nk_user_font *font) + struct nk_input *in, const struct nk_user_font *font) { int old_value; struct nk_rect touch; @@ -142,7 +142,7 @@ NK_LIB int nk_do_selectable_symbol(nk_flags *state, struct nk_command_buffer *out, struct nk_rect bounds, const char *str, int len, nk_flags align, int *value, enum nk_symbol_type sym, const struct nk_style_selectable *style, - const struct nk_input *in, const struct nk_user_font *font) + struct nk_input *in, const struct nk_user_font *font) { int old_value; struct nk_rect touch; @@ -192,7 +192,7 @@ nk_selectable_text(struct nk_context *ctx, const char *str, int len, { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; const struct nk_style *style; enum nk_widget_layout_states state; @@ -221,7 +221,7 @@ nk_selectable_image_text(struct nk_context *ctx, struct nk_image img, { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; const struct nk_style *style; enum nk_widget_layout_states state; @@ -250,7 +250,7 @@ nk_selectable_symbol_text(struct nk_context *ctx, enum nk_symbol_type sym, { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; const struct nk_style *style; enum nk_widget_layout_states state; diff --git a/src/nuklear_toggle.c b/src/nuklear_toggle.c index 8f4ced27d..bf5490c4b 100644 --- a/src/nuklear_toggle.c +++ b/src/nuklear_toggle.c @@ -7,7 +7,7 @@ * * ===============================================================*/ NK_LIB int -nk_toggle_behavior(const struct nk_input *in, struct nk_rect select, +nk_toggle_behavior(struct nk_input *in, struct nk_rect select, nk_flags *state, int active) { nk_widget_state_reset(state); @@ -52,6 +52,7 @@ nk_draw_checkbox(struct nk_command_buffer *out, nk_fill_rect(out, *selector, 0, style->border_color); nk_fill_rect(out, nk_shrink_rect(*selector, style->border), 0, background->data.color); } else nk_draw_image(out, *selector, &background->data.image, nk_white); + if (active) { if (cursor->type == NK_STYLE_ITEM_IMAGE) nk_draw_image(out, *cursors, &cursor->data.image, nk_white); @@ -91,13 +92,13 @@ nk_draw_option(struct nk_command_buffer *out, /* draw background and cursor */ if (background->type == NK_STYLE_ITEM_COLOR) { - nk_fill_circle(out, *selector, style->border_color); - nk_fill_circle(out, nk_shrink_rect(*selector, style->border), background->data.color); + nk_stroke_circle(out, *selector, 1, background->data.color); } else nk_draw_image(out, *selector, &background->data.image, nk_white); + if (active) { if (cursor->type == NK_STYLE_ITEM_IMAGE) nk_draw_image(out, *cursors, &cursor->data.image, nk_white); - else nk_fill_circle(out, *cursors, cursor->data.color); + else nk_fill_circle(out, *cursors, background->data.color); } text.padding.x = 0; @@ -109,7 +110,7 @@ NK_LIB int nk_do_toggle(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r, int *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_style_toggle *style, struct nk_input *in, const struct nk_user_font *font) { int was_active; @@ -177,7 +178,7 @@ nk_check_text(struct nk_context *ctx, const char *text, int len, int active) { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; const struct nk_style *style; struct nk_rect bounds; @@ -272,7 +273,7 @@ nk_option_text(struct nk_context *ctx, const char *text, int len, int is_active) { struct nk_window *win; struct nk_panel *layout; - const struct nk_input *in; + struct nk_input *in; const struct nk_style *style; struct nk_rect bounds; diff --git a/src/nuklear_tooltip.c b/src/nuklear_tooltip.c index c4ce1fee2..388fc1b7f 100644 --- a/src/nuklear_tooltip.c +++ b/src/nuklear_tooltip.c @@ -11,7 +11,7 @@ nk_tooltip_begin(struct nk_context *ctx, float width) { int x,y,w,h; struct nk_window *win; - const struct nk_input *in; + struct nk_input *in; struct nk_rect bounds; int ret; diff --git a/src/nuklear_tree.c b/src/nuklear_tree.c index a0cc3de5f..4e0ea04a4 100644 --- a/src/nuklear_tree.c +++ b/src/nuklear_tree.c @@ -14,7 +14,7 @@ nk_tree_state_base(struct nk_context *ctx, enum nk_tree_type type, struct nk_panel *layout; const struct nk_style *style; struct nk_command_buffer *out; - const struct nk_input *in; + struct nk_input *in; const struct nk_style_button *button; enum nk_symbol_type symbol; float row_height; @@ -195,7 +195,7 @@ nk_tree_element_image_push_hashed_base(struct nk_context *ctx, enum nk_tree_type struct nk_panel *layout; const struct nk_style *style; struct nk_command_buffer *out; - const struct nk_input *in; + struct nk_input *in; const struct nk_style_button *button; enum nk_symbol_type symbol; float row_height; @@ -338,4 +338,3 @@ nk_tree_element_pop(struct nk_context *ctx) { nk_tree_state_pop(ctx); } - diff --git a/src/nuklear_util.c b/src/nuklear_util.c index 6379adf18..34c28da17 100644 --- a/src/nuklear_util.c +++ b/src/nuklear_util.c @@ -13,6 +13,8 @@ NK_LIB int nk_is_upper(int c){return (c >= 'A' && c <= 'Z') || (c >= 0xC0 && c < NK_LIB int nk_to_upper(int c) {return (c >= 'a' && c <= 'z') ? (c - ('a' - 'A')) : c;} NK_LIB int nk_to_lower(int c) {return (c >= 'A' && c <= 'Z') ? (c - ('a' + 'A')) : c;} +#ifdef NK_MEMCPY_BUILTIN + NK_LIB void* nk_memcopy(void *dst0, const void *src0, nk_size length) { @@ -69,6 +71,11 @@ nk_memcopy(void *dst0, const void *src0, nk_size length) done: return (dst0); } + +#endif + +#ifdef NK_MEMSET_BUILTIN + NK_LIB void nk_memset(void *ptr, int c0, nk_size size) { @@ -120,6 +127,9 @@ nk_memset(void *ptr, int c0, nk_size size) #undef nk_wsize #undef nk_wmask } + +#endif + NK_LIB void nk_zero(void *ptr, nk_size size) { diff --git a/src/nuklear_vertex.c b/src/nuklear_vertex.c index 8e94f889c..143deeecd 100644 --- a/src/nuklear_vertex.c +++ b/src/nuklear_vertex.c @@ -224,6 +224,8 @@ nk_draw_list_alloc_vertices(struct nk_draw_list *list, nk_size count) if (!vtx) return 0; list->vertex_count += (unsigned int)count; + #ifndef NK_UINT_DRAW_INDEX + /* This assert triggers because your are drawing a lot of stuff and nuklear * defined `nk_draw_index` as `nk_ushort` to safe space be default. * @@ -233,8 +235,11 @@ nk_draw_list_alloc_vertices(struct nk_draw_list *list, nk_size count) * backend (OpenGL, DirectX, ...). For example in OpenGL for `glDrawElements` * instead of specifing `GL_UNSIGNED_SHORT` you have to define `GL_UNSIGNED_INT`. * Sorry for the inconvenience. */ - if(sizeof(nk_draw_index)==2) NK_ASSERT((list->vertex_count < NK_USHORT_MAX && + NK_ASSERT((list->vertex_count < NK_USHORT_MAX && "To many verticies for 16-bit vertex indicies. Please read comment above on how to solve this problem")); + + #endif + return vtx; } NK_INTERN nk_draw_index* diff --git a/src/paq.sh b/src/paq.sh index 53b8552fc..ea2c0149a 100755 --- a/src/paq.sh +++ b/src/paq.sh @@ -1,3 +1,2 @@ #!/bin/sh -python build.py --macro NK --intro HEADER --pub nuklear.h --priv nuklear_internal.h,nuklear_math.c,nuklear_util.c,nuklear_color.c,nuklear_utf8.c,nuklear_buffer.c,nuklear_string.c,nuklear_draw.c,nuklear_vertex.c,nuklear_font.c,nuklear_input.c,nuklear_style.c,nuklear_context.c,nuklear_pool.c,nuklear_page_element.c,nuklear_table.c,nuklear_panel.c,nuklear_window.c,nuklear_popup.c,nuklear_contextual.c,nuklear_menu.c,nuklear_layout.c,nuklear_tree.c,nuklear_group.c,nuklear_list_view.c,nuklear_widget.c,nuklear_text.c,nuklear_image.c,nuklear_button.c,nuklear_toggle.c,nuklear_selectable.c,nuklear_slider.c,nuklear_progress.c,nuklear_scrollbar.c,nuklear_text_editor.c,nuklear_edit.c,nuklear_property.c,nuklear_chart.c,nuklear_color_picker.c,nuklear_combo.c,nuklear_tooltip.c --outro LICENSE,CHANGELOG,CREDITS - +python build.py --macro NK --intro HEADER --pub nuklear.h --priv nuklear_internal.h,nuklear_math.c,nuklear_util.c,nuklear_color.c,nuklear_utf8.c,nuklear_buffer.c,nuklear_string.c,nuklear_draw.c,nuklear_vertex.c,nuklear_font.c,nuklear_input.c,nuklear_style.c,nuklear_context.c,nuklear_pool.c,nuklear_page_element.c,nuklear_table.c,nuklear_panel.c,nuklear_window.c,nuklear_popup.c,nuklear_contextual.c,nuklear_menu.c,nuklear_layout.c,nuklear_tree.c,nuklear_group.c,nuklear_list_view.c,nuklear_widget.c,nuklear_text.c,nuklear_image.c,nuklear_button.c,nuklear_toggle.c,nuklear_selectable.c,nuklear_slider.c,nuklear_progress.c,nuklear_scrollbar.c,nuklear_text_editor.c,nuklear_edit.c,nuklear_property.c,nuklear_chart.c,nuklear_color_picker.c,nuklear_combo.c,nuklear_tooltip.c --outro LICENSE,CHANGELOG,CREDITS > ../nuklear.h