diff options
author | Bowon Ryu <bowon.ryu@samsung.com> | 2019-11-18 21:25:26 +0900 |
---|---|---|
committer | WooHyun Jung <wh0705.jung@samsung.com> | 2019-11-18 21:25:26 +0900 |
commit | c30176e7ffac0ab70b8ef92cb0fce62b75499181 (patch) | |
tree | 41ba8ca7090ddda5baed1b881e13e00d947da5f9 | |
parent | 070cde61b5a55bae055a084aa4dffbca02dfdcba (diff) | |
download | efl-c30176e7ffac0ab70b8ef92cb0fce62b75499181.tar.gz |
slider: fix value error from step
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
-rw-r--r-- | src/lib/elementary/efl_ui_slider.c | 21 | ||||
-rw-r--r-- | src/lib/elementary/elm_priv.h | 3 | ||||
-rw-r--r-- | src/lib/elementary/elm_slider.c | 39 |
3 files changed, 60 insertions, 3 deletions
diff --git a/src/lib/elementary/efl_ui_slider.c b/src/lib/elementary/efl_ui_slider.c index 2aca5f96f5..219a15bc94 100644 --- a/src/lib/elementary/efl_ui_slider.c +++ b/src/lib/elementary/efl_ui_slider.c @@ -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 diff --git a/src/lib/elementary/elm_priv.h b/src/lib/elementary/elm_priv.h index 0d71bd0b08..0be9080eab 100644 --- a/src/lib/elementary/elm_priv.h +++ b/src/lib/elementary/elm_priv.h @@ -329,6 +329,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; diff --git a/src/lib/elementary/elm_slider.c b/src/lib/elementary/elm_slider.c index 85426386e2..c426a45aeb 100644 --- a/src/lib/elementary/elm_slider.c +++ b/src/lib/elementary/elm_slider.c @@ -144,7 +144,6 @@ _indicator_set(Evas_Object *obj) elm_layout_text_set(obj, "elm.dragable.slider:elm.indicator", str); if (sd->popup) edje_object_part_text_set(sd->popup, "elm.indicator", str); - if (sd->popup2) { eina_strbuf_reset(sd->indi_format_strbuf); @@ -336,6 +335,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; @@ -489,6 +522,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 @@ -507,6 +542,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 |