From 48ab7b2a7c37df25b98daa624b958b8f0ab47b4a Mon Sep 17 00:00:00 2001 From: Anton Afanasyev Date: Sat, 5 Sep 2020 09:14:41 -0700 Subject: [PATCH 1/3] paq: Pipe output to file --- src/paq.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/paq.sh b/src/paq.sh index 1eb05a4..37d9d69 100755 --- a/src/paq.sh +++ b/src/paq.sh @@ -1,3 +1,3 @@ #!/bin/sh -python build.py --macro NK --intro HEADER --pub nuklear.h --priv1 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 --extern stb_rect_pack.h,stb_truetype.h --priv2 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 --priv1 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 --extern stb_rect_pack.h,stb_truetype.h --priv2 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 From ea3bb68e2a57370f044b8dd5eed95a99b04807f7 Mon Sep 17 00:00:00 2001 From: Anton Afanasyev Date: Sat, 5 Sep 2020 09:11:12 -0700 Subject: [PATCH 2/3] Use the nk_font_atlas's allocator for stb_truetype memory management by default And allow the consumer to customize by redefining STBTT_malloc/STBTT_free --- nuklear.h | 43 +++++++++++++++++++++++++++++------------- package.json | 2 +- src/CHANGELOG | 1 + src/nuklear.h | 12 ------------ src/nuklear_font.c | 4 +++- src/nuklear_internal.h | 26 +++++++++++++++++++++++++ 6 files changed, 61 insertions(+), 27 deletions(-) diff --git a/nuklear.h b/nuklear.h index 2388993..6631ccb 100644 --- a/nuklear.h +++ b/nuklear.h @@ -5701,18 +5701,6 @@ template struct nk_alignof{struct Big {T x; char c;}; enum { #define NK_ALIGNOF(t) ((char*)(&((struct {char c; t _h;}*)0)->_h) - (char*)0) #endif -#ifdef NK_IMPLEMENTATION -#define STB_RECT_PACK_IMPLEMENTATION -#define STB_TRUETYPE_IMPLEMENTATION -#endif - -#ifndef STBTT_malloc -static nk_handle fictional_handle = {0}; - -#define STBTT_malloc(x,u) nk_malloc( fictional_handle, 0, x ) -#define STBTT_free(x,u) nk_mfree( fictional_handle , x) -#endif - #endif /* NK_NUKLEAR_H_ */ #ifdef NK_IMPLEMENTATION @@ -6043,6 +6031,32 @@ NK_LIB void nk_draw_property(struct nk_command_buffer *out, const struct nk_styl 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); +#ifdef NK_INCLUDE_FONT_BAKING + +#define STB_RECT_PACK_IMPLEMENTATION +#define STB_TRUETYPE_IMPLEMENTATION + +/* Allow consumer to define own STBTT_malloc/STBTT_free, and use the font atlas' allocator otherwise */ +#ifndef STBTT_malloc +static void* +nk_stbtt_malloc(nk_size size, void *user_data) { + struct nk_allocator *alloc = (struct nk_allocator *) user_data; + return alloc->alloc(alloc->userdata, 0, size); +} + +static void +nk_stbtt_free(void *ptr, void *user_data) { + struct nk_allocator *alloc = (struct nk_allocator *) user_data; + alloc->free(alloc->userdata, ptr); +} + +#define STBTT_malloc(x,u) nk_stbtt_malloc(x,u) +#define STBTT_free(x,u) nk_stbtt_free(x,u) + +#endif // STBTT_malloc + +#endif // NK_INCLUDE_FONT_BAKING + #endif @@ -16419,7 +16433,9 @@ nk_font_bake_pack(struct nk_font_baker *baker, /* setup font baker from temporary memory */ for (config_iter = config_list; config_iter; config_iter = config_iter->next) { it = config_iter; - do {if (!stbtt_InitFont(&baker->build[i++].info, (const unsigned char*)it->ttf_blob, 0)) + struct stbtt_fontinfo *font_info = &baker->build[i++].info; + font_info->userdata = alloc; + do {if (!stbtt_InitFont(font_info, (const unsigned char*)it->ttf_blob, 0)) return nk_false; } while ((it = it->n) != config_iter); } @@ -29154,6 +29170,7 @@ 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 /// +/// - 2020/09/05 (4.05.0) - Use the nk_font_atlas allocator for stb_truetype memory management. /// - 2020/09/04 (4.04.1) - Replace every boolean int by nk_bool /// - 2020/09/04 (4.04.0) - Add nk_bool with NK_INCLUDE_STANDARD_BOOL /// - 2020/06/13 (4.03.1) - Fix nk_pool allocation sizes. diff --git a/package.json b/package.json index 4d05181..521f5e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nuklear", - "version": "4.03.1", + "version": "4.05.0", "repo": "Immediate-Mode-UI/Nuklear", "description": "A small ANSI C gui toolkit", "keywords": ["gl", "ui", "toolkit"], diff --git a/src/CHANGELOG b/src/CHANGELOG index 28ce2ca..28cc9e3 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -8,6 +8,7 @@ /// - [yy]: Minor version with non-breaking API and library changes /// - [zz]: Bug fix version with no direct changes to API /// +/// - 2020/09/05 (4.05.0) - Use the nk_font_atlas allocator for stb_truetype memory management. /// - 2020/09/04 (4.04.1) - Replace every boolean int by nk_bool /// - 2020/09/04 (4.04.0) - Add nk_bool with NK_INCLUDE_STANDARD_BOOL /// - 2020/06/13 (4.03.1) - Fix nk_pool allocation sizes. diff --git a/src/nuklear.h b/src/nuklear.h index d0a8f78..cb934aa 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -5480,16 +5480,4 @@ template struct nk_alignof{struct Big {T x; char c;}; enum { #define NK_ALIGNOF(t) ((char*)(&((struct {char c; t _h;}*)0)->_h) - (char*)0) #endif -#ifdef NK_IMPLEMENTATION -#define STB_RECT_PACK_IMPLEMENTATION -#define STB_TRUETYPE_IMPLEMENTATION -#endif - -#ifndef STBTT_malloc -static nk_handle fictional_handle = {0}; - -#define STBTT_malloc(x,u) nk_malloc( fictional_handle, 0, x ) -#define STBTT_free(x,u) nk_mfree( fictional_handle , x) -#endif - #endif /* NK_NUKLEAR_H_ */ diff --git a/src/nuklear_font.c b/src/nuklear_font.c index afe0846..35d94ac 100644 --- a/src/nuklear_font.c +++ b/src/nuklear_font.c @@ -190,7 +190,9 @@ nk_font_bake_pack(struct nk_font_baker *baker, /* setup font baker from temporary memory */ for (config_iter = config_list; config_iter; config_iter = config_iter->next) { it = config_iter; - do {if (!stbtt_InitFont(&baker->build[i++].info, (const unsigned char*)it->ttf_blob, 0)) + struct stbtt_fontinfo *font_info = &baker->build[i++].info; + font_info->userdata = alloc; + do {if (!stbtt_InitFont(font_info, (const unsigned char*)it->ttf_blob, 0)) return nk_false; } while ((it = it->n) != config_iter); } diff --git a/src/nuklear_internal.h b/src/nuklear_internal.h index 4291100..3da5715 100644 --- a/src/nuklear_internal.h +++ b/src/nuklear_internal.h @@ -324,5 +324,31 @@ NK_LIB void nk_draw_property(struct nk_command_buffer *out, const struct nk_styl 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); +#ifdef NK_INCLUDE_FONT_BAKING + +#define STB_RECT_PACK_IMPLEMENTATION +#define STB_TRUETYPE_IMPLEMENTATION + +/* Allow consumer to define own STBTT_malloc/STBTT_free, and use the font atlas' allocator otherwise */ +#ifndef STBTT_malloc +static void* +nk_stbtt_malloc(nk_size size, void *user_data) { + struct nk_allocator *alloc = (struct nk_allocator *) user_data; + return alloc->alloc(alloc->userdata, 0, size); +} + +static void +nk_stbtt_free(void *ptr, void *user_data) { + struct nk_allocator *alloc = (struct nk_allocator *) user_data; + alloc->free(alloc->userdata, ptr); +} + +#define STBTT_malloc(x,u) nk_stbtt_malloc(x,u) +#define STBTT_free(x,u) nk_stbtt_free(x,u) + +#endif // STBTT_malloc + +#endif // NK_INCLUDE_FONT_BAKING + #endif From d30e07f4979f0dd0aab80ae8fa7ad24cbffe8dc9 Mon Sep 17 00:00:00 2001 From: Anton Afanasyev Date: Sat, 5 Sep 2020 09:14:20 -0700 Subject: [PATCH 3/3] Remove trailing spaces --- nuklear.h | 2 +- src/build.py | 2 +- src/nuklear_combo.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/nuklear.h b/nuklear.h index 6631ccb..e262d8f 100644 --- a/nuklear.h +++ b/nuklear.h @@ -28309,7 +28309,7 @@ nk_combo_begin_text(struct nk_context *ctx, const char *selected, int len, sym = style->combo.sym_hover; else if (is_clicked) sym = style->combo.sym_active; - else + else sym = style->combo.sym_normal; /* represents whether or not the combo's button symbol should be drawn */ diff --git a/src/build.py b/src/build.py index 804b23f..ba29fef 100644 --- a/src/build.py +++ b/src/build.py @@ -9,7 +9,7 @@ def print_help(): """usage: python single_header_packer.py --macro [--intro ] --extern --pub --priv1 --priv2 [--outro ] where can be a comma-separated list of files. e.g. --priv *.c,inc/*.h - + The 'extern' files are placed between 'priv1' and 'priv2'. The resulting code is packed as follows: diff --git a/src/nuklear_combo.c b/src/nuklear_combo.c index fe5373f..18ab17d 100644 --- a/src/nuklear_combo.c +++ b/src/nuklear_combo.c @@ -102,7 +102,7 @@ nk_combo_begin_text(struct nk_context *ctx, const char *selected, int len, sym = style->combo.sym_hover; else if (is_clicked) sym = style->combo.sym_active; - else + else sym = style->combo.sym_normal; /* represents whether or not the combo's button symbol should be drawn */