aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHosang Kim <hosang12.kim@samsung.com>2017-07-11 16:25:44 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-07-11 16:34:14 +0900
commitf41e2761608fff7b070d630a73848908c6be5e5b (patch)
treecf47583270aa7434147084985dcc43b8930f1462
parentevas: Add a test case with a custom font (diff)
downloadefl-f41e2761608fff7b070d630a73848908c6be5e5b.tar.gz
slider: Allow range limitations
Summary: When user drags slider, slider value cannot be changed by API. However the necessity of above behavior has emerged. Because sometimes applications want limitation of slider value. Test Plan: elementary_test -> slider -> Limited Reviewers: woohyun, cedric, SanghyeonLee, singh.amitesh, jpeg Reviewed By: jpeg Subscribers: cedric, jpeg Differential Revision: https://phab.enlightenment.org/D4883
-rw-r--r--src/bin/elementary/test_slider.c93
-rw-r--r--src/lib/edje/edje_calc.c9
-rw-r--r--src/lib/edje/edje_util.c3
3 files changed, 100 insertions, 5 deletions
diff --git a/src/bin/elementary/test_slider.c b/src/bin/elementary/test_slider.c
index 9956a9be78..68e3f884ef 100644
--- a/src/bin/elementary/test_slider.c
+++ b/src/bin/elementary/test_slider.c
@@ -3,17 +3,82 @@
#endif
#include <Elementary.h>
+struct _api_data
+{
+ Evas_Object *slider;
+ Evas_Object *popup;
+ Eina_Bool limit;
+};
+typedef struct _api_data api_data;
+
void
_delay_change_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
- printf("delay,changed! slider value : %d\n", (int)round(elm_slider_value_get(obj)));
+ printf("delay,changed! slider value : %d\n", (int)round(elm_slider_value_get(obj)));
}
void
_change_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
+ double val = elm_slider_value_get(obj);
+ elm_slider_value_set(data, val);
+}
+
+static void
+_ok_btn_clicked(void *data, Evas_Object *obj EINA_UNUSED,
+ void *event_info EINA_UNUSED)
+{
+ api_data *api = data;
+ api->limit = EINA_FALSE;
+ evas_object_del(api->popup);
+ api->popup = NULL;
+}
+
+static void
+_close_btn_clicked(void *data, Evas_Object *obj EINA_UNUSED,
+ void *event_info EINA_UNUSED)
+{
+ api_data *api = data;
+ evas_object_del(api->popup);
+ api->popup = NULL;
+}
+
+void
+_popup_add(api_data *api)
+{
+ Evas_Object *win;
+ Evas_Object *btn, *btn2;
+
+ if (!api->popup)
+ {
+ win = elm_object_top_widget_get(api->slider);
+ api->popup = elm_popup_add(win);
+
+ elm_object_text_set(api->popup, "Tap Ok to allow the value to be increased above 80.");
+
+ btn = elm_button_add(api->popup);
+ elm_object_text_set(btn, "Ok");
+ elm_object_part_content_set(api->popup, "button1", btn);
+ evas_object_smart_callback_add(btn, "clicked", _ok_btn_clicked, api);
+
+ btn2 = elm_button_add(api->popup);
+ elm_object_text_set(btn2, "Close");
+ elm_object_part_content_set(api->popup, "button2", btn2);
+ evas_object_smart_callback_add(btn2, "clicked", _close_btn_clicked, api);
+
+ evas_object_show(api->popup);
+ }
+}
+
+void
+_change_cb2(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
+{
+ api_data *api = data;
double val = elm_slider_value_get(obj);
- elm_slider_value_set(data, val);
+ if (val >= 80.0 && api->limit) {
+ elm_slider_value_set(obj, 80.0);
+ _popup_add(api);
+ }
}
void
@@ -68,6 +133,12 @@ _change_range_print_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_inf
printf("range values:- from: %f, to: %f\n", from, to);
}
+static void
+_cleanup_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
+{
+ free(data);
+}
+
void
test_slider(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
@@ -75,8 +146,11 @@ test_slider(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_in
double step;
char buf[PATH_MAX];
+ api_data *api = calloc(1, sizeof(api_data));
+
win = elm_win_util_standard_add("slider", "Slider");
elm_win_autodel_set(win, EINA_TRUE);
+ evas_object_event_callback_add(win, EVAS_CALLBACK_FREE, _cleanup_cb, api);
fr = elm_frame_add(win);
evas_object_size_hint_weight_set(fr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
@@ -196,6 +270,21 @@ test_slider(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_in
elm_box_pack_end(bx, sl);
evas_object_show(sl);
+ // limited slider
+ api->slider = sl = elm_slider_add(bx);
+ api->limit = EINA_TRUE;
+ elm_object_text_set(sl, "Limited");
+ elm_slider_span_size_set(sl, 120);
+ elm_slider_unit_format_set(sl, "%1.0f units");
+ elm_slider_indicator_format_set(sl, "%1.0f");
+ elm_slider_min_max_set(sl, 0, 100);
+ evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
+ evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, 0.0);
+ elm_box_pack_end(bx, sl);
+ evas_object_show(sl);
+
+ evas_object_smart_callback_add(sl, "changed", _change_cb2, api);
+
// scale doubled slider
sl = elm_slider_add(bx);
elm_slider_indicator_show_set(sl, EINA_FALSE);
diff --git a/src/lib/edje/edje_calc.c b/src/lib/edje/edje_calc.c
index fdae32a975..1bad0321cc 100644
--- a/src/lib/edje/edje_calc.c
+++ b/src/lib/edje/edje_calc.c
@@ -1072,6 +1072,7 @@ _edje_part_dragable_calc(Edje *ed EINA_UNUSED, Edje_Real_Part *ep, FLOAT_T *x, F
void
_edje_dragable_pos_set(Edje *ed, Edje_Real_Part *ep, FLOAT_T x, FLOAT_T y)
{
+ Evas_Coord ex = 0, ey = 0;
/* check whether this part is dragable at all */
if (!ep->drag) return;
@@ -1080,8 +1081,12 @@ _edje_dragable_pos_set(Edje *ed, Edje_Real_Part *ep, FLOAT_T x, FLOAT_T y)
* value we would set foo to, because it would depend on the
* size of the dragable...
*/
+ evas_object_geometry_get(ep->object, &ex, &ey, NULL, NULL);
+
if (NEQ(ep->drag->x, x) || ep->drag->tmp.x)
{
+ if (ep->drag->down.count > 0)
+ ep->drag->down.x = ex;
ep->drag->x = x;
ep->drag->tmp.x = 0;
ep->drag->need_reset = 0;
@@ -1091,6 +1096,8 @@ _edje_dragable_pos_set(Edje *ed, Edje_Real_Part *ep, FLOAT_T x, FLOAT_T y)
if (NEQ(ep->drag->y, y) || ep->drag->tmp.y)
{
+ if (ep->drag->down.count > 0)
+ ep->drag->down.y = ey;
ep->drag->y = y;
ep->drag->tmp.y = 0;
ep->drag->need_reset = 0;
@@ -5157,7 +5164,9 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta
dy = ZERO;
_edje_part_dragable_calc(ed, ep, &dx, &dy);
ep->drag->x = dx;
+ ep->drag->val.x = dx;
ep->drag->y = dy;
+ ep->drag->val.y = dy;
ep->drag->tmp.x = 0;
ep->drag->tmp.y = 0;
ep->drag->need_reset = 0;
diff --git a/src/lib/edje/edje_util.c b/src/lib/edje/edje_util.c
index 601661336f..0829a803de 100644
--- a/src/lib/edje/edje_util.c
+++ b/src/lib/edje/edje_util.c
@@ -3517,7 +3517,6 @@ _edje_object_part_drag_value_set(Edje *ed, const char *part, double dx, double d
rp = _edje_real_part_recursive_get(&ed, part);
if (!rp) return EINA_FALSE;
if (!rp->drag) return EINA_FALSE;
- if (rp->drag->down.count > 0) return EINA_FALSE;
EINA_LIST_FOREACH(ed->user_defined, l, eud)
if (eud->type == EDJE_USER_DRAG_VALUE && !strcmp(part, eud->part))
@@ -3827,7 +3826,6 @@ _edje_object_part_drag_step(Edje *ed, const char *part, double dx, double dy)
rp = _edje_real_part_recursive_get(&ed, part);
if (!rp) return EINA_FALSE;
if (!rp->drag) return EINA_FALSE;
- if (rp->drag->down.count > 0) return EINA_FALSE;
EINA_LIST_FOREACH(ed->user_defined, l, eud)
if (eud->type == EDJE_USER_DRAG_STEP && !strcmp(part, eud->part))
@@ -3879,7 +3877,6 @@ _edje_object_part_drag_page(Edje *ed, const char *part, double dx, double dy)
rp = _edje_real_part_recursive_get(&ed, part);
if (!rp) return EINA_FALSE;
if (!rp->drag) return EINA_FALSE;
- if (rp->drag->down.count > 0) return EINA_FALSE;
EINA_LIST_FOREACH(ed->user_defined, l, eud)
if (eud->type == EDJE_USER_DRAG_PAGE && !strcmp(part, eud->part))