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
This commit is contained in:
Gustavo Sverzut Barbieri 2009-12-22 12:11:21 +00:00
parent 3de84a0229
commit abde958791
2 changed files with 39 additions and 1 deletions

View File

@ -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

View File

@ -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);
}