From 0c55c20e657e41a331f1bcc9ca184fafb761a763 Mon Sep 17 00:00:00 2001 From: Michael BOUCHAUD Date: Sun, 17 Jun 2012 11:41:19 +0000 Subject: [PATCH] elementary: add a test and an example for the unit format function in progressbar SVN revision: 72293 --- src/bin/test_progressbar.c | 15 ++++++++++++++- src/examples/progressbar_example.c | 21 +++++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/bin/test_progressbar.c b/src/bin/test_progressbar.c index 4164ea1..7d50f54 100644 --- a/src/bin/test_progressbar.c +++ b/src/bin/test_progressbar.c @@ -68,6 +68,18 @@ my_progressbar_destroy(void *data __UNUSED__, Evas_Object *obj, void *event_info evas_object_del(obj); } +static char * +my_progressbar_format_cb(double val) +{ + char buf[1024]; + int files; + + files = (1-val)*14000; + if(snprintf(buf, 30, "%i files left", files) > 0) + return strdup(buf); + return NULL; +} + void test_progressbar(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) { @@ -89,7 +101,8 @@ test_progressbar(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event elm_box_pack_end(bx, pb); // elm_progressbar_horizontal_set(pb, EINA_TRUE); // elm_object_text_set(pb, "Progression %"); -// elm_progressbar_unit_format_set(pb, NULL); + elm_progressbar_unit_format_function_set(pb, my_progressbar_format_cb, + (void (*)(char *)) free); evas_object_show(pb); _test_progressbar.pb1 = pb; diff --git a/src/examples/progressbar_example.c b/src/examples/progressbar_example.c index f7341a2..c402964 100644 --- a/src/examples/progressbar_example.c +++ b/src/examples/progressbar_example.c @@ -82,6 +82,22 @@ _progressbar_example_stop(void *data, } } +static char * +_progress_format_cb(double val) +{ + static char buf[30]; + int files = (1-val)*14000; + if (snprintf(buf, 30, "%i files left", files) > 0) + return strdup(buf); + return NULL; +} + +static void +_progress_format_free(char *str) +{ + free(fstr); +} + static void _on_done(void *data, Evas_Object *obj, @@ -136,12 +152,13 @@ elm_main(int argc, elm_icon_file_set(ic1, buf, NULL); evas_object_size_hint_aspect_set(ic1, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); - /* pb with label, icon, custom unit label and span size set */ + /* pb with label, icon, custom unit label function and span size set */ pb = elm_progressbar_add(win); elm_object_text_set(pb, "Label"); elm_object_part_content_set(pb, "icon", ic1); elm_progressbar_inverted_set(pb, EINA_TRUE); - elm_progressbar_unit_format_set(pb, "%1.1f units"); + elm_progressbar_unit_format_function_set(pb, _progress_format_cb, + _progress_format_free); elm_progressbar_span_size_set(pb, 200); evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5); evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); -- 2.7.4