efl_ui_slider: correct to a multiple of step when drag is finished

Summary:
this is needed in order to support the value to be a multiple of the
step when drag has finished. The normal changed event is still emitted
with non-multiple of step, but the steady event only contains the
correct values now.

ref T8187

Reviewers: zmike, segfaultxavi, woohyun

Reviewed By: zmike

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Maniphest Tasks: T8187

Differential Revision: https://phab.enlightenment.org/D9928
This commit is contained in:
Marcel Hollerbach 2019-09-13 10:14:37 -04:00 committed by Mike Blumenkrantz
parent 6bac60262e
commit bc8c432841
2 changed files with 50 additions and 0 deletions

View File

@ -103,6 +103,17 @@ _drag_value_fetch(Evas_Object *obj)
}
}
static void
_adjust_to_step(Efl_Ui_Slider *obj, Efl_Ui_Slider_Data *pd)
{
if (pd->step)
{
double relative_step = pd->step/(pd->val_max - pd->val_min);
double new_value = (round(pd->val/relative_step))*relative_step;
_user_value_update(obj, new_value);
}
}
static void
_drag_value_update(Evas_Object *obj)
{
@ -518,6 +529,7 @@ _spacer_up_cb(void *data,
if (sd->spacer_down) sd->spacer_down = EINA_FALSE;
_drag_value_fetch(data);
_adjust_to_step(data, sd);
efl_event_callback_call(data, EFL_UI_SLIDER_EVENT_SLIDER_DRAG_STOP, NULL);
if (sd->frozen)

View File

@ -96,8 +96,46 @@ EFL_START_TEST(efl_ui_test_slider_step)
ck_assert_int_eq(efl_ui_range_value_get(slider), 10);
}
EFL_END_TEST
EFL_START_TEST(efl_ui_test_slider_step_drag)
{
Eo *slider;
Evas *e;
Eo *win = win_add();
efl_gfx_entity_size_set(win, EINA_SIZE2D(400, 100));
slider = efl_add(EFL_UI_SLIDER_CLASS, win,
efl_gfx_entity_size_set(efl_added, EINA_SIZE2D(400, 100))
);
efl_ui_range_limits_set(slider, 0, 100);
efl_ui_range_step_set(slider, 10);
efl_ui_range_value_set(slider, 20);
e = evas_object_evas_get(win);
efl_layout_signal_process(slider, EINA_TRUE);
get_me_to_those_events(slider);
int x, y, w, h;
int sx, sy, sw, sh;
evas_object_geometry_get(elm_object_part_content_get(slider, "efl.bar"), &x, &y, &w, &h);
evas_object_geometry_get(slider, &sx, &sy, &sw, &sh);
evas_event_feed_mouse_in(e, 0, NULL);
evas_event_feed_mouse_down(e, 1, 0, 0, NULL);
evas_event_feed_mouse_move(e, x + (w / 4)*3, y + (h / 4)*3, 0, NULL);
evas_event_feed_mouse_move(e, x + (w / 2), y + (h / 2), 0, NULL);
evas_event_feed_mouse_move(e, x + (w / 4), y + (h / 4), 0, NULL);
evas_event_feed_mouse_up(e, 1, 0, 0, NULL);
efl_layout_signal_process(slider, EINA_TRUE);
ck_assert_int_eq(efl_ui_range_value_get(slider), 20);
}
EFL_END_TEST
void efl_ui_test_slider(TCase *tc)
{
tcase_add_test(tc, efl_ui_test_slider_events);
tcase_add_test(tc, efl_ui_test_slider_step);
tcase_add_test(tc, efl_ui_test_slider_step_drag);
}