spinner: Add to support spinner value %d format. 60/46960/3
authorwoochan lee <wc0917.lee@samsung.com>
Fri, 7 Aug 2015 07:58:54 +0000 (16:58 +0900)
committerJaeun Choi <jaeun12.choi@samsung.com>
Thu, 27 Aug 2015 11:06:57 +0000 (04:06 -0700)
Summary:
When user set min max as 50, 150 with %d format, then value set as 100.
The spinner value set as '0'
Because the sd->val type is double.
Spinner entry has same problem.

@fix

Test Plan:
Set spinner format as %d.
Check the spinner value.
It's not supported.

Reviewers: Jaehyun_Cho, cedric, Hermet

Reviewed By: Hermet

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

Conflicts:

src/lib/elm_spinner.c

Change-Id: I9095b06f80955066fc5697663e56a4903389b658
Origin: upstream

src/lib/elm_spinner.c

index 49966662f809a5d5a33fff8805bd0129e45a9015..f9e98f069b5716f9d53925a5490167c3f3d493ee 100644 (file)
@@ -50,6 +50,24 @@ static const Elm_Action key_actions[] = {
 static void _access_increment_decrement_info_say(Evas_Object *obj,
                                                  Eina_Bool is_incremented);
 
+static Eina_Bool
+_is_label_format_integer(const char *fmt)
+{
+   const char *start = strchr(fmt, '%');
+   const char *itr;
+
+   for (itr = start + 1; *itr != '\0'; itr++)
+     {
+        if ((*itr == 'd') || (*itr == 'u') || (*itr == 'i') ||
+            (*itr == 'o') || (*itr == 'x') || (*itr == 'X'))
+          return EINA_TRUE;
+        else if ((*itr == 'f'))
+          return EINA_FALSE;
+     }
+
+   return EINA_FALSE;
+}
+
 static void
 _entry_show(Elm_Spinner_Data *sd)
 {
@@ -100,9 +118,13 @@ _entry_show(Elm_Spinner_Data *sd)
                }
           }
      }
-   snprintf(buf, sizeof(buf), fmt, sd->val);
 
 apply:
+   if (_is_label_format_integer(fmt))
+     snprintf(buf, sizeof(buf), fmt, (int)sd->val);
+   else
+     snprintf(buf, sizeof(buf), fmt, sd->val);
+
    elm_object_text_set(sd->ent, buf);
 }
 
@@ -125,7 +147,12 @@ _label_write(Evas_Object *obj)
      }
 
    if (sd->label)
-     snprintf(buf, sizeof(buf), sd->label, sd->val);
+     {
+        if (_is_label_format_integer(sd->label))
+          snprintf(buf, sizeof(buf), sd->label, (int)sd->val);
+        else
+          snprintf(buf, sizeof(buf), sd->label, sd->val);
+     }
    else
      snprintf(buf, sizeof(buf), "%.0f", sd->val);