From abde958791e0f57160c154c74b947672244c9a13 Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Tue, 22 Dec 2009 12:11:21 +0000 Subject: [PATCH] elm_slider : Add indicator format callback function and drag signals Hello all, I just made my first attempt to improve Elementary. The attached patch adds an indicator format callback function for showing a more versatile indicator string. It also sends drag start/stop signals when the dragging starts and ends. This is useful for showing a music playback progress slider. When the slider indicator is being dragged, the indicator would show the "seek position" in time. When the dragging is stopped, the music player can then seek to the correct position. I couldn't figure out how to do this with elm_slider, so I just added these lines. By: Brian Wang SVN revision: 44649 --- legacy/elementary/src/lib/Elementary.h.in | 3 ++ legacy/elementary/src/lib/elm_slider.c | 37 ++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/legacy/elementary/src/lib/Elementary.h.in b/legacy/elementary/src/lib/Elementary.h.in index 2b6389ea0c..04a8e74172 100644 --- a/legacy/elementary/src/lib/Elementary.h.in +++ b/legacy/elementary/src/lib/Elementary.h.in @@ -788,6 +788,7 @@ extern "C" { EAPI void elm_slider_span_size_set(Evas_Object *obj, Evas_Coord size); EAPI void elm_slider_unit_format_set(Evas_Object *obj, const char *format); EAPI void elm_slider_indicator_format_set(Evas_Object *obj, const char *indicator); + EAPI void elm_slider_indicator_format_function_set(Evas_Object *obj, const char *(*func)(double val)); EAPI void elm_slider_horizontal_set(Evas_Object *obj, Eina_Bool horizontal); EAPI void elm_slider_min_max_set(Evas_Object *obj, double min, double max); EAPI void elm_slider_value_set(Evas_Object *obj, double val); @@ -796,6 +797,8 @@ extern "C" { /* smart callbacks called: * "changed" - when the slider value changes * "delay,changed" - when the slider value changed, but a small time after a change (use this if you only want to respond to a change once the slider is held still for a short while). + * "slider,drag,start" - dragging the slider indicator around has started + * "slider,drag,stop" - dragging the slider indicator around has stopped */ typedef enum _Elm_Genlist_Item_Flags diff --git a/legacy/elementary/src/lib/elm_slider.c b/legacy/elementary/src/lib/elm_slider.c index 2e95df2a29..d97a1485a0 100644 --- a/legacy/elementary/src/lib/elm_slider.c +++ b/legacy/elementary/src/lib/elm_slider.c @@ -16,6 +16,10 @@ * period or when they release their finger/mouse, so it avoids possibly * expensive reactions to the value change. * + * slider,drag,start - dragging the slider indicator around has started + * + * slider,drag,stop - dragging the slider indicator around has stopped + * * A slider can be horizontal or vertical. It can contain an Icon and has a * primary label as well as a units label (that is formatted with floating * point values and thus accepts a printf-style format string, like @@ -45,6 +49,7 @@ struct _Widget_Data const char *label; const char *units; const char *indicator; + const char *(*indicator_format_func)(double val); Eina_Bool horizontal : 1; Eina_Bool inverted : 1; double val, val_min, val_max; @@ -206,7 +211,14 @@ static void _indicator_set(Evas_Object *obj) { Widget_Data *wd = elm_widget_data_get(obj); - if (wd->indicator) + if (wd->indicator_format_func) + { + const char *buf; + + buf = wd->indicator_format_func(wd->val); + edje_object_part_text_set(wd->slider, "elm.indicator", buf); + } + else if (wd->indicator) { char buf[1024]; @@ -229,6 +241,7 @@ static void _drag_start(void *data, Evas_Object *obj, const char *emission, const char *source) { _val_fetch(data); + evas_object_smart_callback_call(data, "slider,drag,start", NULL); _units_set(data); _indicator_set(data); } @@ -237,6 +250,7 @@ static void _drag_stop(void *data, Evas_Object *obj, const char *emission, const char *source) { _val_fetch(data); + evas_object_smart_callback_call(data, "slider,drag,stop", NULL); _units_set(data); _indicator_set(data); } @@ -579,3 +593,24 @@ elm_slider_inverted_set(Evas_Object *obj, Eina_Bool inverted) _units_set(obj); _indicator_set(obj); } + +/** + * Set the format function pointer for the inducator area + * + * Set the callback function to format the indicator string. + * See elm_slider_indicator_format_set() for more info on how this works. + * + * @param obj The slider object + * @param indicator The format string for the indicator display + * @param func The indicator format function + * + * @ingroup Slider + */ +EAPI void +elm_slider_indicator_format_function_set(Evas_Object *obj, const char *(*func)(double val)) +{ + Widget_Data *wd = elm_widget_data_get(obj); + wd->indicator_format_func = func; + _indicator_set(obj); +} +