-
Notifications
You must be signed in to change notification settings - Fork 578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added support for combo from an array of struct #725
Open
gooosedev
wants to merge
9
commits into
Immediate-Mode-UI:master
Choose a base branch
from
gooosedev:feature/combobox_for_struct
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0ccc68d
added support for combo from an array of struct
gooosedev 501b9e3
renamed the function to nk_combo_from_struct_array
gooosedev 326584e
added small example for combobox_for_struct inside overview example
gooosedev fa7d7f7
Merge branch 'master' of github.com:Immediate-Mode-UI/Nuklear into fe…
RobLoach 420ac59
feature/combo_from_struct_array:
gooosedev 48c2272
Made the struct array definition more readable
gooosedev 4a46e6a
feature/combo_from_struct_array
gooosedev 2e297f8
Merge branch 'master' into feature/combobox_for_struct
gooosedev da871a8
fixed doc format
gooosedev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -819,6 +819,43 @@ nk_combo_callback(struct nk_context *ctx, void(*item_getter)(void*, int, const c | |
nk_combo_end(ctx); | ||
} return selected; | ||
} | ||
|
||
|
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add some API documentation? Define each parameter, and give examples where possible. Thanks. |
||
{ | ||
int i = 0; | ||
int max_height; | ||
struct nk_vec2 item_spacing; | ||
struct nk_vec2 window_padding; | ||
char* sel; | ||
char* name; | ||
NK_ASSERT(ctx); | ||
NK_ASSERT(items); | ||
NK_ASSERT(ctx->current); | ||
if (!ctx || !items ||!count) | ||
return selected; | ||
|
||
item_spacing = ctx->style.window.spacing; | ||
window_padding = nk_panel_get_padding(&ctx->style, ctx->current->layout->type); | ||
max_height = count * item_height + count * (int)item_spacing.y; | ||
max_height += (int)item_spacing.y * 2 + (int)window_padding.y * 2; | ||
size.y = NK_MIN(size.y, (float)max_height); | ||
sel = *(char**)((char*)items + (item_sz*selected) + stride); | ||
if (nk_combo_begin_label(ctx, sel, size)) { | ||
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; | ||
} | ||
nk_combo_end(ctx); | ||
} | ||
return selected; | ||
} | ||
|
||
NK_API void | ||
nk_combobox(struct nk_context *ctx, const char *const *items, int count, | ||
int *selected, int item_height, struct nk_vec2 size) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May want to declare the struct outside of the code block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declare or define? What would be the reasoning g for this? I have definitely seen structure definitions with local scope.
But then again. I don't think that is a c89 capability.