elm_spinner: Support min,max filter for float format case.

Summary: The previous min, max filter doesn't support float format case.

Test Plan: elementary_test -> spinner.

Reviewers: jpeg, cedric, woohyun, myoungwoon

Subscribers: cedric, jpeg

Differential Revision: https://phab.enlightenment.org/D5016
This commit is contained in:
Woochan Lee 2017-08-22 14:31:04 +09:00 committed by Jean-Philippe Andre
parent 4656f98e22
commit d1631d8a86
2 changed files with 41 additions and 27 deletions

View File

@ -69,13 +69,6 @@ EFL_CALLBACKS_ARRAY_DEFINE(_inc_dec_button_cb,
static void _access_increment_decrement_info_say(Evas_Object *obj,
Eina_Bool is_incremented);
typedef enum _Elm_Spinner_Format_Type
{
SPINNER_FORMAT_FLOAT,
SPINNER_FORMAT_INT,
SPINNER_FORMAT_INVALID
} Elm_Spinner_Format_Type;
static Eina_Bool
_is_valid_digit(char x)
{
@ -547,8 +540,8 @@ _text_insert(const char *text, const char *input, int pos)
static void
_min_max_validity_filter(void *data, Evas_Object *obj, char **text)
{
const char *str, *new_str;
char *insert;
const char *str, *point;
char *insert, *new_str = NULL;
double val;
int max_len, len;
@ -564,20 +557,32 @@ _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(sd->val_max)) + 1;
len = evas_string_char_len_get(new_str);
if (len < max_len)
if (sd->format_type == SPINNER_FORMAT_INT)
{
ELM_SAFE_FREE(new_str, free);
return;
len = strlen(new_str);
if (len < max_len) goto end;
}
else if (sd->format_type == SPINNER_FORMAT_FLOAT)
{
point = strchr(new_str, '.');
if (point)
{
if ((int) strlen(point + 1) > sd->decimal_points)
{
*insert = 0;
goto end;
}
}
}
val = strtod(new_str, NULL);
ELM_SAFE_FREE(new_str, free);
if ((val < sd->val_min) || (val > sd->val_max))
*insert = 0;
end:
free(new_str);
}
static void
@ -1480,22 +1485,22 @@ EOLIAN static void
_elm_spinner_label_format_set(Eo *obj, Elm_Spinner_Data *sd, const char *fmt)
{
Elm_Spinner_Format_Type type;
if (fmt)
if (!fmt) fmt = "%.0f";
type = _is_label_format_integer(fmt);
if (type == SPINNER_FORMAT_INVALID)
{
type = _is_label_format_integer(fmt);
if (type == SPINNER_FORMAT_INVALID)
{
ERR("format:\"%s\" is Invalid, cannot be set", fmt);
return;
}
else if (type == SPINNER_FORMAT_FLOAT)
{
sd->decimal_points = _decimal_points_get(fmt);
}
ERR("format:\"%s\" is invalid, cannot be set", fmt);
return;
}
else if (type == SPINNER_FORMAT_FLOAT)
{
sd->decimal_points = _decimal_points_get(fmt);
}
eina_stringshare_replace(&sd->label, fmt);
sd->format_type = type;
_label_write(obj);
elm_layout_sizing_eval(obj);
_entry_accept_filter_add(obj);

View File

@ -25,6 +25,14 @@
/**
* Base layout smart data extended with spinner instance data.
*/
typedef enum _Elm_Spinner_Format_Type
{
SPINNER_FORMAT_FLOAT,
SPINNER_FORMAT_INT,
SPINNER_FORMAT_INVALID
} Elm_Spinner_Format_Type;
typedef struct _Elm_Spinner_Data Elm_Spinner_Data;
struct _Elm_Spinner_Data
{
@ -41,6 +49,7 @@ struct _Elm_Spinner_Data
Ecore_Timer *longpress_timer; /**< a timer to detect long press. After lonpress timeout,
start continuous change of values until mouse up */
Eina_List *special_values;
Elm_Spinner_Format_Type format_type;
Eina_Bool entry_visible : 1;
Eina_Bool entry_reactivate : 1;