Skip to content

Commit 987c8b8

Browse files
authored
Return if value changed for property_*() and combobox*() functions (#912)
2 parents 1fb5865 + a94e6ed commit 987c8b8

File tree

4 files changed

+86
-40
lines changed

4 files changed

+86
-40
lines changed

nuklear.h

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3594,7 +3594,7 @@ NK_API nk_bool nk_color_pick(struct nk_context*, struct nk_colorf*, enum nk_colo
35943594
* a `#` at the beginning. It will not be shown but guarantees correct behavior.
35953595
*
35963596
* ```c
3597-
* void nk_property_int(struct nk_context *ctx, const char *name, int min, int *val, int max, int step, float inc_per_pixel);
3597+
* nk_bool nk_property_int(struct nk_context *ctx, const char *name, int min, int *val, int max, int step, float inc_per_pixel);
35983598
* ```
35993599
*
36003600
* Parameter | Description
@@ -3606,8 +3606,10 @@ NK_API nk_bool nk_color_pick(struct nk_context*, struct nk_colorf*, enum nk_colo
36063606
* \param[in] max | Maximum value not allowed to be overflown
36073607
* \param[in] step | Increment added and subtracted on increment and decrement button
36083608
* \param[in] inc_per_pixel | Value per pixel added or subtracted on dragging
3609+
*
3610+
* \returns `true(1)` if the value changed
36093611
*/
3610-
NK_API void nk_property_int(struct nk_context*, const char *name, int min, int *val, int max, int step, float inc_per_pixel);
3612+
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);
36113613

36123614
/**
36133615
* # # nk_property_float
@@ -3617,7 +3619,7 @@ NK_API void nk_property_int(struct nk_context*, const char *name, int min, int *
36173619
* a `#` at the beginning. It will not be shown but guarantees correct behavior.
36183620
*
36193621
* ```c
3620-
* void nk_property_float(struct nk_context *ctx, const char *name, float min, float *val, float max, float step, float inc_per_pixel);
3622+
* nk_bool nk_property_float(struct nk_context *ctx, const char *name, float min, float *val, float max, float step, float inc_per_pixel);
36213623
* ```
36223624
*
36233625
* Parameter | Description
@@ -3629,8 +3631,10 @@ NK_API void nk_property_int(struct nk_context*, const char *name, int min, int *
36293631
* \param[in] max | Maximum value not allowed to be overflown
36303632
* \param[in] step | Increment added and subtracted on increment and decrement button
36313633
* \param[in] inc_per_pixel | Value per pixel added or subtracted on dragging
3634+
*
3635+
* \returns `true(1)` if the value changed
36323636
*/
3633-
NK_API void nk_property_float(struct nk_context*, const char *name, float min, float *val, float max, float step, float inc_per_pixel);
3637+
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);
36343638

36353639
/**
36363640
* # # nk_property_double
@@ -3640,7 +3644,7 @@ NK_API void nk_property_float(struct nk_context*, const char *name, float min, f
36403644
* a `#` at the beginning. It will not be shown but guarantees correct behavior.
36413645
*
36423646
* ```c
3643-
* void nk_property_double(struct nk_context *ctx, const char *name, double min, double *val, double max, double step, double inc_per_pixel);
3647+
* nk_bool nk_property_double(struct nk_context *ctx, const char *name, double min, double *val, double max, double step, double inc_per_pixel);
36443648
* ```
36453649
*
36463650
* Parameter | Description
@@ -3652,8 +3656,10 @@ NK_API void nk_property_float(struct nk_context*, const char *name, float min, f
36523656
* \param[in] max | Maximum value not allowed to be overflown
36533657
* \param[in] step | Increment added and subtracted on increment and decrement button
36543658
* \param[in] inc_per_pixel | Value per pixel added or subtracted on dragging
3659+
*
3660+
* \returns `true(1)` if the value changed
36553661
*/
3656-
NK_API void nk_property_double(struct nk_context*, const char *name, double min, double *val, double max, double step, float inc_per_pixel);
3662+
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);
36573663

36583664
/**
36593665
* # # nk_propertyi
@@ -3795,10 +3801,10 @@ NK_API int nk_combo(struct nk_context*, const char *const *items, int count, int
37953801
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);
37963802
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);
37973803
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);
3798-
NK_API void nk_combobox(struct nk_context*, const char *const *items, int count, int *selected, int item_height, struct nk_vec2 size);
3799-
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);
3800-
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);
3801-
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);
3804+
NK_API nk_bool nk_combobox(struct nk_context*, const char *const *items, int count, int *selected, int item_height, struct nk_vec2 size);
3805+
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);
3806+
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);
3807+
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);
38023808
/* =============================================================================
38033809
*
38043810
* ABSTRACT COMBOBOX
@@ -29179,47 +29185,56 @@ nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant
2917929185
win->edit.active = nk_false;
2918029186
}
2918129187
}
29182-
NK_API void
29188+
NK_API nk_bool
2918329189
nk_property_int(struct nk_context *ctx, const char *name,
2918429190
int min, int *val, int max, int step, float inc_per_pixel)
2918529191
{
2918629192
struct nk_property_variant variant;
29193+
nk_bool changed;
2918729194
NK_ASSERT(ctx);
2918829195
NK_ASSERT(name);
2918929196
NK_ASSERT(val);
2919029197

29191-
if (!ctx || !ctx->current || !name || !val) return;
29198+
if (!ctx || !ctx->current || !name || !val) return nk_false;
2919229199
variant = nk_property_variant_int(*val, min, max, step);
2919329200
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_INT);
29201+
changed = variant.value.i != *val;
2919429202
*val = variant.value.i;
29203+
return changed;
2919529204
}
29196-
NK_API void
29205+
NK_API nk_bool
2919729206
nk_property_float(struct nk_context *ctx, const char *name,
2919829207
float min, float *val, float max, float step, float inc_per_pixel)
2919929208
{
2920029209
struct nk_property_variant variant;
29210+
nk_bool changed;
2920129211
NK_ASSERT(ctx);
2920229212
NK_ASSERT(name);
2920329213
NK_ASSERT(val);
2920429214

29205-
if (!ctx || !ctx->current || !name || !val) return;
29215+
if (!ctx || !ctx->current || !name || !val) return nk_false;
2920629216
variant = nk_property_variant_float(*val, min, max, step);
2920729217
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT);
29218+
changed = variant.value.f != *val;
2920829219
*val = variant.value.f;
29220+
return changed;
2920929221
}
29210-
NK_API void
29222+
NK_API nk_bool
2921129223
nk_property_double(struct nk_context *ctx, const char *name,
2921229224
double min, double *val, double max, double step, float inc_per_pixel)
2921329225
{
2921429226
struct nk_property_variant variant;
29227+
nk_bool changed;
2921529228
NK_ASSERT(ctx);
2921629229
NK_ASSERT(name);
2921729230
NK_ASSERT(val);
2921829231

29219-
if (!ctx || !ctx->current || !name || !val) return;
29232+
if (!ctx || !ctx->current || !name || !val) return nk_false;
2922029233
variant = nk_property_variant_double(*val, min, max, step);
2922129234
nk_property(ctx, name, &variant, inc_per_pixel, NK_FILTER_FLOAT);
29235+
changed = variant.value.d != *val;
2922229236
*val = variant.value.d;
29237+
return changed;
2922329238
}
2922429239
NK_API int
2922529240
nk_propertyi(struct nk_context *ctx, const char *name, int min, int val,
@@ -30624,31 +30639,39 @@ nk_combo_callback(struct nk_context *ctx, void(*item_getter)(void*, int, const c
3062430639
nk_combo_end(ctx);
3062530640
} return selected;
3062630641
}
30627-
NK_API void
30642+
NK_API nk_bool
3062830643
nk_combobox(struct nk_context *ctx, const char *const *items, int count,
3062930644
int *selected, int item_height, struct nk_vec2 size)
3063030645
{
30646+
int tmp = *selected;
3063130647
*selected = nk_combo(ctx, items, count, *selected, item_height, size);
30648+
return tmp != *selected;
3063230649
}
30633-
NK_API void
30650+
NK_API nk_bool
3063430651
nk_combobox_string(struct nk_context *ctx, const char *items_separated_by_zeros,
3063530652
int *selected, int count, int item_height, struct nk_vec2 size)
3063630653
{
30654+
int tmp = *selected;
3063730655
*selected = nk_combo_string(ctx, items_separated_by_zeros, *selected, count, item_height, size);
30656+
return tmp != *selected;
3063830657
}
30639-
NK_API void
30658+
NK_API nk_bool
3064030659
nk_combobox_separator(struct nk_context *ctx, const char *items_separated_by_separator,
3064130660
int separator, int *selected, int count, int item_height, struct nk_vec2 size)
3064230661
{
30662+
int tmp = *selected;
3064330663
*selected = nk_combo_separator(ctx, items_separated_by_separator, separator,
3064430664
*selected, count, item_height, size);
30665+
return tmp != *selected;
3064530666
}
30646-
NK_API void
30667+
NK_API nk_bool
3064730668
nk_combobox_callback(struct nk_context *ctx,
3064830669
void(*item_getter)(void* data, int id, const char **out_text),
3064930670
void *userdata, int *selected, int count, int item_height, struct nk_vec2 size)
3065030671
{
30672+
int tmp = *selected;
3065130673
*selected = nk_combo_callback(ctx, item_getter, userdata, *selected, count, item_height, size);
30674+
return tmp != *selected;
3065230675
}
3065330676

3065430677

src/nuklear.h

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3371,7 +3371,7 @@ NK_API nk_bool nk_color_pick(struct nk_context*, struct nk_colorf*, enum nk_colo
33713371
* a `#` at the beginning. It will not be shown but guarantees correct behavior.
33723372
*
33733373
* ```c
3374-
* void nk_property_int(struct nk_context *ctx, const char *name, int min, int *val, int max, int step, float inc_per_pixel);
3374+
* nk_bool nk_property_int(struct nk_context *ctx, const char *name, int min, int *val, int max, int step, float inc_per_pixel);
33753375
* ```
33763376
*
33773377
* Parameter | Description
@@ -3383,8 +3383,10 @@ NK_API nk_bool nk_color_pick(struct nk_context*, struct nk_colorf*, enum nk_colo
33833383
* \param[in] max | Maximum value not allowed to be overflown
33843384
* \param[in] step | Increment added and subtracted on increment and decrement button
33853385
* \param[in] inc_per_pixel | Value per pixel added or subtracted on dragging
3386+
*
3387+
* \returns `true(1)` if the value changed
33863388
*/
3387-
NK_API void nk_property_int(struct nk_context*, const char *name, int min, int *val, int max, int step, float inc_per_pixel);
3389+
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);
33883390

33893391
/**
33903392
* # # nk_property_float
@@ -3394,7 +3396,7 @@ NK_API void nk_property_int(struct nk_context*, const char *name, int min, int *
33943396
* a `#` at the beginning. It will not be shown but guarantees correct behavior.
33953397
*
33963398
* ```c
3397-
* void nk_property_float(struct nk_context *ctx, const char *name, float min, float *val, float max, float step, float inc_per_pixel);
3399+
* nk_bool nk_property_float(struct nk_context *ctx, const char *name, float min, float *val, float max, float step, float inc_per_pixel);
33983400
* ```
33993401
*
34003402
* Parameter | Description
@@ -3406,8 +3408,10 @@ NK_API void nk_property_int(struct nk_context*, const char *name, int min, int *
34063408
* \param[in] max | Maximum value not allowed to be overflown
34073409
* \param[in] step | Increment added and subtracted on increment and decrement button
34083410
* \param[in] inc_per_pixel | Value per pixel added or subtracted on dragging
3411+
*
3412+
* \returns `true(1)` if the value changed
34093413
*/
3410-
NK_API void nk_property_float(struct nk_context*, const char *name, float min, float *val, float max, float step, float inc_per_pixel);
3414+
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);
34113415

34123416
/**
34133417
* # # nk_property_double
@@ -3417,7 +3421,7 @@ NK_API void nk_property_float(struct nk_context*, const char *name, float min, f
34173421
* a `#` at the beginning. It will not be shown but guarantees correct behavior.
34183422
*
34193423
* ```c
3420-
* void nk_property_double(struct nk_context *ctx, const char *name, double min, double *val, double max, double step, double inc_per_pixel);
3424+
* nk_bool nk_property_double(struct nk_context *ctx, const char *name, double min, double *val, double max, double step, double inc_per_pixel);
34213425
* ```
34223426
*
34233427
* Parameter | Description
@@ -3429,8 +3433,10 @@ NK_API void nk_property_float(struct nk_context*, const char *name, float min, f
34293433
* \param[in] max | Maximum value not allowed to be overflown
34303434
* \param[in] step | Increment added and subtracted on increment and decrement button
34313435
* \param[in] inc_per_pixel | Value per pixel added or subtracted on dragging
3436+
*
3437+
* \returns `true(1)` if the value changed
34323438
*/
3433-
NK_API void nk_property_double(struct nk_context*, const char *name, double min, double *val, double max, double step, float inc_per_pixel);
3439+
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);
34343440

34353441
/**
34363442
* # # nk_propertyi
@@ -3572,10 +3578,10 @@ NK_API int nk_combo(struct nk_context*, const char *const *items, int count, int
35723578
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);
35733579
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);
35743580
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);
3575-
NK_API void nk_combobox(struct nk_context*, const char *const *items, int count, int *selected, int item_height, struct nk_vec2 size);
3576-
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);
3577-
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);
3578-
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);
3581+
NK_API nk_bool nk_combobox(struct nk_context*, const char *const *items, int count, int *selected, int item_height, struct nk_vec2 size);
3582+
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);
3583+
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);
3584+
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);
35793585
/* =============================================================================
35803586
*
35813587
* 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)