mirror of
https://github.com/armory3d/armorpaint.git
synced 2026-10-02 02:54:34 +08:00
ui: allow comma in slider
This commit is contained in:
+27
-10
@@ -2451,6 +2451,32 @@ int ui_combo(int *value, string_array_t *texts, char *label, bool show_label, in
|
||||
return (*value);
|
||||
}
|
||||
|
||||
static void ui_decimal_comma_to_dot(char *text) {
|
||||
if (strchr(text, '(') != NULL) {
|
||||
return;
|
||||
}
|
||||
// 1,1 -> 1.1
|
||||
for (char *c = text; *c != '\0'; ++c) {
|
||||
if (*c == ',' && (c == text || isdigit((unsigned char)c[-1])) && isdigit((unsigned char)c[1])) {
|
||||
*c = '.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float ui_parse_float(char *text) {
|
||||
ui_decimal_comma_to_dot(text);
|
||||
#ifdef WITH_EVAL
|
||||
char expression[UI_TEXT_MAX + 64];
|
||||
snprintf(expression, sizeof(expression), "float main() { return %s%s; }", text[0] == '.' ? "0" : "", text);
|
||||
minic_ctx_t *ctx = minic_eval(expression);
|
||||
float result = minic_ctx_result(ctx);
|
||||
minic_ctx_free(ctx);
|
||||
return result;
|
||||
#else
|
||||
return atof(text);
|
||||
#endif
|
||||
}
|
||||
|
||||
float ui_slider(float *value, char *text, float from, float to, bool filled, float precision, bool display_value, int align, bool text_edit) {
|
||||
current->item_changed = false;
|
||||
ui_id_t id = ui_widget_id(value, UI_ID_SLIDER);
|
||||
@@ -2512,16 +2538,7 @@ float ui_slider(float *value, char *text, float from, float to, bool filled, flo
|
||||
ui_update_text_edit(lalign, true);
|
||||
}
|
||||
if (current->submit_text_id == id) {
|
||||
char *text = current->text_to_submit;
|
||||
#ifdef WITH_EVAL
|
||||
char expression[UI_TEXT_MAX + 64];
|
||||
snprintf(expression, sizeof(expression), "float main() { return %s%s; }", text[0] == '.' ? "0" : "", text);
|
||||
minic_ctx_t *_ctx = minic_eval(expression);
|
||||
(*value) = minic_ctx_result(_ctx);
|
||||
minic_ctx_free(_ctx);
|
||||
#else
|
||||
(*value) = atof(text);
|
||||
#endif
|
||||
(*value) = ui_parse_float(current->text_to_submit);
|
||||
ui_finish_text_edit();
|
||||
current->item_changed = current->changed = true;
|
||||
}
|
||||
|
||||
@@ -321,6 +321,7 @@ char *ui_text_input(char **value, char *label, int align, bool editable, bool li
|
||||
bool ui_check(bool *value, char *text, char *label);
|
||||
bool ui_radio(int *value, int position, char *text, char *label);
|
||||
int ui_combo(int *value, string_array_t *texts, char *label, bool show_label, int align, bool search_bar);
|
||||
float ui_parse_float(char *text);
|
||||
float ui_slider(float *value, char *text, float from, float to, bool filled, float precision, bool display_value, int align, bool text_edit);
|
||||
void ui_row(f32_array_t *ratios);
|
||||
void ui_row2();
|
||||
|
||||
@@ -85,7 +85,7 @@ float ui_float_input(float *value, char *label, int align, float precision) {
|
||||
ui_set_next_id(1);
|
||||
ui_text_input(&text, label, align, true, false);
|
||||
if (ui_item_changed())
|
||||
*value = atof(text);
|
||||
*value = ui_parse_float(text);
|
||||
if (text != buffer)
|
||||
free(text);
|
||||
ui_pop_id();
|
||||
|
||||
Reference in New Issue
Block a user