Nuklear icon indicating copy to clipboard operation
Nuklear copied to clipboard

added support for combo from an array of struct

Open gooosedev opened this issue 1 year ago • 6 comments

This PR adds a new combo function nk_combo_from_struct_array the objective is to be able to make combos from an array of structs (the only requirement is for the struct to have a char* ptr to hold the name)

parameters are the same as for the nk_combo function, with the addition of the size of the struct and a stride to the member to use for the combo entry.

example:

struct mystruct{
  float f;
  char* name;
  int i;
};
struct mystruct items [3]={
  {1.0, "foo", 1},
  {1.0, "foobar", 1},
  {1.0, "bar", 1},
};
int selected;
/* ... */
selected = nk_combo_from_struct_array(ctx, &items, 3, sizeof(struct mystruct), offsetof(struct mystruct, name), selected, 15, nk_vec2(x,y));

gooosedev avatar Oct 27 '24 11:10 gooosedev

Thanks a lot. Would you mind adding a small example in the overview demo? It serves as a good space to test the code and make sure it's all still functional.

RobLoach avatar Nov 17 '24 20:11 RobLoach

I added a small example as requested. Please let me know if something else is needed.

gooosedev avatar Nov 18 '24 16:11 gooosedev

I do agree the function name might not be the best, i'll try to come up with a better suited one.

for the documentation, do you prefer that i do it in the source file / header for nk_combo ? or as a comment in the overview.c file ?

gooosedev avatar Dec 08 '24 10:12 gooosedev

Definitely in the NK combo section. Preferably in the nuclear.H file, as the packer puts that first. when reading the single header, the public api prototypes are listed and documented near the top, then private library comes second; then definitions later. So placing docs above the definition will not be seen by future readers unless they explicitly scroll through 30k lines to find it.

Also, overview.c is not sourced for documentation

awschult002 avatar Dec 09 '24 11:12 awschult002

I'd even say in src/nuklear.h

riri avatar Dec 09 '24 14:12 riri

Unfortunately, the documentation format you have chosen has been recently deprecated. Take a look at the other header blocks in the most recent src/nuklear.h

awschult002 avatar Dec 11 '24 23:12 awschult002