Skip to content

Commit

Permalink
Merge pull request #642 from SnootierMoon/master
Browse files Browse the repository at this point in the history
Add `const` qualifiers to `nk_allocator` in more places.
  • Loading branch information
RobLoach authored May 25, 2024
2 parents b9e84c0 + dd61233 commit 47f570c
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
30 changes: 15 additions & 15 deletions nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ NK_API nk_bool nk_init_fixed(struct nk_context*, void *memory, nk_size size, con
/// interface to nuklear. Can be useful for cases like monitoring memory consumption.
///
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
/// nk_bool nk_init(struct nk_context *ctx, struct nk_allocator *alloc, const struct nk_user_font *font);
/// nk_bool nk_init(struct nk_context *ctx, const struct nk_allocator *alloc, const struct nk_user_font *font);
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
///
/// Parameter | Description
Expand All @@ -624,7 +624,7 @@ NK_API nk_bool nk_init_fixed(struct nk_context*, void *memory, nk_size size, con
///
/// Returns either `false(0)` on failure or `true(1)` on success.
*/
NK_API nk_bool nk_init(struct nk_context*, struct nk_allocator*, const struct nk_user_font*);
NK_API nk_bool nk_init(struct nk_context*, const struct nk_allocator*, const struct nk_user_font*);
/*/// #### nk_init_custom
/// Initializes a `nk_context` struct from two different either fixed or growing
/// buffers. The first buffer is for allocating draw commands while the second buffer is
Expand Down Expand Up @@ -4132,8 +4132,8 @@ NK_API const nk_rune *nk_font_korean_glyph_ranges(void);
#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
NK_API void nk_font_atlas_init_default(struct nk_font_atlas*);
#endif
NK_API void nk_font_atlas_init(struct nk_font_atlas*, struct nk_allocator*);
NK_API void nk_font_atlas_init_custom(struct nk_font_atlas*, struct nk_allocator *persistent, struct nk_allocator *transient);
NK_API void nk_font_atlas_init(struct nk_font_atlas*, const struct nk_allocator*);
NK_API void nk_font_atlas_init_custom(struct nk_font_atlas*, const struct nk_allocator *persistent, const struct nk_allocator *transient);
NK_API void nk_font_atlas_begin(struct nk_font_atlas*);
NK_API struct nk_font_config nk_font_config(float pixel_height);
NK_API struct nk_font *nk_font_atlas_add(struct nk_font_atlas*, const struct nk_font_config*);
Expand Down Expand Up @@ -4410,7 +4410,7 @@ NK_API nk_bool nk_filter_binary(const struct nk_text_edit*, nk_rune unicode);
#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
NK_API void nk_textedit_init_default(struct nk_text_edit*);
#endif
NK_API void nk_textedit_init(struct nk_text_edit*, struct nk_allocator*, nk_size size);
NK_API void nk_textedit_init(struct nk_text_edit*, const struct nk_allocator*, nk_size size);
NK_API void nk_textedit_init_fixed(struct nk_text_edit*, void *memory, nk_size size);
NK_API void nk_textedit_free(struct nk_text_edit*);
NK_API void nk_textedit_text(struct nk_text_edit*, const char*, int total_len);
Expand Down Expand Up @@ -5970,7 +5970,7 @@ NK_LIB struct nk_vec2 nk_text_calculate_text_bounds(const struct nk_user_font *f
NK_LIB int nk_strfmt(char *buf, int buf_size, const char *fmt, va_list args);
#endif
#ifdef NK_INCLUDE_STANDARD_IO
NK_LIB char *nk_file_load(const char* path, nk_size* siz, struct nk_allocator *alloc);
NK_LIB char *nk_file_load(const char* path, nk_size* siz, const struct nk_allocator *alloc);
#endif

/* buffer */
Expand Down Expand Up @@ -6015,7 +6015,7 @@ NK_LIB struct nk_window *nk_find_window(struct nk_context *ctx, nk_hash hash, co
NK_LIB void nk_insert_window(struct nk_context *ctx, struct nk_window *win, enum nk_window_insert_location loc);

/* pool */
NK_LIB void nk_pool_init(struct nk_pool *pool, struct nk_allocator *alloc, unsigned int capacity);
NK_LIB void nk_pool_init(struct nk_pool *pool, const struct nk_allocator *alloc, unsigned int capacity);
NK_LIB void nk_pool_free(struct nk_pool *pool);
NK_LIB void nk_pool_init_fixed(struct nk_pool *pool, void *memory, nk_size size);
NK_LIB struct nk_page_element *nk_pool_alloc(struct nk_pool *pool);
Expand Down Expand Up @@ -7492,7 +7492,7 @@ nk_murmur_hash(const void * key, int len, nk_hash seed)
}
#ifdef NK_INCLUDE_STANDARD_IO
NK_LIB char*
nk_file_load(const char* path, nk_size* siz, struct nk_allocator *alloc)
nk_file_load(const char* path, nk_size* siz, const struct nk_allocator *alloc)
{
char *buf;
FILE *fd;
Expand Down Expand Up @@ -16681,7 +16681,7 @@ nk_font_baker_memory(nk_size *temp, int *glyph_count,
*temp += nk_build_align + nk_baker_align;
}
NK_INTERN struct nk_font_baker*
nk_font_baker(void *memory, int glyph_count, int count, struct nk_allocator *alloc)
nk_font_baker(void *memory, int glyph_count, int count, const struct nk_allocator *alloc)
{
struct nk_font_baker *baker;
if (!memory) return 0;
Expand All @@ -16698,7 +16698,7 @@ NK_INTERN int
nk_font_bake_pack(struct nk_font_baker *baker,
nk_size *image_memory, int *width, int *height, struct nk_recti *custom,
const struct nk_font_config *config_list, int count,
struct nk_allocator *alloc)
const struct nk_allocator *alloc)
{
NK_STORAGE const nk_size max_height = 1024 * 32;
const struct nk_font_config *config_iter, *it;
Expand Down Expand Up @@ -17428,7 +17428,7 @@ nk_font_atlas_init_default(struct nk_font_atlas *atlas)
}
#endif
NK_API void
nk_font_atlas_init(struct nk_font_atlas *atlas, struct nk_allocator *alloc)
nk_font_atlas_init(struct nk_font_atlas *atlas, const struct nk_allocator *alloc)
{
NK_ASSERT(atlas);
NK_ASSERT(alloc);
Expand All @@ -17439,7 +17439,7 @@ nk_font_atlas_init(struct nk_font_atlas *atlas, struct nk_allocator *alloc)
}
NK_API void
nk_font_atlas_init_custom(struct nk_font_atlas *atlas,
struct nk_allocator *permanent, struct nk_allocator *temporary)
const struct nk_allocator *permanent, const struct nk_allocator *temporary)
{
NK_ASSERT(atlas);
NK_ASSERT(permanent);
Expand Down Expand Up @@ -19091,7 +19091,7 @@ nk_init_custom(struct nk_context *ctx, struct nk_buffer *cmds,
return 1;
}
NK_API nk_bool
nk_init(struct nk_context *ctx, struct nk_allocator *alloc,
nk_init(struct nk_context *ctx, const struct nk_allocator *alloc,
const struct nk_user_font *font)
{
NK_ASSERT(alloc);
Expand Down Expand Up @@ -19380,7 +19380,7 @@ nk__next(struct nk_context *ctx, const struct nk_command *cmd)
*
* ===============================================================*/
NK_LIB void
nk_pool_init(struct nk_pool *pool, struct nk_allocator *alloc,
nk_pool_init(struct nk_pool *pool, const struct nk_allocator *alloc,
unsigned int capacity)
{
NK_ASSERT(capacity >= 1);
Expand Down Expand Up @@ -27204,7 +27204,7 @@ nk_textedit_init_fixed(struct nk_text_edit *state, void *memory, nk_size size)
nk_str_init_fixed(&state->string, memory, size);
}
NK_API void
nk_textedit_init(struct nk_text_edit *state, struct nk_allocator *alloc, nk_size size)
nk_textedit_init(struct nk_text_edit *state, const struct nk_allocator *alloc, nk_size size)
{
NK_ASSERT(state);
NK_ASSERT(alloc);
Expand Down
10 changes: 5 additions & 5 deletions src/nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ NK_API nk_bool nk_init_fixed(struct nk_context*, void *memory, nk_size size, con
/// interface to nuklear. Can be useful for cases like monitoring memory consumption.
///
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
/// nk_bool nk_init(struct nk_context *ctx, struct nk_allocator *alloc, const struct nk_user_font *font);
/// nk_bool nk_init(struct nk_context *ctx, const struct nk_allocator *alloc, const struct nk_user_font *font);
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
///
/// Parameter | Description
Expand All @@ -402,7 +402,7 @@ NK_API nk_bool nk_init_fixed(struct nk_context*, void *memory, nk_size size, con
///
/// Returns either `false(0)` on failure or `true(1)` on success.
*/
NK_API nk_bool nk_init(struct nk_context*, struct nk_allocator*, const struct nk_user_font*);
NK_API nk_bool nk_init(struct nk_context*, const struct nk_allocator*, const struct nk_user_font*);
/*/// #### nk_init_custom
/// Initializes a `nk_context` struct from two different either fixed or growing
/// buffers. The first buffer is for allocating draw commands while the second buffer is
Expand Down Expand Up @@ -3910,8 +3910,8 @@ NK_API const nk_rune *nk_font_korean_glyph_ranges(void);
#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
NK_API void nk_font_atlas_init_default(struct nk_font_atlas*);
#endif
NK_API void nk_font_atlas_init(struct nk_font_atlas*, struct nk_allocator*);
NK_API void nk_font_atlas_init_custom(struct nk_font_atlas*, struct nk_allocator *persistent, struct nk_allocator *transient);
NK_API void nk_font_atlas_init(struct nk_font_atlas*, const struct nk_allocator*);
NK_API void nk_font_atlas_init_custom(struct nk_font_atlas*, const struct nk_allocator *persistent, const struct nk_allocator *transient);
NK_API void nk_font_atlas_begin(struct nk_font_atlas*);
NK_API struct nk_font_config nk_font_config(float pixel_height);
NK_API struct nk_font *nk_font_atlas_add(struct nk_font_atlas*, const struct nk_font_config*);
Expand Down Expand Up @@ -4188,7 +4188,7 @@ NK_API nk_bool nk_filter_binary(const struct nk_text_edit*, nk_rune unicode);
#ifdef NK_INCLUDE_DEFAULT_ALLOCATOR
NK_API void nk_textedit_init_default(struct nk_text_edit*);
#endif
NK_API void nk_textedit_init(struct nk_text_edit*, struct nk_allocator*, nk_size size);
NK_API void nk_textedit_init(struct nk_text_edit*, const struct nk_allocator*, nk_size size);
NK_API void nk_textedit_init_fixed(struct nk_text_edit*, void *memory, nk_size size);
NK_API void nk_textedit_free(struct nk_text_edit*);
NK_API void nk_textedit_text(struct nk_text_edit*, const char*, int total_len);
Expand Down
2 changes: 1 addition & 1 deletion src/nuklear_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ nk_init_custom(struct nk_context *ctx, struct nk_buffer *cmds,
return 1;
}
NK_API nk_bool
nk_init(struct nk_context *ctx, struct nk_allocator *alloc,
nk_init(struct nk_context *ctx, const struct nk_allocator *alloc,
const struct nk_user_font *font)
{
NK_ASSERT(alloc);
Expand Down
12 changes: 6 additions & 6 deletions src/nuklear_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ nk_font_baker_memory(nk_size *temp, int *glyph_count,
*temp += nk_build_align + nk_baker_align;
}
NK_INTERN struct nk_font_baker*
nk_font_baker(void *memory, int glyph_count, int count, struct nk_allocator *alloc)
nk_font_baker(void *memory, int glyph_count, int count, const struct nk_allocator *alloc)
{
struct nk_font_baker *baker;
if (!memory) return 0;
Expand All @@ -163,7 +163,7 @@ NK_INTERN int
nk_font_bake_pack(struct nk_font_baker *baker,
nk_size *image_memory, int *width, int *height, struct nk_recti *custom,
const struct nk_font_config *config_list, int count,
struct nk_allocator *alloc)
const struct nk_allocator *alloc)
{
NK_STORAGE const nk_size max_height = 1024 * 32;
const struct nk_font_config *config_iter, *it;
Expand Down Expand Up @@ -192,15 +192,15 @@ nk_font_bake_pack(struct nk_font_baker *baker,
it = config_iter;
do {
struct stbtt_fontinfo *font_info = &baker->build[i++].info;
font_info->userdata = alloc;
font_info->userdata = (void*)alloc;

if (!stbtt_InitFont(font_info, (const unsigned char*)it->ttf_blob, stbtt_GetFontOffsetForIndex((const unsigned char*)it->ttf_blob, 0)))
return nk_false;
} while ((it = it->n) != config_iter);
}
*height = 0;
*width = (total_glyph_count > 1000) ? 1024 : 512;
stbtt_PackBegin(&baker->spc, 0, (int)*width, (int)max_height, 0, 1, alloc);
stbtt_PackBegin(&baker->spc, 0, (int)*width, (int)max_height, 0, 1, (void*)alloc);
{
int input_i = 0;
int range_n = 0;
Expand Down Expand Up @@ -893,7 +893,7 @@ nk_font_atlas_init_default(struct nk_font_atlas *atlas)
}
#endif
NK_API void
nk_font_atlas_init(struct nk_font_atlas *atlas, struct nk_allocator *alloc)
nk_font_atlas_init(struct nk_font_atlas *atlas, const struct nk_allocator *alloc)
{
NK_ASSERT(atlas);
NK_ASSERT(alloc);
Expand All @@ -904,7 +904,7 @@ nk_font_atlas_init(struct nk_font_atlas *atlas, struct nk_allocator *alloc)
}
NK_API void
nk_font_atlas_init_custom(struct nk_font_atlas *atlas,
struct nk_allocator *permanent, struct nk_allocator *temporary)
const struct nk_allocator *permanent, const struct nk_allocator *temporary)
{
NK_ASSERT(atlas);
NK_ASSERT(permanent);
Expand Down
4 changes: 2 additions & 2 deletions src/nuklear_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ NK_LIB struct nk_vec2 nk_text_calculate_text_bounds(const struct nk_user_font *f
NK_LIB int nk_strfmt(char *buf, int buf_size, const char *fmt, va_list args);
#endif
#ifdef NK_INCLUDE_STANDARD_IO
NK_LIB char *nk_file_load(const char* path, nk_size* siz, struct nk_allocator *alloc);
NK_LIB char *nk_file_load(const char* path, nk_size* siz, const struct nk_allocator *alloc);
#endif

/* buffer */
Expand Down Expand Up @@ -183,7 +183,7 @@ NK_LIB struct nk_window *nk_find_window(struct nk_context *ctx, nk_hash hash, co
NK_LIB void nk_insert_window(struct nk_context *ctx, struct nk_window *win, enum nk_window_insert_location loc);

/* pool */
NK_LIB void nk_pool_init(struct nk_pool *pool, struct nk_allocator *alloc, unsigned int capacity);
NK_LIB void nk_pool_init(struct nk_pool *pool, const struct nk_allocator *alloc, unsigned int capacity);
NK_LIB void nk_pool_free(struct nk_pool *pool);
NK_LIB void nk_pool_init_fixed(struct nk_pool *pool, void *memory, nk_size size);
NK_LIB struct nk_page_element *nk_pool_alloc(struct nk_pool *pool);
Expand Down
2 changes: 1 addition & 1 deletion src/nuklear_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* ===============================================================*/
NK_LIB void
nk_pool_init(struct nk_pool *pool, struct nk_allocator *alloc,
nk_pool_init(struct nk_pool *pool, const struct nk_allocator *alloc,
unsigned int capacity)
{
NK_ASSERT(capacity >= 1);
Expand Down
2 changes: 1 addition & 1 deletion src/nuklear_text_editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ nk_textedit_init_fixed(struct nk_text_edit *state, void *memory, nk_size size)
nk_str_init_fixed(&state->string, memory, size);
}
NK_API void
nk_textedit_init(struct nk_text_edit *state, struct nk_allocator *alloc, nk_size size)
nk_textedit_init(struct nk_text_edit *state, const struct nk_allocator *alloc, nk_size size)
{
NK_ASSERT(state);
NK_ASSERT(alloc);
Expand Down
2 changes: 1 addition & 1 deletion src/nuklear_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ nk_murmur_hash(const void * key, int len, nk_hash seed)
}
#ifdef NK_INCLUDE_STANDARD_IO
NK_LIB char*
nk_file_load(const char* path, nk_size* siz, struct nk_allocator *alloc)
nk_file_load(const char* path, nk_size* siz, const struct nk_allocator *alloc)
{
char *buf;
FILE *fd;
Expand Down

0 comments on commit 47f570c

Please sign in to comment.