slider: fix value error from step submit/tizen/20191118.220200
authorBowon Ryu <bowon.ryu@samsung.com>
Mon, 18 Nov 2019 12:25:26 +0000 (21:25 +0900)
committerJongmin Lee <jm105.lee@samsung.com>
Mon, 18 Nov 2019 21:54:36 +0000 (06:54 +0900)
Summary:
When the slider moves using step,
_drag_value_fetch(), _val_fetch() calculates a value from position of edje_part.
Then the calculated value is updated.
However, this causes a slight error.

This patch updates value ​​first when moving with steps.

* Test Example

```
Evas_Object *sl = elm_slider_add(bx);
elm_slider_min_max_set(sl, -5, 5);
elm_slider_value_set(sl, 0.0);
elm_slider_step_set(sl, 0.1);
evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_smart_callback_add(sl, "changed", _change_cb, NULL);
```
```
void
_change_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
   double val = elm_slider_value_get(obj);

   if (val == -5.0) printf("val[%f] == -5.0 \n", val);
   if (val == -4.0) printf("val[%f] == -4.0 \n", val);
   if (val == -3.0) printf("val[%f] == -3.0 \n", val);
   if (val == -2.0) printf("val[%f] == -2.0 \n", val);
   if (val == -1.0) printf("val[%f] == -1.0 \n", val);
   if (val == 0.0) printf("val[%f] == 0.0 \n", val);
   if (val == 1.0) printf("val[%f] == 1.0 \n", val);
   if (val == 2.0) printf("val[%f] == 2.0 \n", val);
   if (val == 3.0) printf("val[%f] == 3.0 \n", val);
   if (val == 4.0) printf("val[%f] == 4.0 \n", val);
   if (val == 5.0) printf("val[%f] == 5.0 \n", val);
}
```

If you move the slider using step in this test,
You can see that some logs are not visible. (Some values ​​are incorrect)

Test Plan:
elementary_test -to slider
elementary_test -to efl.ui.slider

Reviewers: woohyun, cedric, bu5hm4n

Reviewed By: woohyun, bu5hm4n

Subscribers: bu5hm4n, #reviewers, #committers

Tags: #efl

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

src/lib/elementary/efl_ui_slider.c
src/lib/elementary/elm_priv.h
src/lib/elementary/elm_slider.c

index 149e21c..7fa0967 100644 (file)
@@ -78,6 +78,21 @@ _user_value_update(Evas_Object *obj, double value)
 }
 
 static void
+_step_value_update(Evas_Object *obj, double step)
+{
+   double value;
+
+   EFL_UI_SLIDER_DATA_GET(obj, sd);
+
+   if (efl_ui_mirrored_get(obj) ^ efl_ui_layout_orientation_is_inverted(sd->dir))
+     step *= -1.0;
+
+   value = CLAMP(sd->val + step, sd->val_min, sd->val_max);
+   _user_value_update(obj, value);
+
+}
+
+static void
 _drag_value_fetch(Evas_Object *obj)
 {
    EFL_UI_SLIDER_DATA_GET(obj, sd);
@@ -194,7 +209,8 @@ _drag_up(Evas_Object *obj)
 
    efl_ui_drag_step_move(efl_part(wd->resize_obj, "efl.draggable.slider"),
                            relative_step, relative_step);
-   _drag_value_fetch(obj);
+
+   _step_value_update(obj, step);
 }
 
 static void
@@ -214,7 +230,8 @@ _drag_down(Evas_Object *obj)
 
    efl_ui_drag_step_move(efl_part(wd->resize_obj, "efl.draggable.slider"),
                            relative_step, relative_step);
-   _drag_value_fetch(obj);
+
+   _step_value_update(obj, step);
 }
 
 static Eina_Bool
index 04c0344..6b8ea3d 100644 (file)
@@ -334,6 +334,9 @@ extern const char *_elm_engines[];
 # define ELM_PRIV_SMART_CALLBACKS_DESC(name, signal, type) \
    {name, type},
 
+# define CLAMP(x, min, max) \
+   (((x) > (max)) ? (max) : (((x) < (min)) ? (min) : (x)))
+
 struct _Elm_Config_Flags
 {
    Eina_Bool engine : 1;
index 34e8cf4..5d485d5 100644 (file)
@@ -382,6 +382,40 @@ _val_set(Evas_Object *obj)
 }
 
 static void
+_user_value_update(Evas_Object *obj, double value)
+{
+   double val = value;
+
+   ELM_SLIDER_DATA_GET_OR_RETURN(obj, sd);
+
+   if (fabs(val - sd->val) > DBL_EPSILON)
+     {
+        sd->val = val;
+        sd->intvl_from = val;
+        _val_set(obj);
+
+        evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
+        ecore_timer_del(sd->delay);
+        sd->delay = ecore_timer_add(SLIDER_DELAY_CHANGED_INTERVAL, _delay_change, obj);
+     }
+}
+
+static void
+_step_value_update(Evas_Object *obj, double step)
+{
+   double value, absolute_step;
+
+   ELM_SLIDER_DATA_GET(obj, sd);
+
+   if (efl_ui_mirrored_get(obj) ^ efl_ui_layout_orientation_is_inverted(sd->dir))
+     step *= -1.0;
+
+   absolute_step = step * (sd->val_max - sd->val_min);
+   value = CLAMP(sd->val + absolute_step, sd->val_min, sd->val_max);
+   _user_value_update(obj, value);
+}
+
+static void
 _val_fetch(Evas_Object *obj, Eina_Bool user_event)
 {
    double posx = 0.0, posy = 0.0, pos = 0.0, val;
@@ -544,6 +578,8 @@ _drag_up(void *data,
    ELM_WIDGET_DATA_GET_OR_RETURN(data, wd);
    efl_ui_drag_step_move(efl_part(wd->resize_obj, "elm.dragable.slider"),
                          step, step);
+
+   _step_value_update(data, step);
 }
 
 static void
@@ -562,6 +598,8 @@ _drag_down(void *data,
    ELM_WIDGET_DATA_GET_OR_RETURN(data, wd);
    efl_ui_drag_step_move(efl_part(wd->resize_obj, "elm.dragable.slider"),
                          step, step);
+
+   _step_value_update(data, step);
 }
 
 static Eina_Bool