From 3497975a2fe5083f9fc59201b6c5753bf68e74dd Mon Sep 17 00:00:00 2001 From: Gustavo Lima Chaves Date: Mon, 6 Dec 2010 12:45:33 +0000 Subject: [PATCH] Better handling of mouse wheel events for sliders. SVN revision: 55323 --- src/bin/test_slider.c | 23 ++++++++++++++++++----- src/lib/elm_slider.c | 34 +++++++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/bin/test_slider.c b/src/bin/test_slider.c index d1b51cf..e17b67b 100644 --- a/src/bin/test_slider.c +++ b/src/bin/test_slider.c @@ -38,7 +38,7 @@ test_slider(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info sl = elm_slider_add(win); sl1 = sl; - elm_slider_label_set(sl, "Label"); + elm_slider_label_set(sl, "Horizontal"); elm_slider_icon_set(sl, ic); elm_slider_unit_format_set(sl, "%1.1f units"); elm_slider_span_size_set(sl, 120); @@ -54,7 +54,7 @@ test_slider(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); sl = elm_slider_add(win); - elm_slider_label_set(sl, "Label 2"); + elm_slider_label_set(sl, "Horizontal inverted"); elm_slider_end_set(sl, ic); elm_slider_span_size_set(sl, 80); evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5); @@ -71,7 +71,7 @@ test_slider(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info sl = elm_slider_add(win); elm_slider_indicator_show_set(sl, EINA_FALSE); - elm_slider_label_set(sl, "Label 3"); + elm_slider_label_set(sl, "Scale doubled"); elm_slider_unit_format_set(sl, "%3.0f units"); elm_slider_span_size_set(sl, 40); evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5); @@ -92,7 +92,7 @@ test_slider(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info sl = elm_slider_add(win); elm_slider_icon_set(sl, ic); - elm_slider_label_set(sl, "Label 4"); + elm_slider_label_set(sl, "Vertical inverted"); elm_slider_inverted_set(sl, 1); elm_slider_unit_format_set(sl, "units"); elm_slider_span_size_set(sl, 60); @@ -106,9 +106,22 @@ test_slider(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info evas_object_show(ic); evas_object_show(sl); - evas_object_smart_callback_add(sl1, "changed", _change_cb, sl); + sl = elm_slider_add(win); + elm_slider_label_set(sl, "Vertical"); + elm_slider_unit_format_set(sl, "units"); + elm_slider_span_size_set(sl, 60); + evas_object_size_hint_align_set(sl, 0.5, EVAS_HINT_FILL); + evas_object_size_hint_weight_set(sl, 0.0, EVAS_HINT_EXPAND); + elm_slider_indicator_format_set(sl, "%1.1f"); + elm_slider_value_set(sl, 0.2); + elm_object_scale_set(sl, 1.0); + elm_slider_horizontal_set(sl, EINA_FALSE); + elm_box_pack_end(bx, sl); + evas_object_show(ic); + evas_object_show(sl); + evas_object_show(win); } #endif diff --git a/src/lib/elm_slider.c b/src/lib/elm_slider.c index 3d31151..334c727 100644 --- a/src/lib/elm_slider.c +++ b/src/lib/elm_slider.c @@ -59,6 +59,8 @@ struct _Widget_Data Evas_Coord size; }; +#define ELM_SLIDER_INVERTED_FACTOR (-1.0) + static const char *widtype = NULL; static void _del_hook(Evas_Object *obj); static void _theme_hook(Evas_Object *obj); @@ -362,17 +364,39 @@ _drag_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSE } static void +_drag_step(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__) +{ + _val_fetch(data); + _units_set(data); + _indicator_set(data); +} + +static void _drag_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__) { - Widget_Data *wd = elm_widget_data_get(data); - edje_object_part_drag_step(wd->slider, "elm.dragable.slider", -0.05, -0.05); + double step; + Widget_Data *wd; + + wd = elm_widget_data_get(data); + step = 0.05; + + if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR; + + edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step); } static void _drag_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__) { - Widget_Data *wd = elm_widget_data_get(data); - edje_object_part_drag_step(wd->slider, "elm.dragable.slider", 0.05, 0.05); + double step; + Widget_Data *wd; + + wd = elm_widget_data_get(data); + step = -0.05; + + if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR; + + edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step); } /** @@ -417,7 +441,7 @@ elm_slider_add(Evas_Object *parent) edje_object_signal_callback_add(wd->slider, "drag", "*", _drag, obj); edje_object_signal_callback_add(wd->slider, "drag,start", "*", _drag_start, obj); edje_object_signal_callback_add(wd->slider, "drag,stop", "*", _drag_stop, obj); - edje_object_signal_callback_add(wd->slider, "drag,step", "*", _drag_stop, obj); + edje_object_signal_callback_add(wd->slider, "drag,step", "*", _drag_step, obj); edje_object_signal_callback_add(wd->slider, "drag,page", "*", _drag_stop, obj); // edje_object_signal_callback_add(wd->slider, "drag,set", "*", _drag_stop, obj); edje_object_signal_callback_add(wd->slider, "mouse,wheel,0,-1", "*", _drag_up, obj); -- 2.7.4