From 845d6d1b57b207f09b351a923b02c5330907a5d4 Mon Sep 17 00:00:00 2001 From: Woochan Lee Date: Mon, 18 Dec 2017 13:23:32 +0900 Subject: [PATCH] efl_ui_spin_button: Fix can't input number in case of the min value is bigger than 1. Summary: Min Max validate logic has been changed to support decimal point counting. It makes this side effect. Test Plan: elementary_test -> efl_ui_spin_button sample. (On the min max filter enabled.) Reviewers: jpeg, Jaehyun_Cho, woohyun Reviewed By: Jaehyun_Cho Subscribers: cedric, jpeg Differential Revision: https://phab.enlightenment.org/D5580 --- src/lib/elementary/efl_ui_spin_button.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/lib/elementary/efl_ui_spin_button.c b/src/lib/elementary/efl_ui_spin_button.c index d8d0f9ddb6..42667938eb 100644 --- a/src/lib/elementary/efl_ui_spin_button.c +++ b/src/lib/elementary/efl_ui_spin_button.c @@ -285,7 +285,7 @@ _min_max_validity_filter(void *data, Evas_Object *obj, char **text) const char *str, *point; char *insert, *new_str = NULL; double val; - int max_len, len; + int max_len = 0, len; EINA_SAFETY_ON_NULL_RETURN(data); EINA_SAFETY_ON_NULL_RETURN(obj); @@ -299,15 +299,9 @@ _min_max_validity_filter(void *data, Evas_Object *obj, char **text) insert = *text; new_str = _text_insert(str, insert, elm_entry_cursor_pos_get(obj)); if (!new_str) return; - max_len = log10(fabs(pd->val_max)) + 1; + if (strchr(new_str, '-')) max_len++; - new_str = _text_insert(str, insert, elm_entry_cursor_pos_get(obj)); - if (pd->format_type == SPIN_FORMAT_INT) - { - len = strlen(new_str); - if (len < max_len) goto end; - } - else if (pd->format_type == SPIN_FORMAT_FLOAT) + if (pd->format_type == SPIN_FORMAT_FLOAT) { point = strchr(new_str, '.'); if (point) @@ -320,6 +314,11 @@ _min_max_validity_filter(void *data, Evas_Object *obj, char **text) } } + max_len += (fabs(pd->val_max) > fabs(pd->val_min)) ? + (log10(fabs(pd->val_max)) + 1) : (log10(fabs(pd->val_min)) + 1); + len = strlen(new_str); + if (len < max_len) goto end; + val = strtod(new_str, NULL); if ((val < pd->val_min) || (val > pd->val_max)) *insert = 0;