|
这个代码片段展示了如何添加自定义单元格式基本progressbar小部件。
- //units label format callback
- static char *_progress_format_cb(double val) {
- static char buffer[15];
- int items = val * 100;
- if (snprintf(buffer, 15, "%i items sent", items) > 0) {
- return strdup(buffer);
- }
- return NULL;
- }
- //free unit format string
- static void _progress_format_free(char *str) {
- free(str);
- }
- // update progressbar, 1% for each call (for demo purposes)
- static Eina_Bool progressbar_value_set(void *data) {
- Evas_Object *progressbar = data;
- double progress = elm_progressbar_value_get(progressbar);
- if (progress < 1.0) {
- progress += 0.01;
- elm_progressbar_value_set(progressbar, progress);
- return ECORE_CALLBACK_RENEW;
- }
- return ECORE_CALLBACK_CANCEL;
- }
- static void progressbar_test(Evas_Object *parent) {
- // create a progressbar
- Evas_Object *progressbar = elm_progressbar_add(parent);
- elm_win_resize_object_add(parent, progressbar);
- //progressbar setup
- elm_progressbar_horizontal_set(progressbar, EINA_FALSE);
- elm_object_style_set(progressbar, "progressbar");
- //set units label function
- elm_progressbar_unit_format_function_set(progressbar, _progress_format_cb, _progress_format_free);
- evas_object_show(progressbar);
- // add a timer to change progressbar values (demo)
- ecore_timer_add(0.1, progressbar_value_set, progressbar);
- }
复制代码 |
|