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
This commit is contained in:
parent
070cde61b5
commit
c30176e7ff
|
@ -77,6 +77,21 @@ _user_value_update(Evas_Object *obj, double value)
|
|||
evas_object_smart_changed(obj);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
@ -335,6 +334,40 @@ _val_set(Evas_Object *obj)
|
|||
evas_object_smart_changed(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)
|
||||
{
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue