Skip to content

Commit a94e6ed

Browse files
committed
Return if value changed for property_*() and combobox*() functions
1 parent 4aff9c7 commit a94e6ed

4 files changed

Lines changed: 86 additions & 40 deletions

File tree

nuklear.h

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3580,7 +3580,7 @@ NK_API nk_bool nk_color_pick(struct nk_context*, struct nk_colorf*, enum nk_colo
35803580
* a `#` at the beginning. It will not be shown but guarantees correct behavior.
35813581
*
35823582
* ```c
3583-
* void nk_property_int(struct nk_context *ctx, const char *name, int min, int *val, int max, int step, float inc_per_pixel);
3583+
* nk_bool nk_property_int(struct nk_context *ctx, const char *name, int min, int *val, int max, int step, float inc_per_pixel);
35843584
* ```
35853585
*
35863586
* Parameter | Description
@@ -3592,8 +3592,10 @@ NK_API nk_bool nk_color_pick(struct nk_context*, struct nk_colorf*, enum nk_colo
35923592
* \param[in] max | Maximum value not allowed to be overflown
35933593
* \param[in] step | Increment added and subtracted on increment and decrement button
35943594
* \param[in] inc_per_pixel | Value per pixel added or subtracted on dragging
3595+
*
3596+
* \returns `true(1)` if the value changed
35953597
*/
3596-
NK_API void nk_property_int(struct nk_context*, const char *name, int min, int *val, int max, int step, float inc_per_pixel);
3598+
NK_API nk_bool nk_property_int(struct nk_context*, const char *name, int min, int *val, int max, int step, float inc_per_pixel);
35973599

35983600
/**
35993601
* # # nk_property_float
@@ -3603,7 +3605,7 @@ NK_API void nk_property_int(struct nk_context*, const char *name, int min, int *
36033605
* a `#` at the beginning. It will not be shown but guarantees correct behavior.
36043606
*
36053607
* ```c
3606-
* void nk_property_float(struct nk_context *ctx, const char *name, float min, float *val, float max, float step, float inc_per_pixel);
3608+
* nk_bool nk_property_float(struct nk_context *ctx, const char *name, float min, float *val, float max, float step, float inc_per_pixel);
36073609
* ```
36083610
*
36093611
* Parameter | Description
@@ -3615,8 +3617,10 @@ NK_API void nk_property_int(struct nk_context*, const char *name, int min, int *
36153617
* \param[in] max | Maximum value not allowed to be overflown
36163618
* \param[in] step | Increment added and subtracted on increment and decrement button
36173619
* \param[in] inc_per_pixel | Value per pixel added or subtracted on dragging
3620+
*
3621+
* \returns `true(1)` if the value changed
36183622
*/
3619-
NK_API void nk_property_float(struct nk_context*, const char *name, float min, float *val, float max, float step, float inc_per_pixel);
3623+
NK_API nk_bool nk_property_float(struct nk_context*, const char *name, float min, float *val, float max, float step, float inc_per_pixel);
36203624

36213625
/**
36223626
* # # nk_property_double
@@ -3626,7 +3630,7 @@ NK_API void nk_property_float(struct nk_context*, const char *name, float min, f
36263630
* a `#` at the beginning. It will not be shown but guarantees correct behavior.
36273631
*
36283632
* ```c
3629-
* void nk_property_double(struct nk_context *ctx, const char *name, double min, double *val, double max, double step, double inc_per_pixel);
3633+
* nk_bool nk_property_double(struct nk_context *ctx, const char *name, double min, double *val, double max, double step, double inc_per_pixel);
36303634
* ```
36313635
*
36323636
* Parameter | Description
@@ -3638,8 +3642,10 @@ NK_API void nk_property_float(struct nk_context*, const char *name, float min, f
36383642
* \param[in] max | Maximum value not allowed to be overflown
36393643
* \param[in] step | Increment added and subtracted on increment and decrement button
36403644
* \param[in] inc_per_pixel | Value per pixel added or subtracted on dragging
3645+
*
3646+
* \returns `true(1)` if the value changed
36413647
*/
3642-
NK_API void nk_property_double(struct nk_context*, const char *name, double min, double *val, double max, double step, float inc_per_pixel);
3648+
NK_API nk_bool nk_property_double(struct nk_context*, const char *name, double min, double *val, double max, double step, float inc_per_pixel);
36433649

36443650
/**
36453651
* # # nk_propertyi
@@ -3781,10 +3787,10 @@ NK_API int nk_combo(struct nk_context*, const char *const *items, int count, int
37813787
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);
37823788
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);
37833789
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);
3784-
NK_API void nk_combobox(struct nk_context*, const char *const *items, int count, int *selected, int item_height, struct nk_vec2 size);
3785-
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);
3786-
NK_API void nk_combobox_separator(struct nk_context*, const char *items_separated_by_separator, int separator, int *selected, int count, int item_height, struct nk_vec2 size);
3787-
NK_API void nk_combobox_callback(struct nk_context*, void(*item_getter)(void*, int, const char**), void*, int *selected, int count, int item_height, struct nk_vec2 size);
3790+
NK_API nk_bool nk_combobox(struct nk_context*, const char *const *items, int count, int *selected, int item_height, struct nk_vec2 size);
3791+
NK_API nk_bool nk_combobox_string(struct nk_context*, const char *items_separated_by_zeros, int *selected, int count, int item_height, struct nk_vec2 size);
3792+
NK_API nk_bool nk_combobox_separator(struct nk_context*, const char *items_separated_by_separator, int separator, int *selected, int count, int item_height, struct nk_vec2 size);
3793+
NK_API nk_bool nk_combobox_callback(struct nk_context*, void(*item_getter)(void*, int, const char**), void*, int *selected, int count, int item_height, struct nk_vec2 size);
37883794
/* =============================================================================
37893795
*
37903796
* ABSTRACT COMBOBOX
@@ -29149,47 +29155,56 @@ nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant
2914929155
win->edit.active = nk_false;
2915029156
}
2915129157
}
29152-
NK_API void
29158+
NK_API nk_bool
2915329159
nk_property_int(struct nk_context *ctx, const char *name,
2915429160
int min, int *val, int max, int step, float inc_per_pixel)
2915529161
{
2915629162
struct nk_property_variant variant;
29163+
nk_bool changed;
2915729164
NK_ASSERT(ctx);
2915829165
NK_ASSERT(name);
2915929166
NK_ASSERT(val);
2916029167

29161-
if (!ctx || !ctx->current || !name || !val) return;
29168+
if (!ctx || !ctx->current || !name || !val) return nk_false;
2916229169
variant = nk_property_variant_int(*val, min, max, step);
2916329170
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_INT);
29171+
changed = variant.value.i != *val;
2916429172
*val = variant.value.i;
29173+
return changed;
2916529174
}
29166-
NK_API void
29175+
NK_API nk_bool
2916729176
nk_property_float(struct nk_context *ctx, const char *name,
2916829177
float min, float *val, float max, float step, float inc_per_pixel)
2916929178
{
2917029179
struct nk_property_variant variant;
29180+
nk_bool changed;
2917129181
NK_ASSERT(ctx);
2917229182
NK_ASSERT(name);
2917329183
NK_ASSERT(val);
2917429184

29175-
if (!ctx || !ctx->current || !name || !val) return;
29185+
if (!ctx || !ctx->current || !name || !val) return nk_false;
2917629186
variant = nk_property_variant_float(*val, min, max, step);
2917729187
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT);
29188+
changed = variant.value.f != *val;
2917829189
*val = variant.value.f;
29190+
return changed;
2917929191
}
29180-
NK_API void
29192+
NK_API nk_bool
2918129193
nk_property_double(struct nk_context *ctx, const char *name,
2918229194
double min, double *val, double max, double step, float inc_per_pixel)
2918329195
{
2918429196
struct nk_property_variant variant;
29197+
nk_bool changed;
2918529198
NK_ASSERT(ctx);
2918629199
NK_ASSERT(name);
2918729200
NK_ASSERT(val);
2918829201

29189-
if (!ctx || !ctx->current || !name || !val) return;
29202+
if (!ctx || !ctx->current || !name || !val) return nk_false;
2919029203
variant = nk_property_variant_double(*val, min, max, step);
2919129204
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT);
29205+
changed = variant.value.d != *val;
2919229206
*val = variant.value.d;
29207+
return changed;
2919329208
}
2919429209
NK_API int
2919529210
nk_propertyi(struct nk_context *ctx, const char *name, int min, int val,
@@ -30594,31 +30609,39 @@ nk_combo_callback(struct nk_context *ctx, void(*item_getter)(void*, int, const c
3059430609
nk_combo_end(ctx);
3059530610
} return selected;
3059630611
}
30597-
NK_API void
30612+
NK_API nk_bool
3059830613
nk_combobox(struct nk_context *ctx, const char *const *items, int count,
3059930614
int *selected, int item_height, struct nk_vec2 size)
3060030615
{
30616+
int tmp = *selected;
3060130617
*selected = nk_combo(ctx, items, count, *selected, item_height, size);
30618+
return tmp != *selected;
3060230619
}
30603-
NK_API void
30620+
NK_API nk_bool
3060430621
nk_combobox_string(struct nk_context *ctx, const char *items_separated_by_zeros,
3060530622
int *selected, int count, int item_height, struct nk_vec2 size)
3060630623
{
30624+
int tmp = *selected;
3060730625
*selected = nk_combo_string(ctx, items_separated_by_zeros, *selected, count, item_height, size);
30626+
return tmp != *selected;
3060830627
}
30609-
NK_API void
30628+
NK_API nk_bool
3061030629
nk_combobox_separator(struct nk_context *ctx, const char *items_separated_by_separator,
3061130630
int separator, int *selected, int count, int item_height, struct nk_vec2 size)
3061230631
{
30632+
int tmp = *selected;
3061330633
*selected = nk_combo_separator(ctx, items_separated_by_separator, separator,
3061430634
*selected, count, item_height, size);
30635+
return tmp != *selected;
3061530636
}
30616-
NK_API void
30637+
NK_API nk_bool
3061730638
nk_combobox_callback(struct nk_context *ctx,
3061830639
void(*item_getter)(void* data, int id, const char **out_text),
3061930640
void *userdata, int *selected, int count, int item_height, struct nk_vec2 size)
3062030641
{
30642+
int tmp = *selected;
3062130643
*selected = nk_combo_callback(ctx, item_getter, userdata, *selected, count, item_height, size);
30644+
return tmp != *selected;
3062230645
}
3062330646

3062430647

src/nuklear.h

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3357,7 +3357,7 @@ NK_API nk_bool nk_color_pick(struct nk_context*, struct nk_colorf*, enum nk_colo
33573357
* a `#` at the beginning. It will not be shown but guarantees correct behavior.
33583358
*
33593359
* ```c
3360-
* void nk_property_int(struct nk_context *ctx, const char *name, int min, int *val, int max, int step, float inc_per_pixel);
3360+
* nk_bool nk_property_int(struct nk_context *ctx, const char *name, int min, int *val, int max, int step, float inc_per_pixel);
33613361
* ```
33623362
*
33633363
* Parameter | Description
@@ -3369,8 +3369,10 @@ NK_API nk_bool nk_color_pick(struct nk_context*, struct nk_colorf*, enum nk_colo
33693369
* \param[in] max | Maximum value not allowed to be overflown
33703370
* \param[in] step | Increment added and subtracted on increment and decrement button
33713371
* \param[in] inc_per_pixel | Value per pixel added or subtracted on dragging
3372+
*
3373+
* \returns `true(1)` if the value changed
33723374
*/
3373-
NK_API void nk_property_int(struct nk_context*, const char *name, int min, int *val, int max, int step, float inc_per_pixel);
3375+
NK_API nk_bool nk_property_int(struct nk_context*, const char *name, int min, int *val, int max, int step, float inc_per_pixel);
33743376

33753377
/**
33763378
* # # nk_property_float
@@ -3380,7 +3382,7 @@ NK_API void nk_property_int(struct nk_context*, const char *name, int min, int *
33803382
* a `#` at the beginning. It will not be shown but guarantees correct behavior.
33813383
*
33823384
* ```c
3383-
* void nk_property_float(struct nk_context *ctx, const char *name, float min, float *val, float max, float step, float inc_per_pixel);
3385+
* nk_bool nk_property_float(struct nk_context *ctx, const char *name, float min, float *val, float max, float step, float inc_per_pixel);
33843386
* ```
33853387
*
33863388
* Parameter | Description
@@ -3392,8 +3394,10 @@ NK_API void nk_property_int(struct nk_context*, const char *name, int min, int *
33923394
* \param[in] max | Maximum value not allowed to be overflown
33933395
* \param[in] step | Increment added and subtracted on increment and decrement button
33943396
* \param[in] inc_per_pixel | Value per pixel added or subtracted on dragging
3397+
*
3398+
* \returns `true(1)` if the value changed
33953399
*/
3396-
NK_API void nk_property_float(struct nk_context*, const char *name, float min, float *val, float max, float step, float inc_per_pixel);
3400+
NK_API nk_bool nk_property_float(struct nk_context*, const char *name, float min, float *val, float max, float step, float inc_per_pixel);
33973401

33983402
/**
33993403
* # # nk_property_double
@@ -3403,7 +3407,7 @@ NK_API void nk_property_float(struct nk_context*, const char *name, float min, f
34033407
* a `#` at the beginning. It will not be shown but guarantees correct behavior.
34043408
*
34053409
* ```c
3406-
* void nk_property_double(struct nk_context *ctx, const char *name, double min, double *val, double max, double step, double inc_per_pixel);
3410+
* nk_bool nk_property_double(struct nk_context *ctx, const char *name, double min, double *val, double max, double step, double inc_per_pixel);
34073411
* ```
34083412
*
34093413
* Parameter | Description
@@ -3415,8 +3419,10 @@ NK_API void nk_property_float(struct nk_context*, const char *name, float min, f
34153419
* \param[in] max | Maximum value not allowed to be overflown
34163420
* \param[in] step | Increment added and subtracted on increment and decrement button
34173421
* \param[in] inc_per_pixel | Value per pixel added or subtracted on dragging
3422+
*
3423+
* \returns `true(1)` if the value changed
34183424
*/
3419-
NK_API void nk_property_double(struct nk_context*, const char *name, double min, double *val, double max, double step, float inc_per_pixel);
3425+
NK_API nk_bool nk_property_double(struct nk_context*, const char *name, double min, double *val, double max, double step, float inc_per_pixel);
34203426

34213427
/**
34223428
* # # nk_propertyi
@@ -3558,10 +3564,10 @@ NK_API int nk_combo(struct nk_context*, const char *const *items, int count, int
35583564
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);
35593565
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);
35603566
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);
3561-
NK_API void nk_combobox(struct nk_context*, const char *const *items, int count, int *selected, int item_height, struct nk_vec2 size);
3562-
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);
3563-
NK_API void nk_combobox_separator(struct nk_context*, const char *items_separated_by_separator, int separator, int *selected, int count, int item_height, struct nk_vec2 size);
3564-
NK_API void nk_combobox_callback(struct nk_context*, void(*item_getter)(void*, int, const char**), void*, int *selected, int count, int item_height, struct nk_vec2 size);
3567+
NK_API nk_bool nk_combobox(struct nk_context*, const char *const *items, int count, int *selected, int item_height, struct nk_vec2 size);
3568+
NK_API nk_bool nk_combobox_string(struct nk_context*, const char *items_separated_by_zeros, int *selected, int count, int item_height, struct nk_vec2 size);
3569+
NK_API nk_bool nk_combobox_separator(struct nk_context*, const char *items_separated_by_separator, int separator, int *selected, int count, int item_height, struct nk_vec2 size);
3570+
NK_API nk_bool nk_combobox_callback(struct nk_context*, void(*item_getter)(void*, int, const char**), void*, int *selected, int count, int item_height, struct nk_vec2 size);
35653571
/* =============================================================================
35663572
*
35673573
* ABSTRACT COMBOBOX

src/nuklear_combo.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -819,29 +819,37 @@ nk_combo_callback(struct nk_context *ctx, void(*item_getter)(void*, int, const c
819819
nk_combo_end(ctx);
820820
} return selected;
821821
}
822-
NK_API void
822+
NK_API nk_bool
823823
nk_combobox(struct nk_context *ctx, const char *const *items, int count,
824824
int *selected, int item_height, struct nk_vec2 size)
825825
{
826+
int tmp = *selected;
826827
*selected = nk_combo(ctx, items, count, *selected, item_height, size);
828+
return tmp != *selected;
827829
}
828-
NK_API void
830+
NK_API nk_bool
829831
nk_combobox_string(struct nk_context *ctx, const char *items_separated_by_zeros,
830832
int *selected, int count, int item_height, struct nk_vec2 size)
831833
{
834+
int tmp = *selected;
832835
*selected = nk_combo_string(ctx, items_separated_by_zeros, *selected, count, item_height, size);
836+
return tmp != *selected;
833837
}
834-
NK_API void
838+
NK_API nk_bool
835839
nk_combobox_separator(struct nk_context *ctx, const char *items_separated_by_separator,
836840
int separator, int *selected, int count, int item_height, struct nk_vec2 size)
837841
{
842+
int tmp = *selected;
838843
*selected = nk_combo_separator(ctx, items_separated_by_separator, separator,
839844
*selected, count, item_height, size);
845+
return tmp != *selected;
840846
}
841-
NK_API void
847+
NK_API nk_bool
842848
nk_combobox_callback(struct nk_context *ctx,
843849
void(*item_getter)(void* data, int id, const char **out_text),
844850
void *userdata, int *selected, int count, int item_height, struct nk_vec2 size)
845851
{
852+
int tmp = *selected;
846853
*selected = nk_combo_callback(ctx, item_getter, userdata, *selected, count, item_height, size);
854+
return tmp != *selected;
847855
}

src/nuklear_property.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,47 +446,56 @@ nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant
446446
win->edit.active = nk_false;
447447
}
448448
}
449-
NK_API void
449+
NK_API nk_bool
450450
nk_property_int(struct nk_context *ctx, const char *name,
451451
int min, int *val, int max, int step, float inc_per_pixel)
452452
{
453453
struct nk_property_variant variant;
454+
nk_bool changed;
454455
NK_ASSERT(ctx);
455456
NK_ASSERT(name);
456457
NK_ASSERT(val);
457458

458-
if (!ctx || !ctx->current || !name || !val) return;
459+
if (!ctx || !ctx->current || !name || !val) return nk_false;
459460
variant = nk_property_variant_int(*val, min, max, step);
460461
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_INT);
462+
changed = variant.value.i != *val;
461463
*val = variant.value.i;
464+
return changed;
462465
}
463-
NK_API void
466+
NK_API nk_bool
464467
nk_property_float(struct nk_context *ctx, const char *name,
465468
float min, float *val, float max, float step, float inc_per_pixel)
466469
{
467470
struct nk_property_variant variant;
471+
nk_bool changed;
468472
NK_ASSERT(ctx);
469473
NK_ASSERT(name);
470474
NK_ASSERT(val);
471475

472-
if (!ctx || !ctx->current || !name || !val) return;
476+
if (!ctx || !ctx->current || !name || !val) return nk_false;
473477
variant = nk_property_variant_float(*val, min, max, step);
474478
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT);
479+
changed = variant.value.f != *val;
475480
*val = variant.value.f;
481+
return changed;
476482
}
477-
NK_API void
483+
NK_API nk_bool
478484
nk_property_double(struct nk_context *ctx, const char *name,
479485
double min, double *val, double max, double step, float inc_per_pixel)
480486
{
481487
struct nk_property_variant variant;
488+
nk_bool changed;
482489
NK_ASSERT(ctx);
483490
NK_ASSERT(name);
484491
NK_ASSERT(val);
485492

486-
if (!ctx || !ctx->current || !name || !val) return;
493+
if (!ctx || !ctx->current || !name || !val) return nk_false;
487494
variant = nk_property_variant_double(*val, min, max, step);
488495
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT);
496+
changed = variant.value.d != *val;
489497
*val = variant.value.d;
498+
return changed;
490499
}
491500
NK_API int
492501
nk_propertyi(struct nk_context *ctx, const char *name, int min, int val,

0 commit comments

Comments
 (0)