FlipSelector: fix items creation when range is used
authorDaniel Zaoui <daniel.zaoui@yahoo.com>
Mon, 26 Nov 2018 08:32:31 +0000 (10:32 +0200)
committerHermet Park <hermetpark@gmail.com>
Wed, 5 Dec 2018 05:37:06 +0000 (14:37 +0900)
In the case step is 0, the application will enter in an infinite loop
where the max will never be reached. To fix this, step is set to 1 if 0
is given by the user.
Moreover, step is forced to positive. According to the given min and
max values, the step will be negative or positive. In this way, we are
sure to be inside the correct range.

src/lib/elementary/elm_flipselector.c

index 66b840bd0c7f347212ed3f282371dd786d23b2a5..ec771789c69af853933b1a9b9fccf618c00ef9ab 100644 (file)
@@ -490,14 +490,18 @@ static void
 _items_add(Evas_Object *obj)
 {
    double d;
+   Eina_Bool reverse;
    char buf[16];
 
    ELM_FLIPSELECTOR_DATA_GET(obj, sd);
+   reverse = (sd->val_min > sd->val_max);
    _clear_items(obj);
-   for (d = sd->val_min; d < sd->val_max; d = d + sd->step)
+   for (d = sd->val_min; d < sd->val_max;)
      {
         snprintf(buf, sizeof(buf), "%.2f", d);
         elm_flipselector_item_append(obj, buf, NULL, NULL);
+        if (reverse) d = d - sd->step;
+        else d = d + sd->step;
      }
    snprintf(buf, sizeof(buf), "%.2f", sd->val_max);
    elm_flipselector_item_append(obj, buf, NULL, NULL);
@@ -506,7 +510,6 @@ _items_add(Evas_Object *obj)
 EOLIAN static void
 _elm_flipselector_efl_ui_range_range_min_max_set(Eo *obj, Elm_Flipselector_Data *sd, double min, double max)
 {
-   if (min > max) return;
    if ((sd->val_min == min) && (sd->val_max == max)) return;
 
    sd->val_min = min;
@@ -527,6 +530,9 @@ _elm_flipselector_efl_ui_range_range_step_set(Eo *obj EINA_UNUSED, Elm_Flipselec
 {
    if (sd->step == step) return;
 
+   if (step == 0.0) step = 1.0;
+   else if (step < 0.0) step *= -1;
+
    sd->step = step;
    _items_add(obj);
 }