Skip to content

Commit

Permalink
feature/combo_from_struct_array:
Browse files Browse the repository at this point in the history
- Added documentation
- Added check for NULL char pointer for the name
  • Loading branch information
gooosedev committed Dec 11, 2024
1 parent fa7d7f7 commit 420ac59
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -3543,6 +3543,24 @@ NK_API int nk_combo(struct nk_context*, const char *const *items, int count, int
NK_API int nk_combo_separator(struct nk_context*, const char *items_separated_by_separator, int separator, int selected, int count, int item_height, struct nk_vec2 size);
NK_API int nk_combo_string(struct nk_context*, const char *items_separated_by_zeros, int selected, int count, int item_height, struct nk_vec2 size);
NK_API int nk_combo_callback(struct nk_context*, void(*item_getter)(void*, int, const char**), void *userdata, int selected, int count, int item_height, struct nk_vec2 size);
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// NK_API int nk_combo_from_struct_array(struct nk_context *ctx, const void *items, int count, int item_sz, int stride, int selected, int item_height, struct nk_vec2 size);
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
///
/// Parameter | Description
/// --------------------|-----------------------------------------------------------
/// __ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function
/// __items__ | `void` pointer to a list of structures
/// __count__ | Number of elements in the array of structs
/// __items_sz__ | Size of an individual structure.
/// __stride__ | Stride to a char* member inside the structure
/// __selected__ | the index of the current selected item
/// __item_height__ | Height of the element
/// __size__ | Size of the element listing, must point to a `nk_vec2` structure
/// Returns the index of the newly selected item.
/// #### Usage
/// The nk_combo_from_struct_array is designed to create a combobox from an array of strct containing a `char*` member that we use as a name
/// this avoids the need to have two arrays (one being for the array of structs, and one for the names)
NK_API int nk_combo_from_struct_array(struct nk_context *ctx, const void *items, int count, int item_sz, int stride, int selected, int item_height, struct nk_vec2 size);
NK_API void nk_combobox(struct nk_context*, const char **items, int count, int *selected, int item_height, struct nk_vec2 size);
NK_API void nk_combobox_string(struct nk_context*, const char *items_separated_by_zeros, int *selected, int count, int item_height, struct nk_vec2 size);
Expand Down
2 changes: 2 additions & 0 deletions src/nuklear_combo.c
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,8 @@ NK_API int nk_combo_from_struct_array(struct nk_context *ctx, const void *items,
nk_layout_row_dynamic(ctx, (float)item_height, 1);
for (i = 0; i < count; ++i) {
name = *(char**)((char*)items + stride);
if(!name)
name = "";
if (nk_combo_item_label(ctx, name, NK_TEXT_LEFT))
selected = i;
items = (char*)items + item_sz;
Expand Down

0 comments on commit 420ac59

Please sign in to comment.