cedric pushed a commit to branch master.

http://git.enlightenment.org/core/elementary.git/commit/?id=4b0f40e472c416e5547acf95068ad59c5fd3f8d2

commit 4b0f40e472c416e5547acf95068ad59c5fd3f8d2
Author: woochan lee <wc0917....@samsung.com>
Date:   Mon Nov 9 16:28:19 2015 -0800

    spinner: add entry filter for accepted only digits and "."
    
    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 <ced...@osg.samsung.com>
---
 src/lib/elm_spinner.c        | 47 ++++++++++++++++++++++++++++++++++++++++++++
 src/lib/elm_widget_spinner.h |  1 +
 2 files changed, 48 insertions(+)

diff --git a/src/lib/elm_spinner.c b/src/lib/elm_spinner.c
index db3781a..61b3a58 100644
--- a/src/lib/elm_spinner.c
+++ b/src/lib/elm_spinner.c
@@ -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*
diff --git a/src/lib/elm_widget_spinner.h b/src/lib/elm_widget_spinner.h
index 151b704..4287eec 100644
--- a/src/lib/elm_widget_spinner.h
+++ b/src/lib/elm_widget_spinner.h
@@ -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,

-- 


Reply via email to