progressbar_example.c
#include <Elementary.h>
#include <time.h>
typedef struct Progressbar_Example
{
Evas_Object *pb2; /* pulsing */
Evas_Object *pb6; /* pulsing */
Evas_Object *pb8; /* pulsing */
Eina_Bool run;
Ecore_Timer *timer;
} Progressbar_Example;
static Progressbar_Example example_data;
static Eina_Bool
_progressbar_example_value_set(void *data EINA_UNUSED)
{
double progress;
progress = elm_progressbar_value_get(example_data.pb1);
if (progress < 1.0) progress += 0.0123;
else progress = 0.0;
/* just the non-pulsing ones need an update */
elm_progressbar_value_set(example_data.pb1, progress);
elm_progressbar_value_set(example_data.pb3, progress);
elm_progressbar_value_set(example_data.pb4, progress);
elm_progressbar_value_set(example_data.pb5, progress);
elm_progressbar_value_set(example_data.pb7, progress);
if (progress < 1.0) return ECORE_CALLBACK_RENEW;
example_data.run = 0;
}
static void
_progressbar_example_start(void *data EINA_UNUSED,
void *event_info EINA_UNUSED)
{
elm_progressbar_pulse(example_data.pb2, EINA_TRUE);
elm_progressbar_pulse(example_data.pb6, EINA_TRUE);
elm_progressbar_pulse(example_data.pb8, EINA_TRUE);
if (!example_data.run)
{
example_data.timer = ecore_timer_add(
0.1, _progressbar_example_value_set, NULL);
example_data.run = EINA_TRUE;
}
}
/* end of show */
static void
_progressbar_example_stop(void *data EINA_UNUSED,
void *event_info EINA_UNUSED)
{
elm_progressbar_pulse(example_data.pb2, EINA_FALSE);
elm_progressbar_pulse(example_data.pb6, EINA_FALSE);
elm_progressbar_pulse(example_data.pb8, EINA_FALSE);
if (example_data.run)
{
ecore_timer_del(example_data.timer);
example_data.run = EINA_FALSE;
}
}
/* Format callback */
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(str);
}
/* Callback for "changed" signal */
static void
_on_changed(void *data,
void *event_info EINA_UNUSED)
{
static char buf[30];
static time_t tstart = 0;
static double eta = 0;
time_t tdiff;
double val;
Evas_Object *label = (Evas_Object *)data;
if (EINA_DBL_EQ(val, 0))
{
tstart = 0;
elm_object_text_set(label, "ETA: N/A");
return;
}
/* First invocation */
if (tstart == 0)
{
tstart = time(NULL);
}
/* Calculate ETA and update */
tdiff = time(NULL) - tstart;
eta = 0.3*eta + 0.7*(tdiff/val)*(1-val);
snprintf(buf, 30, "ETA: %.0fs", eta);
elm_object_text_set(label, buf);
}
static void
_on_done(void *data EINA_UNUSED,
void *event_info EINA_UNUSED)
{
_progressbar_example_stop(NULL, NULL, NULL);
}
EAPI_MAIN int
elm_main(int argc EINA_UNUSED,
char **argv EINA_UNUSED)
{
Evas_Object *win, *pb, *bx, *hbx, *bt, *bt_bx, *ic1, *ic2, *label;
char buf[PATH_MAX];
elm_app_info_set(elm_main, "elementary", "images/logo_small.png");
win = elm_win_util_standard_add("progressbar", "Progress bar example");
evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
bx = elm_box_add(win);
/* pb with no label, default unit label and no icon */
example_data.pb1 = pb;
/* pb with label, and set to pulse */
elm_object_text_set(pb, "Infinite bounce");
example_data.pb2 = pb;
ic1 = elm_icon_add(win);
snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
elm_image_file_set(ic1, buf, NULL);
/* pb with label, icon, custom unit label function and span size set */
elm_object_text_set(pb, "Label");
elm_object_part_content_set(pb, "icon", ic1);
_progress_format_free);
example_data.pb3 = pb;
/* pb with label and changed trigger */
elm_object_text_set(pb, "Label");
label = elm_label_add(win);
elm_object_text_set(label, "ETA: N/A");
elm_box_pack_end(bx, label);
evas_object_smart_callback_add(pb, "changed", _on_changed, label);
example_data.pb4 = pb;
hbx = elm_box_add(win);
elm_box_pack_end(bx, hbx);
/* vertical pb */
elm_box_pack_end(hbx, pb);
elm_object_text_set(pb, "percent");
example_data.pb5 = pb;
/* vertical pb, with pulse and custom (small) span size */
elm_object_text_set(pb, "Infinite bounce");
elm_box_pack_end(hbx, pb);
example_data.pb6 = pb;
ic2 = elm_icon_add(win);
elm_image_file_set(ic2, buf, NULL);
/* vertical pb, inverted, with custom unit format and icon*/
elm_object_text_set(pb, "Label");
elm_object_part_content_set(pb, "icon", ic2);
elm_box_pack_end(hbx, pb);
example_data.pb7 = pb;
/* "wheel" style progress bar */
elm_object_style_set(pb, "wheel");
elm_object_text_set(pb, "Style: wheel");
example_data.pb8 = pb;
bt_bx = elm_box_add(win);
elm_box_pack_end(bx, bt_bx);
bt = elm_button_add(win);
elm_object_text_set(bt, "Start");
evas_object_smart_callback_add(bt, "clicked", _progressbar_example_start,
NULL);
elm_box_pack_end(bt_bx, bt);
bt = elm_button_add(win);
elm_object_text_set(bt, "Stop");
evas_object_smart_callback_add(bt, "clicked", _progressbar_example_stop,
NULL);
elm_box_pack_end(bt_bx, bt);
return 0;
}
#define EVAS_HINT_EXPAND
Use with evas_object_size_hint_weight_set(), evas_object_size_hint_weight_get(), evas_object_size_hin...
Definition: Evas_Common.h:297
@ EVAS_ASPECT_CONTROL_HORIZONTAL
Use all horizontal container space to place an object, using the given aspect.
Definition: Evas_Common.h:376
@ EVAS_ASPECT_CONTROL_VERTICAL
Use all vertical container space to place an object, using the given aspect.
Definition: Evas_Common.h:377
#define EVAS_HINT_FILL
Use with evas_object_size_hint_align_set(), evas_object_size_hint_align_get(), evas_object_size_hint_...
Definition: Evas_Common.h:298
#define ECORE_CALLBACK_RENEW
Return value to keep a callback.
Definition: Ecore_Common.h:153
#define ECORE_CALLBACK_CANCEL
Return value to remove a callback.
Definition: Ecore_Common.h:152
void * ecore_timer_del(Ecore_Timer *timer)
Deletes the specified timer from the timer list.
Definition: ecore_timer.c:238
Ecore_Timer * ecore_timer_add(double in, Ecore_Task_Cb func, const void *data)
Creates a timer to call the given function in the given period of time.
Definition: ecore_timer.c:189
Eo Ecore_Timer
A handle for timers.
Definition: Ecore_Common.h:3079
#define EINA_DBL_EQ(a, b)
Safe comparison of double.
Definition: eina_util.h:100
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:539
#define EINA_FALSE
boolean value FALSE (numerical value 0)
Definition: eina_types.h:533
unsigned char Eina_Bool
Type to mimic a boolean.
Definition: eina_types.h:527
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339
void elm_app_info_set(void *mainfunc, const char *dom, const char *checkfile)
Re-locate the application somewhere else after compilation, if the developer wishes for easier distri...
Definition: elm_main.c:496
const char * elm_app_data_dir_get(void)
Get the application's run time data prefix directory, as set by elm_app_info_set() and the way (envir...
Definition: elm_main.c:586
void elm_box_horizontal_set(Elm_Box *obj, Eina_Bool horizontal)
Set the horizontal orientation.
Definition: elm_box_eo.legacy.c:27
Evas_Object * elm_box_add(Evas_Object *parent)
Add a new box to the parent.
Definition: elm_box.c:363
void elm_box_pack_end(Elm_Box *obj, Efl_Canvas_Object *subobj)
Add an object at the end of the pack list.
Definition: elm_box_eo.legacy.c:57
Evas_Object * elm_button_add(Evas_Object *parent)
Add a new button to the parent's canvas.
Definition: efl_ui_button.c:459
void elm_object_part_content_set(Evas_Object *obj, const char *part, Evas_Object *content)
Set the content on part of a given container widget.
Definition: elm_main.c:1562
#define ELM_MAIN()
macro to be used after the elm_main() function
Definition: elm_general.h:556
void elm_exit(void)
Ask to exit Elementary's main loop.
Definition: elm_main.c:1373
void elm_run(void)
Run Elementary's main loop.
Definition: elm_main.c:1357
Evas_Object * elm_icon_add(Evas_Object *parent)
Add a new icon object to the parent.
Definition: elm_icon.c:613
Eina_Bool elm_image_file_set(Evas_Object *obj, const char *file, const char *group)
Set the file that will be used as the image's source.
Definition: efl_ui_image.c:2435
Evas_Object * elm_label_add(Evas_Object *parent)
Add a new label to the parent.
Definition: elm_label.c:421
void elm_progressbar_value_set(Evas_Object *obj, double val)
Control the progress value (in percentage) on a given progress bar widget.
Definition: efl_ui_progressbar.c:1040
void elm_progressbar_span_size_set(Evas_Object *obj, Evas_Coord size)
Control the (exact) length of the bar region of a given progress bar widget.
Definition: efl_ui_progressbar.c:1009
void elm_progressbar_pulse(Evas_Object *obj, Eina_Bool state)
Start/stop a given progress bar "pulsing" animation, if its under that mode.
Definition: efl_ui_progressbar.c:838
void elm_progressbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
Control the orientation of a given progress bar widget.
Definition: efl_ui_progressbar.c:899
void elm_progressbar_inverted_set(Evas_Object *obj, Eina_Bool inverted)
Invert a given progress bar widget's displaying values order.
Definition: efl_ui_progressbar.c:879
void elm_progressbar_unit_format_function_set(Evas_Object *obj, progressbar_func_type func, progressbar_freefunc_type free_func)
Set the format function pointer for the units label.
Definition: efl_ui_progressbar.c:944
double elm_progressbar_value_get(const Evas_Object *obj)
Get the progress value (in percentage) on a given progress bar widget.
Definition: efl_ui_progressbar.c:1046
Evas_Object * elm_progressbar_add(Evas_Object *parent)
Add a new progress bar widget to the given parent Elementary (container) object.
Definition: efl_ui_progressbar.c:809
void elm_progressbar_unit_format_set(Evas_Object *obj, const char *units)
Control the format string for a given progress bar widget's units label.
Definition: efl_ui_progressbar.c:1023
void elm_progressbar_pulse_set(Evas_Object *obj, Eina_Bool pulse)
Control whether a given progress bar widget is at "pulsing mode" or not.
Definition: efl_ui_progressbar.c:819
Eina_Bool elm_object_style_set(Evas_Object *obj, const char *style)
Set the style to used by a given widget.
Definition: elm_main.c:1583
Evas_Object * elm_win_util_standard_add(const char *name, const char *title)
Adds a window object with standard setup.
Definition: efl_ui_win.c:9582
void elm_win_resize_object_add(Eo *obj, Evas_Object *subobj)
Add subobj as a resize object of window obj.
Definition: efl_ui_win.c:8997
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
EVAS_API void evas_object_size_hint_weight_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's weight.
Definition: evas_object_main.c:2638
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition: Evas_Common.h:185
EVAS_API void evas_object_size_hint_align_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's alignment.
Definition: evas_object_main.c:2650
EVAS_API void evas_object_size_hint_aspect_set(Evas_Object *obj, Evas_Aspect_Control aspect, Evas_Coord w, Evas_Coord h)
Sets the hints for an object's aspect ratio.
Definition: evas_object_main.c:2581
EVAS_API void evas_object_smart_callback_add(Evas_Object *eo_obj, const char *event, Evas_Smart_Cb func, const void *data)
Add (register) a callback function to the smart event specified by event on the smart object obj.
Definition: evas_object_smart.c:1040