summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-07-16 13:58:42 +0200
committerXavi Artigas <xavierartigas@yahoo.es>2019-07-16 16:37:29 +0200
commit1bae8ec521f9e49453f51b921dbab1fe9c95fd6c (patch)
treead1a98fc2becdb53930131fd217a0471c229c4b0
parent1d90b113e0b1b5dd4fa7476168b6a8ff8dc06cc3 (diff)
efl_ui_slider: change the semantical meaning of step property
Summary: before the step property was used as a relative value. The value that was added in the end was (max-min)*step. Which is quite confusing given the fact that the other APIs in in efl_ui_range_display are also taking values absolut. Other implementations also do so. fix T4834 Subscribers: cedric, #reviewers, #committers Tags: #efl Maniphest Tasks: T4834 Differential Revision: https://phab.enlightenment.org/D9327
-rw-r--r--src/bin/elementary/test_ui_slider.c25
-rw-r--r--src/lib/elementary/efl_ui_slider.c8
-rw-r--r--src/tests/elementary/efl_ui_test_slider.c37
3 files changed, 49 insertions, 21 deletions
diff --git a/src/bin/elementary/test_ui_slider.c b/src/bin/elementary/test_ui_slider.c
index 38447efbc4..75df5f9d98 100644
--- a/src/bin/elementary/test_ui_slider.c
+++ b/src/bin/elementary/test_ui_slider.c
@@ -4,17 +4,6 @@
4#include <Efl_Ui.h> 4#include <Efl_Ui.h>
5#include <Elementary.h> 5#include <Elementary.h>
6 6
7static double
8_step_size_calculate(double min, double max)
9{
10 double step = 0.0;
11 int steps = 0;
12
13 steps = max - min;
14 if (steps) step = (1.0 / steps);
15 return step;
16}
17
18static void 7static void
19_slider_changed_cb(void *data EINA_UNUSED, const Efl_Event *ev) 8_slider_changed_cb(void *data EINA_UNUSED, const Efl_Event *ev)
20{ 9{
@@ -31,7 +20,6 @@ void
31test_ui_slider(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) 20test_ui_slider(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
32{ 21{
33 Eo *win, *bx, *hbx; 22 Eo *win, *bx, *hbx;
34 double step;
35 23
36 win = efl_add_ref(EFL_UI_WIN_CLASS, NULL, 24 win = efl_add_ref(EFL_UI_WIN_CLASS, NULL,
37 efl_ui_win_type_set(efl_added, EFL_UI_WIN_TYPE_BASIC), 25 efl_ui_win_type_set(efl_added, EFL_UI_WIN_TYPE_BASIC),
@@ -67,11 +55,10 @@ test_ui_slider(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event
67 efl_text_interactive_editable_set(efl_added, EINA_FALSE), 55 efl_text_interactive_editable_set(efl_added, EINA_FALSE),
68 efl_pack(bx, efl_added)); 56 efl_pack(bx, efl_added));
69 57
70 step = _step_size_calculate(0, 9);
71 efl_add(EFL_UI_SLIDER_CLASS, bx, 58 efl_add(EFL_UI_SLIDER_CLASS, bx,
72 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(120, 0)), 59 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(120, 0)),
73 efl_gfx_hint_align_set(efl_added, 0.5, 0.5), 60 efl_gfx_hint_align_set(efl_added, 0.5, 0.5),
74 efl_ui_range_step_set(efl_added, step), 61 efl_ui_range_step_set(efl_added, 0.1),
75 efl_pack(bx, efl_added)); 62 efl_pack(bx, efl_added));
76 63
77 efl_add(EFL_UI_TEXT_CLASS, bx, 64 efl_add(EFL_UI_TEXT_CLASS, bx,
@@ -82,7 +69,7 @@ test_ui_slider(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event
82 efl_add(EFL_UI_SLIDER_CLASS, bx, 69 efl_add(EFL_UI_SLIDER_CLASS, bx,
83 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(120, 0)), 70 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(120, 0)),
84 efl_ui_range_limits_set(efl_added, 10, 145), 71 efl_ui_range_limits_set(efl_added, 10, 145),
85 efl_ui_range_step_set(efl_added, step), 72 efl_ui_range_step_set(efl_added, 9),
86 elm_object_disabled_set(efl_added, EINA_TRUE), 73 elm_object_disabled_set(efl_added, EINA_TRUE),
87 efl_pack(bx, efl_added)); 74 efl_pack(bx, efl_added));
88 75
@@ -98,7 +85,7 @@ test_ui_slider(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event
98 efl_add(EFL_UI_SLIDER_CLASS, hbx, 85 efl_add(EFL_UI_SLIDER_CLASS, hbx,
99 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(0, 160)), 86 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(0, 160)),
100 efl_ui_range_limits_set(efl_added, 10, 145), 87 efl_ui_range_limits_set(efl_added, 10, 145),
101 efl_ui_range_step_set(efl_added, step), 88 efl_ui_range_step_set(efl_added, 9),
102 efl_ui_range_value_set(efl_added, 70), 89 efl_ui_range_value_set(efl_added, 70),
103 efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_VERTICAL), 90 efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_VERTICAL),
104 efl_pack(hbx, efl_added)); 91 efl_pack(hbx, efl_added));
@@ -106,7 +93,7 @@ test_ui_slider(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event
106 efl_add(EFL_UI_SLIDER_CLASS, hbx, 93 efl_add(EFL_UI_SLIDER_CLASS, hbx,
107 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(0, 160)), 94 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(0, 160)),
108 efl_ui_range_limits_set(efl_added, 10, 145), 95 efl_ui_range_limits_set(efl_added, 10, 145),
109 efl_ui_range_step_set(efl_added, step), 96 efl_ui_range_step_set(efl_added, 9),
110 efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_VERTICAL), 97 efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_VERTICAL),
111 elm_object_disabled_set(efl_added, EINA_TRUE), 98 elm_object_disabled_set(efl_added, EINA_TRUE),
112 efl_pack(hbx, efl_added)); 99 efl_pack(hbx, efl_added));
@@ -115,7 +102,7 @@ test_ui_slider(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event
115 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(0, 160)), 102 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(0, 160)),
116 efl_ui_range_limits_set(efl_added, 10, 145), 103 efl_ui_range_limits_set(efl_added, 10, 145),
117 efl_ui_range_value_set(efl_added, 35), 104 efl_ui_range_value_set(efl_added, 35),
118 efl_ui_range_step_set(efl_added, step), 105 efl_ui_range_step_set(efl_added, 9),
119 efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_VERTICAL | EFL_UI_LAYOUT_ORIENTATION_INVERTED), 106 efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_VERTICAL | EFL_UI_LAYOUT_ORIENTATION_INVERTED),
120 efl_pack(hbx, efl_added)); 107 efl_pack(hbx, efl_added));
121 108
@@ -127,7 +114,7 @@ test_ui_slider(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event
127 efl_add(EFL_UI_SLIDER_CLASS, bx, 114 efl_add(EFL_UI_SLIDER_CLASS, bx,
128 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(260, 0)), 115 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(260, 0)),
129 efl_ui_range_limits_set(efl_added, 0, 150), 116 efl_ui_range_limits_set(efl_added, 0, 150),
130 efl_ui_range_step_set(efl_added, step), 117 efl_ui_range_step_set(efl_added, 9),
131 efl_event_callback_add(efl_added, EFL_UI_SLIDER_EVENT_CHANGED, _slider_changed_cb, NULL), 118 efl_event_callback_add(efl_added, EFL_UI_SLIDER_EVENT_CHANGED, _slider_changed_cb, NULL),
132 efl_pack(bx, efl_added)); 119 efl_pack(bx, efl_added));
133} 120}
diff --git a/src/lib/elementary/efl_ui_slider.c b/src/lib/elementary/efl_ui_slider.c
index 2eb3f28ac7..7deda127db 100644
--- a/src/lib/elementary/efl_ui_slider.c
+++ b/src/lib/elementary/efl_ui_slider.c
@@ -205,6 +205,7 @@ _drag_up(void *data,
205 const char *source EINA_UNUSED) 205 const char *source EINA_UNUSED)
206{ 206{
207 double step; 207 double step;
208 double relative_step;
208 209
209 EFL_UI_SLIDER_DATA_GET(data, sd); 210 EFL_UI_SLIDER_DATA_GET(data, sd);
210 step = sd->step; 211 step = sd->step;
@@ -212,12 +213,13 @@ _drag_up(void *data,
212 if (efl_ui_layout_orientation_is_inverted(sd->dir)) step *= -1.0; 213 if (efl_ui_layout_orientation_is_inverted(sd->dir)) step *= -1.0;
213 214
214 ELM_WIDGET_DATA_GET_OR_RETURN(data, wd); 215 ELM_WIDGET_DATA_GET_OR_RETURN(data, wd);
216 relative_step = step/(sd->val_max - sd->val_min);
215 if (elm_widget_is_legacy(obj)) 217 if (elm_widget_is_legacy(obj))
216 efl_ui_drag_step_move(efl_part(wd->resize_obj, "elm.dragable.slider"), 218 efl_ui_drag_step_move(efl_part(wd->resize_obj, "elm.dragable.slider"),
217 step, step); 219 step, step);
218 else 220 else
219 efl_ui_drag_step_move(efl_part(wd->resize_obj, "efl.dragable.slider"), 221 efl_ui_drag_step_move(efl_part(wd->resize_obj, "efl.dragable.slider"),
220 step, step); 222 relative_step, relative_step);
221} 223}
222 224
223static void 225static void
@@ -227,6 +229,7 @@ _drag_down(void *data,
227 const char *source EINA_UNUSED) 229 const char *source EINA_UNUSED)
228{ 230{
229 double step; 231 double step;
232 double relative_step;
230 233
231 EFL_UI_SLIDER_DATA_GET(data, sd); 234 EFL_UI_SLIDER_DATA_GET(data, sd);
232 step = -sd->step; 235 step = -sd->step;
@@ -234,12 +237,13 @@ _drag_down(void *data,
234 if (efl_ui_layout_orientation_is_inverted(sd->dir)) step *= -1.0; 237 if (efl_ui_layout_orientation_is_inverted(sd->dir)) step *= -1.0;
235 238
236 ELM_WIDGET_DATA_GET_OR_RETURN(data, wd); 239 ELM_WIDGET_DATA_GET_OR_RETURN(data, wd);
240 relative_step = step/(sd->val_max - sd->val_min);
237 if (elm_widget_is_legacy(obj)) 241 if (elm_widget_is_legacy(obj))
238 efl_ui_drag_step_move(efl_part(wd->resize_obj, "elm.dragable.slider"), 242 efl_ui_drag_step_move(efl_part(wd->resize_obj, "elm.dragable.slider"),
239 step, step); 243 step, step);
240 else 244 else
241 efl_ui_drag_step_move(efl_part(wd->resize_obj, "efl.dragable.slider"), 245 efl_ui_drag_step_move(efl_part(wd->resize_obj, "efl.dragable.slider"),
242 step, step); 246 relative_step, relative_step);
243} 247}
244 248
245static Eina_Bool 249static Eina_Bool
diff --git a/src/tests/elementary/efl_ui_test_slider.c b/src/tests/elementary/efl_ui_test_slider.c
index 55f5f938c2..ff820b01f5 100644
--- a/src/tests/elementary/efl_ui_test_slider.c
+++ b/src/tests/elementary/efl_ui_test_slider.c
@@ -52,7 +52,44 @@ EFL_START_TEST(efl_ui_test_slider_events)
52} 52}
53EFL_END_TEST 53EFL_END_TEST
54 54
55EFL_START_TEST(efl_ui_test_slider_step)
56{
57 Eo *slider;
58 Evas *e;
59 Eo *win = win_add();
60
61 efl_gfx_entity_size_set(win, EINA_SIZE2D(400, 100));
62 slider = efl_add(EFL_UI_SLIDER_CLASS, win,
63 efl_event_callback_add(efl_added, EFL_UI_SLIDER_EVENT_CHANGED, slider_changed, NULL),
64 efl_event_callback_add(efl_added, EFL_UI_SLIDER_EVENT_STEADY, slider_changed, NULL),
65 efl_gfx_entity_size_set(efl_added, EINA_SIZE2D(400, 100))
66 );
67 efl_ui_range_limits_set(slider, 0, 100);
68 efl_ui_range_step_set(slider, 10);
69 efl_ui_range_value_set(slider, 20);
70
71 e = evas_object_evas_get(win);
72
73 efl_layout_signal_process(slider, EINA_TRUE);
74 get_me_to_those_events(slider);
75
76
77 int x, y, w, h;
78 int sx, sy, sw, sh;
79
80 evas_object_geometry_get(elm_object_part_content_get(slider, "efl.bar"), &x, &y, &w, &h);
81 evas_object_geometry_get(slider, &sx, &sy, &sw, &sh);
82 evas_event_feed_mouse_in(e, 0, NULL);
83 evas_event_feed_mouse_move(e, x + (w / 2), y + (h / 2), 0, NULL);
84 evas_event_feed_mouse_wheel(e, -1, 1, 0, NULL);
85 evas_event_feed_mouse_up(e, 1, 0, 0, NULL);
86 efl_layout_signal_process(slider, EINA_TRUE);
87 get_me_to_those_events(slider);
88 ck_assert_int_eq(efl_ui_range_value_get(slider), 10);
89}
90EFL_END_TEST
55void efl_ui_test_slider(TCase *tc) 91void efl_ui_test_slider(TCase *tc)
56{ 92{
57 tcase_add_test(tc, efl_ui_test_slider_events); 93 tcase_add_test(tc, efl_ui_test_slider_events);
94 tcase_add_test(tc, efl_ui_test_slider_step);
58} 95}