spinner: add entry filter for accepted only digits and "." 60/54260/1
authorwoochan lee <wc0917.lee@samsung.com>
Tue, 10 Nov 2015 00:28:19 +0000 (16:28 -0800)
committerwoochan lee <wc0917.lee@samsung.com>
Mon, 14 Dec 2015 10:24:20 +0000 (02:24 -0800)
Summary:
When spinner activated with entry, user can input any characters in entry.
It degrades the usability.

Add filter for only can input numbers and "." for case of decimal point existing.

I will add entry filter for limit size as well after this commit.
This spinner features may help for app developer and users too.

@feature

Test Plan:
Run elementary_test
Test various spinner format for check this.

Reviewers: Hermet, cedric

Subscribers: id213sin, shilpasingh

Differential Revision: https://phab.enlightenment.org/D3299

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Change-Id: I19c656584b940039efcae0d3bacba1380d5bd5ca

src/lib/elm_spinner.c
src/lib/elm_widget_spinner.h

index db3781a..61b3a58 100644 (file)
@@ -390,6 +390,47 @@ _entry_activated_cb(void *data,
    return EINA_TRUE;
 }
 
+static int
+_decimal_points_get(const char *label)
+{
+   char result[2];
+   const char *start = strchr(label, '%');
+
+   while (start)
+     {
+        if (start[1] != '%')
+          {
+             start = strchr(start, '.');
+             start++;
+             break;
+          }
+        else
+          start = strchr(start + 2, '%');
+     }
+
+   sscanf(start, "%[^f]", result);
+
+   return atoi(result);
+}
+
+static void
+_entry_filter_add(Evas_Object *obj)
+{
+   ELM_SPINNER_DATA_GET(obj, sd);
+   static Elm_Entry_Filter_Accept_Set digits_filter_data;
+
+   if (!sd->ent) return;
+
+   elm_entry_markup_filter_remove(sd->ent, elm_entry_filter_accept_set, &digits_filter_data);
+
+   if (sd->decimal_points > 0)
+     digits_filter_data.accepted = ".0123456789";
+   else
+     digits_filter_data.accepted = "0123456789";
+
+   elm_entry_markup_filter_append(sd->ent, elm_entry_filter_accept_set, &digits_filter_data);
+}
+
 static void
 _entry_show_cb(void *data,
                Evas *e EINA_UNUSED,
@@ -435,6 +476,7 @@ _toggle_entry(Evas_Object *obj)
              eo_do(sd->ent, eo_event_callback_add
                (ELM_ENTRY_EVENT_ACTIVATED, _entry_activated_cb, obj));
              elm_layout_content_set(obj, "elm.swallow.entry", sd->ent);
+             _entry_filter_add(obj);
           }
         if (!sd->button_layout)
           {
@@ -1315,8 +1357,13 @@ EOLIAN static void
 _elm_spinner_label_format_set(Eo *obj, Elm_Spinner_Data *sd, const char *fmt)
 {
    eina_stringshare_replace(&sd->label, fmt);
+
+   if (fmt && !(_is_label_format_integer(sd->label)))
+     sd->decimal_points = _decimal_points_get(sd->label);
+
    _label_write(obj);
    elm_layout_sizing_eval(obj);
+   _entry_filter_add(obj);
 }
 
 EOLIAN static const char*
index 151b704..4287eec 100644 (file)
@@ -35,6 +35,7 @@ struct _Elm_Spinner_Data
    double                drag_prev_pos, drag_val_step;
    double                spin_speed, interval, first_interval;
    int                   round;
+   int                   decimal_points;
    Ecore_Timer          *delay_change_timer; /**< a timer for a delay,changed smart callback */
    Ecore_Timer          *spin_timer; /**< a timer for a repeated spinner value change on mouse down */
    Ecore_Timer          *longpress_timer; /**< a timer to detect long press. After lonpress timeout,