diff --git a/legacy/elementary/ChangeLog b/legacy/elementary/ChangeLog index 87489c4530..1af3046b58 100644 --- a/legacy/elementary/ChangeLog +++ b/legacy/elementary/ChangeLog @@ -192,3 +192,7 @@ 2012-06-14 Michael Bouchaud * Add an enum to Elm_Calendar_Mark_Repeat_Type: ELM_CALENDAR_LAST_DAY_OF_MONTH + +2012-06-15 Michael Bouchaud + * elm_progressbar: elm_progressbar_format_function_set to add a callback + function to format the unit string. diff --git a/legacy/elementary/src/lib/elm_progressbar.c b/legacy/elementary/src/lib/elm_progressbar.c index 61f2b64f31..1c23e0a218 100644 --- a/legacy/elementary/src/lib/elm_progressbar.c +++ b/legacy/elementary/src/lib/elm_progressbar.c @@ -23,6 +23,9 @@ struct _Elm_Progressbar_Smart_Data Eina_Bool inverted : 1; Eina_Bool pulse : 1; Eina_Bool pulse_state : 1; + + char *(*unit_format_func)(double val); + void (*unit_format_free)(char *str); }; #define ELM_PROGRESSBAR_DATA_GET(o, sd) \ @@ -74,7 +77,15 @@ _units_set(Evas_Object *obj) { ELM_PROGRESSBAR_DATA_GET(obj, sd); - if (sd->units) + if (sd->unit_format_func) + { + char *buf; + + buf = sd->unit_format_func(sd->val); + elm_layout_text_set(obj, "elm.text.status", buf); + if (sd->unit_format_free) sd->unit_format_free(buf); + } + else if (sd->units) { char buf[1024]; @@ -428,6 +439,19 @@ elm_progressbar_unit_format_get(const Evas_Object *obj) return sd->units; } +EAPI void +elm_progressbar_unit_format_function_set(Evas_Object *obj, char *(func)(double), void (*free_func) (char *)) +{ + ELM_PROGRESSBAR_CHECK(obj); + ELM_PROGRESSBAR_DATA_GET(obj, sd); + + sd->unit_format_func = func; + sd->unit_format_free = free_func; + + _units_set(obj); + elm_layout_sizing_eval(obj); +} + EAPI void elm_progressbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal) diff --git a/legacy/elementary/src/lib/elm_progressbar.h b/legacy/elementary/src/lib/elm_progressbar.h index 989433dedb..40b8840e51 100644 --- a/legacy/elementary/src/lib/elm_progressbar.h +++ b/legacy/elementary/src/lib/elm_progressbar.h @@ -228,6 +228,23 @@ EAPI void elm_progressbar_unit_format_set(Evas_Object *o */ EAPI const char *elm_progressbar_unit_format_get(const Evas_Object *obj); +/** + * Set the format function pointer for the units label + * + * @param obj The progress bar object + * @param func The unit format function + * @param free_func The freeing function for the format string. + * + * Set the callback function to format the unit string. + * + * @see elm_progressbar_unit_format_set() for more info on how this works. + * + * @since 1.1.0 + * + * @ingroup Progressbar + */ +EAPI void elm_progressbar_unit_format_function_set(Evas_Object *obj, char *(func)(double), void (*free_func) (char *)); + /** * Set the orientation of a given progress bar widget *