elementary: add an example for progressbar signal 'changed'. From Daniel Willmann, thx !

SVN revision: 72987
This commit is contained in:
Michael BOUCHAUD 2012-06-28 09:13:05 +00:00
parent 1ce5d19b0d
commit b2c73beb86
1 changed files with 68 additions and 13 deletions

View File

@ -11,15 +11,18 @@
#include <Elementary.h>
#include <time.h>
typedef struct Progressbar_Example
{
Evas_Object *pb1;
Evas_Object *pb2; /* pulsing */
Evas_Object *pb3;
Evas_Object *pb4;
Evas_Object *pb5; /* pulsing */
Evas_Object *pb6;
Evas_Object *pb7; /* pulsing */
Evas_Object *pb5;
Evas_Object *pb6; /* pulsing */
Evas_Object *pb7;
Evas_Object *pb8; /* pulsing */
Eina_Bool run;
Ecore_Timer *timer;
@ -40,7 +43,8 @@ _progressbar_example_value_set(void *data)
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.pb6, 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;
@ -54,8 +58,8 @@ _progressbar_example_start(void *data,
void *event_info)
{
elm_progressbar_pulse(example_data.pb2, EINA_TRUE);
elm_progressbar_pulse(example_data.pb5, EINA_TRUE);
elm_progressbar_pulse(example_data.pb7, EINA_TRUE);
elm_progressbar_pulse(example_data.pb6, EINA_TRUE);
elm_progressbar_pulse(example_data.pb8, EINA_TRUE);
if (!example_data.run)
{
@ -72,8 +76,8 @@ _progressbar_example_stop(void *data,
void *event_info)
{
elm_progressbar_pulse(example_data.pb2, EINA_FALSE);
elm_progressbar_pulse(example_data.pb5, EINA_FALSE);
elm_progressbar_pulse(example_data.pb7, EINA_FALSE);
elm_progressbar_pulse(example_data.pb6, EINA_FALSE);
elm_progressbar_pulse(example_data.pb8, EINA_FALSE);
if (example_data.run)
{
@ -98,6 +102,39 @@ _progress_format_free(char *str)
free(str);
}
static void
_on_changed(void *data,
Evas_Object *obj,
void *event_info)
{
static char buf[30];
static time_t tstart = 0;
static double eta = 0;
time_t tdiff;
double val;
Evas_Object *label = (Evas_Object *)data;
val = elm_progressbar_value_get(obj);
if (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,
Evas_Object *obj,
@ -111,7 +148,7 @@ EAPI_MAIN int
elm_main(int argc,
char **argv)
{
Evas_Object *win, *bg, *pb, *bx, *hbx, *bt, *bt_bx, *ic1, *ic2;
Evas_Object *win, *bg, *pb, *bx, *hbx, *bt, *bt_bx, *ic1, *ic2, *label;
char buf[PATH_MAX];
elm_app_info_set(elm_main, "elementary", "images/logo_small.png");
@ -167,6 +204,24 @@ elm_main(int argc,
evas_object_show(pb);
example_data.pb3 = pb;
/* pb with label and changed trigger */
pb = elm_progressbar_add(win);
elm_object_text_set(pb, "Label");
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);
elm_box_pack_end(bx, pb);
evas_object_show(pb);
label = elm_label_add(win);
elm_object_text_set(label, "ETA: N/A");
evas_object_size_hint_align_set(label, 0.5, 0.5);
evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_box_pack_end(bx, label);
evas_object_show(label);
evas_object_smart_callback_add(pb, "changed", _on_changed, label);
example_data.pb4 = pb;
hbx = elm_box_add(win);
elm_box_horizontal_set(hbx, EINA_TRUE);
evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
@ -182,7 +237,7 @@ elm_main(int argc,
elm_box_pack_end(hbx, pb);
elm_object_text_set(pb, "percent");
evas_object_show(pb);
example_data.pb4 = pb;
example_data.pb5 = pb;
/* vertical pb, with pulse and custom (small) span size */
pb = elm_progressbar_add(win);
@ -195,7 +250,7 @@ elm_main(int argc,
elm_object_text_set(pb, "Infinite bounce");
elm_box_pack_end(hbx, pb);
evas_object_show(pb);
example_data.pb5 = pb;
example_data.pb6 = pb;
ic2 = elm_icon_add(win);
elm_image_file_set(ic2, buf, NULL);
@ -214,7 +269,7 @@ elm_main(int argc,
elm_box_pack_end(hbx, pb);
evas_object_show(ic2);
evas_object_show(pb);
example_data.pb6 = pb;
example_data.pb7 = pb;
/* "wheel" style progress bar */
pb = elm_progressbar_add(win);
@ -224,7 +279,7 @@ elm_main(int argc,
evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_box_pack_end(bx, pb);
evas_object_show(pb);
example_data.pb7 = pb;
example_data.pb8 = pb;
bt_bx = elm_box_add(win);
elm_box_horizontal_set(bt_bx, EINA_TRUE);