Better handling of mouse wheel events for sliders.
authorGustavo Lima Chaves <glima@profusion.mobi>
Mon, 6 Dec 2010 12:45:33 +0000 (12:45 +0000)
committerGustavo Lima Chaves <glima@profusion.mobi>
Mon, 6 Dec 2010 12:45:33 +0000 (12:45 +0000)
SVN revision: 55323

src/bin/test_slider.c
src/lib/elm_slider.c

index d1b51cf..e17b67b 100644 (file)
@@ -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
index 3d31151..334c727 100644 (file)
@@ -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);