summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwoochan lee <wc0917.lee@samsung.com>2015-11-09 16:28:19 -0800
committerCedric BAIL <cedric@osg.samsung.com>2015-11-09 16:28:22 -0800
commit4b0f40e472c416e5547acf95068ad59c5fd3f8d2 (patch)
treea0b2cde9a1eb03b8796faf5515be493e851b7b34
parent4421aee9d5aef3b670e5ab860d2a0a785c458486 (diff)
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 <cedric@osg.samsung.com>
-rw-r--r--src/lib/elm_spinner.c47
-rw-r--r--src/lib/elm_widget_spinner.h1
2 files changed, 48 insertions, 0 deletions
diff --git a/src/lib/elm_spinner.c b/src/lib/elm_spinner.c
index db3781a20..61b3a5832 100644
--- a/src/lib/elm_spinner.c
+++ b/src/lib/elm_spinner.c
@@ -390,6 +390,47 @@ _entry_activated_cb(void *data,
390 return EINA_TRUE; 390 return EINA_TRUE;
391} 391}
392 392
393static int
394_decimal_points_get(const char *label)
395{
396 char result[2];
397 const char *start = strchr(label, '%');
398
399 while (start)
400 {
401 if (start[1] != '%')
402 {
403 start = strchr(start, '.');
404 start++;
405 break;
406 }
407 else
408 start = strchr(start + 2, '%');
409 }
410
411 sscanf(start, "%[^f]", result);
412
413 return atoi(result);
414}
415
416static void
417_entry_filter_add(Evas_Object *obj)
418{
419 ELM_SPINNER_DATA_GET(obj, sd);
420 static Elm_Entry_Filter_Accept_Set digits_filter_data;
421
422 if (!sd->ent) return;
423
424 elm_entry_markup_filter_remove(sd->ent, elm_entry_filter_accept_set, &digits_filter_data);
425
426 if (sd->decimal_points > 0)
427 digits_filter_data.accepted = ".0123456789";
428 else
429 digits_filter_data.accepted = "0123456789";
430
431 elm_entry_markup_filter_append(sd->ent, elm_entry_filter_accept_set, &digits_filter_data);
432}
433
393static void 434static void
394_entry_show_cb(void *data, 435_entry_show_cb(void *data,
395 Evas *e EINA_UNUSED, 436 Evas *e EINA_UNUSED,
@@ -435,6 +476,7 @@ _toggle_entry(Evas_Object *obj)
435 eo_do(sd->ent, eo_event_callback_add 476 eo_do(sd->ent, eo_event_callback_add
436 (ELM_ENTRY_EVENT_ACTIVATED, _entry_activated_cb, obj)); 477 (ELM_ENTRY_EVENT_ACTIVATED, _entry_activated_cb, obj));
437 elm_layout_content_set(obj, "elm.swallow.entry", sd->ent); 478 elm_layout_content_set(obj, "elm.swallow.entry", sd->ent);
479 _entry_filter_add(obj);
438 } 480 }
439 if (!sd->button_layout) 481 if (!sd->button_layout)
440 { 482 {
@@ -1315,8 +1357,13 @@ EOLIAN static void
1315_elm_spinner_label_format_set(Eo *obj, Elm_Spinner_Data *sd, const char *fmt) 1357_elm_spinner_label_format_set(Eo *obj, Elm_Spinner_Data *sd, const char *fmt)
1316{ 1358{
1317 eina_stringshare_replace(&sd->label, fmt); 1359 eina_stringshare_replace(&sd->label, fmt);
1360
1361 if (fmt && !(_is_label_format_integer(sd->label)))
1362 sd->decimal_points = _decimal_points_get(sd->label);
1363
1318 _label_write(obj); 1364 _label_write(obj);
1319 elm_layout_sizing_eval(obj); 1365 elm_layout_sizing_eval(obj);
1366 _entry_filter_add(obj);
1320} 1367}
1321 1368
1322EOLIAN static const char* 1369EOLIAN static const char*
diff --git a/src/lib/elm_widget_spinner.h b/src/lib/elm_widget_spinner.h
index 151b704ea..4287eecc2 100644
--- a/src/lib/elm_widget_spinner.h
+++ b/src/lib/elm_widget_spinner.h
@@ -35,6 +35,7 @@ struct _Elm_Spinner_Data
35 double drag_prev_pos, drag_val_step; 35 double drag_prev_pos, drag_val_step;
36 double spin_speed, interval, first_interval; 36 double spin_speed, interval, first_interval;
37 int round; 37 int round;
38 int decimal_points;
38 Ecore_Timer *delay_change_timer; /**< a timer for a delay,changed smart callback */ 39 Ecore_Timer *delay_change_timer; /**< a timer for a delay,changed smart callback */
39 Ecore_Timer *spin_timer; /**< a timer for a repeated spinner value change on mouse down */ 40 Ecore_Timer *spin_timer; /**< a timer for a repeated spinner value change on mouse down */
40 Ecore_Timer *longpress_timer; /**< a timer to detect long press. After lonpress timeout, 41 Ecore_Timer *longpress_timer; /**< a timer to detect long press. After lonpress timeout,