@@ -5773,6 +5773,10 @@ struct nk_property_state {
57735773 unsigned int seq;
57745774 unsigned int old;
57755775 int state;
5776+ int prev_state;
5777+ nk_hash prev_name;
5778+ char prev_buffer[NK_MAX_NUMBER_BUFFER];
5779+ int prev_length;
57765780};
57775781
57785782struct nk_window {
@@ -7033,7 +7037,7 @@ nk_strtod(const char *str, char **endptr)
70337037 }
70347038 number = value * neg;
70357039 if (endptr)
7036- *endptr = p;
7040+ *endptr = (char *) p;
70377041 return number;
70387042}
70397043#endif
@@ -28809,6 +28813,28 @@ nk_draw_property(struct nk_command_buffer *out, const struct nk_style_property *
2880928813 nk_widget_text(out, *label, name, len, &text, NK_TEXT_CENTERED, font);
2881028814 }
2881128815}
28816+ NK_INTERN void
28817+ nk_property_save(struct nk_property_variant *variant, char *buffer, int len)
28818+ {
28819+ buffer[len] = '\0';
28820+ switch (variant->kind) {
28821+ default: break;
28822+ case NK_PROPERTY_INT:
28823+ variant->value.i = nk_strtoi(buffer, 0);
28824+ variant->value.i = NK_CLAMP(variant->min_value.i, variant->value.i, variant->max_value.i);
28825+ break;
28826+ case NK_PROPERTY_FLOAT:
28827+ nk_string_float_limit(buffer, NK_MAX_FLOAT_PRECISION);
28828+ variant->value.f = nk_strtof(buffer, 0);
28829+ variant->value.f = NK_CLAMP(variant->min_value.f, variant->value.f, variant->max_value.f);
28830+ break;
28831+ case NK_PROPERTY_DOUBLE:
28832+ nk_string_float_limit(buffer, NK_MAX_FLOAT_PRECISION);
28833+ variant->value.d = NK_STRTOD(buffer, 0);
28834+ variant->value.d = NK_CLAMP(variant->min_value.d, variant->value.d, variant->max_value.d);
28835+ break;
28836+ }
28837+ }
2881228838NK_LIB void
2881328839nk_do_property(nk_flags *ws,
2881428840 struct nk_command_buffer *out, struct nk_rect property,
@@ -28932,7 +28958,7 @@ nk_do_property(nk_flags *ws,
2893228958 variant->value.d = NK_CLAMP(variant->min_value.d, variant->value.d + variant->step.d, variant->max_value.d); break;
2893328959 }
2893428960 }
28935- if (old != NK_PROPERTY_EDIT && (*state == NK_PROPERTY_EDIT)) {
28961+ if (!old && (*state == NK_PROPERTY_EDIT)) {
2893628962 /* property has been activated so setup buffer */
2893728963 NK_MEMCPY(buffer, dst, (nk_size)*length);
2893828964 *cursor = nk_utf_len(buffer, *length);
@@ -28967,24 +28993,7 @@ nk_do_property(nk_flags *ws,
2896728993 if (active && !text_edit->active) {
2896828994 /* property is now not active so convert edit text to value*/
2896928995 *state = NK_PROPERTY_DEFAULT;
28970- buffer[*len] = '\0';
28971- switch (variant->kind) {
28972- default: break;
28973- case NK_PROPERTY_INT:
28974- variant->value.i = nk_strtoi(buffer, 0);
28975- variant->value.i = NK_CLAMP(variant->min_value.i, variant->value.i, variant->max_value.i);
28976- break;
28977- case NK_PROPERTY_FLOAT:
28978- nk_string_float_limit(buffer, NK_MAX_FLOAT_PRECISION);
28979- variant->value.f = nk_strtof(buffer, 0);
28980- variant->value.f = NK_CLAMP(variant->min_value.f, variant->value.f, variant->max_value.f);
28981- break;
28982- case NK_PROPERTY_DOUBLE:
28983- nk_string_float_limit(buffer, NK_MAX_FLOAT_PRECISION);
28984- variant->value.d = NK_STRTOD(buffer, 0);
28985- variant->value.d = NK_CLAMP(variant->min_value.d, variant->value.d, variant->max_value.d);
28986- break;
28987- }
28996+ nk_property_save(variant, buffer, *len);
2898828997 }
2898928998}
2899028999NK_LIB struct nk_property_variant
@@ -29032,6 +29041,7 @@ nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant
2903229041
2903329042 struct nk_rect bounds;
2903429043 enum nk_widget_layout_states s;
29044+ nk_bool hot;
2903529045
2903629046 int *state = 0;
2903729047 nk_hash hash = 0;
@@ -29041,6 +29051,7 @@ nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant
2904129051 int *select_begin = 0;
2904229052 int *select_end = 0;
2904329053 int old_state;
29054+ int prev_state;
2904429055
2904529056 char dummy_buffer[NK_MAX_NUMBER_BUFFER];
2904629057 int dummy_state = NK_PROPERTY_DEFAULT;
@@ -29067,8 +29078,15 @@ nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant
2906729078 name++; /* special number hash */
2906829079 } else hash = nk_murmur_hash(name, (int)nk_strlen(name), 42);
2906929080
29081+ /* check if property is previously hot */
29082+ if (win->property.prev_state == NK_PROPERTY_EDIT && hash == win->property.prev_name) {
29083+ nk_property_save(variant, win->property.prev_buffer, win->property.prev_length);
29084+ win->property.prev_state = NK_PROPERTY_DEFAULT;
29085+ }
29086+
2907029087 /* check if property is currently hot item */
29071- if (win->property.active && hash == win->property.name) {
29088+ hot = win->property.active && hash == win->property.name;
29089+ if (hot) {
2907229090 buffer = win->property.buffer;
2907329091 len = &win->property.length;
2907429092 cursor = &win->property.cursor;
@@ -29086,6 +29104,7 @@ nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant
2908629104
2908729105 /* execute property widget */
2908829106 old_state = *state;
29107+ prev_state = win->property.state;
2908929108 ctx->text_edit.clip = ctx->clip;
2909029109 in = ((s == NK_WIDGET_ROM && !win->property.active) ||
2909129110 layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED) ? 0 : &ctx->input;
@@ -29094,7 +29113,14 @@ nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant
2909429113 select_end, &style->property, filter, in, style->font, &ctx->text_edit,
2909529114 ctx->button_behavior);
2909629115
29097- if (in && *state != NK_PROPERTY_DEFAULT && !win->property.active) {
29116+ if (in && *state != NK_PROPERTY_DEFAULT && !hot) {
29117+ /* another property was active */
29118+ if (win->property.active /* && hash != win->property.name */) {
29119+ win->property.prev_state = prev_state;
29120+ win->property.prev_name = win->property.name;
29121+ win->property.prev_length = win->property.length;
29122+ NK_MEMCPY(win->property.prev_buffer, win->property.buffer, win->property.length);
29123+ }
2909829124 /* current property is now hot */
2909929125 win->property.active = 1;
2910029126 NK_MEMCPY(win->property.buffer, buffer, (nk_size)*len);
0 commit comments