2 * Simple Elementary's <b>progress bar widget</b> example, illustrating its
5 * See stdout/stderr for output. Compile with:
8 * gcc -g progressbar_example.c -o progressbar_example `pkg-config --cflags --libs elementary`
12 #include <Elementary.h>
16 typedef struct Progressbar_Example
19 Evas_Object *pb2; /* pulsing */
23 Evas_Object *pb6; /* pulsing */
25 Evas_Object *pb8; /* pulsing */
29 } Progressbar_Example;
31 static Progressbar_Example example_data;
34 _progressbar_example_value_set(void *data)
38 progress = elm_progressbar_value_get(example_data.pb1);
39 if (progress < 1.0) progress += 0.0123;
42 /* just the non-pulsing ones need an update */
43 elm_progressbar_value_set(example_data.pb1, progress);
44 elm_progressbar_value_set(example_data.pb3, progress);
45 elm_progressbar_value_set(example_data.pb4, progress);
46 elm_progressbar_value_set(example_data.pb5, progress);
47 elm_progressbar_value_set(example_data.pb7, progress);
49 if (progress < 1.0) return ECORE_CALLBACK_RENEW;
52 return ECORE_CALLBACK_CANCEL;
56 _progressbar_example_start(void *data,
60 elm_progressbar_pulse(example_data.pb2, EINA_TRUE);
61 elm_progressbar_pulse(example_data.pb6, EINA_TRUE);
62 elm_progressbar_pulse(example_data.pb8, EINA_TRUE);
64 if (!example_data.run)
66 example_data.timer = ecore_timer_add(
67 0.1, _progressbar_example_value_set, NULL);
68 example_data.run = EINA_TRUE;
74 _progressbar_example_stop(void *data,
78 elm_progressbar_pulse(example_data.pb2, EINA_FALSE);
79 elm_progressbar_pulse(example_data.pb6, EINA_FALSE);
80 elm_progressbar_pulse(example_data.pb8, EINA_FALSE);
84 ecore_timer_del(example_data.timer);
85 example_data.run = EINA_FALSE;
91 _progress_format_cb(double val)
94 int files = (1-val)*14000;
95 if (snprintf(buf, 30, "%i files left", files) > 0)
101 _progress_format_free(char *str)
106 /* Callback for "changed" signal */
108 _on_changed(void *data,
113 static time_t tstart = 0;
114 static double eta = 0;
117 Evas_Object *label = (Evas_Object *)data;
119 val = elm_progressbar_value_get(obj);
123 elm_object_text_set(label, "ETA: N/A");
127 /* First invocation */
133 /* Calculate ETA and update */
134 tdiff = time(NULL) - tstart;
135 eta = 0.3*eta + 0.7*(tdiff/val)*(1-val);
136 snprintf(buf, 30, "ETA: %.0fs", eta);
137 elm_object_text_set(label, buf);
145 _progressbar_example_stop(NULL, NULL, NULL);
153 Evas_Object *win, *bg, *pb, *bx, *hbx, *bt, *bt_bx, *ic1, *ic2, *label;
156 elm_app_info_set(elm_main, "elementary", "images/logo_small.png");
157 win = elm_win_add(NULL, "progressbar", ELM_WIN_BASIC);
158 elm_win_title_set(win, "Progress bar example");
159 evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
161 bg = elm_bg_add(win);
162 elm_win_resize_object_add(win, bg);
163 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
164 evas_object_show(bg);
166 bx = elm_box_add(win);
167 elm_win_resize_object_add(win, bx);
168 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
169 evas_object_show(bx);
171 /* pb with no label, default unit label and no icon */
172 pb = elm_progressbar_add(win);
173 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
174 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
175 elm_box_pack_end(bx, pb);
176 evas_object_show(pb);
177 example_data.pb1 = pb;
179 /* pb with label, and set to pulse */
180 pb = elm_progressbar_add(win);
181 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
182 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
183 elm_object_text_set(pb, "Infinite bounce");
184 elm_progressbar_pulse_set(pb, EINA_TRUE);
185 elm_box_pack_end(bx, pb);
186 evas_object_show(pb);
187 example_data.pb2 = pb;
189 ic1 = elm_icon_add(win);
190 snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
191 elm_image_file_set(ic1, buf, NULL);
192 evas_object_size_hint_aspect_set(ic1, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
194 /* pb with label, icon, custom unit label function and span size set */
195 pb = elm_progressbar_add(win);
196 elm_object_text_set(pb, "Label");
197 elm_object_part_content_set(pb, "icon", ic1);
198 elm_progressbar_inverted_set(pb, EINA_TRUE);
199 elm_progressbar_unit_format_function_set(pb, _progress_format_cb,
200 _progress_format_free);
201 elm_progressbar_span_size_set(pb, 200);
202 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
203 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
204 elm_box_pack_end(bx, pb);
205 evas_object_show(ic1);
206 evas_object_show(pb);
207 example_data.pb3 = pb;
209 /* pb with label and changed trigger */
210 pb = elm_progressbar_add(win);
211 elm_object_text_set(pb, "Label");
212 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
213 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
214 elm_box_pack_end(bx, pb);
215 evas_object_show(pb);
217 label = elm_label_add(win);
218 elm_object_text_set(label, "ETA: N/A");
219 evas_object_size_hint_align_set(label, 0.5, 0.5);
220 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
221 elm_box_pack_end(bx, label);
222 evas_object_show(label);
224 evas_object_smart_callback_add(pb, "changed", _on_changed, label);
225 example_data.pb4 = pb;
227 hbx = elm_box_add(win);
228 elm_box_horizontal_set(hbx, EINA_TRUE);
229 evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
230 evas_object_size_hint_align_set(hbx, EVAS_HINT_FILL, EVAS_HINT_FILL);
231 elm_box_pack_end(bx, hbx);
232 evas_object_show(hbx);
235 pb = elm_progressbar_add(win);
236 elm_progressbar_horizontal_set(pb, EINA_FALSE);
237 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, EVAS_HINT_FILL);
238 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
239 elm_box_pack_end(hbx, pb);
240 elm_object_text_set(pb, "percent");
241 evas_object_show(pb);
242 example_data.pb5 = pb;
244 /* vertical pb, with pulse and custom (small) span size */
245 pb = elm_progressbar_add(win);
246 elm_progressbar_horizontal_set(pb, EINA_FALSE);
247 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
248 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
249 elm_progressbar_span_size_set(pb, 80);
250 elm_progressbar_pulse_set(pb, EINA_TRUE);
251 elm_progressbar_unit_format_set(pb, NULL);
252 elm_object_text_set(pb, "Infinite bounce");
253 elm_box_pack_end(hbx, pb);
254 evas_object_show(pb);
255 example_data.pb6 = pb;
257 ic2 = elm_icon_add(win);
258 elm_image_file_set(ic2, buf, NULL);
259 evas_object_size_hint_aspect_set(ic2, EVAS_ASPECT_CONTROL_HORIZONTAL, 1, 1);
261 /* vertical pb, inverted, with custom unit format and icon*/
262 pb = elm_progressbar_add(win);
263 elm_progressbar_horizontal_set(pb, EINA_FALSE);
264 elm_object_text_set(pb, "Label");
265 elm_object_part_content_set(pb, "icon", ic2);
266 elm_progressbar_inverted_set(pb, EINA_TRUE);
267 elm_progressbar_unit_format_set(pb, "%1.2f%%");
268 elm_progressbar_span_size_set(pb, 200);
269 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
270 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
271 elm_box_pack_end(hbx, pb);
272 evas_object_show(ic2);
273 evas_object_show(pb);
274 example_data.pb7 = pb;
276 /* "wheel" style progress bar */
277 pb = elm_progressbar_add(win);
278 elm_object_style_set(pb, "wheel");
279 elm_object_text_set(pb, "Style: wheel");
280 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
281 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
282 elm_box_pack_end(bx, pb);
283 evas_object_show(pb);
284 example_data.pb8 = pb;
286 bt_bx = elm_box_add(win);
287 elm_box_horizontal_set(bt_bx, EINA_TRUE);
288 evas_object_size_hint_weight_set(bt_bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
289 elm_box_pack_end(bx, bt_bx);
290 evas_object_show(bt_bx);
292 bt = elm_button_add(win);
293 elm_object_text_set(bt, "Start");
294 evas_object_smart_callback_add(bt, "clicked", _progressbar_example_start,
296 elm_box_pack_end(bt_bx, bt);
297 evas_object_show(bt);
299 bt = elm_button_add(win);
300 elm_object_text_set(bt, "Stop");
301 evas_object_smart_callback_add(bt, "clicked", _progressbar_example_stop,
303 elm_box_pack_end(bt_bx, bt);
304 evas_object_show(bt);
306 evas_object_show(win);