2 * Simple Elementary's <b>progress bar widget</b> example, illustrating its
5 * See stdout/stderr for output. Compile with:
8 * gcc -g `pkg-config --cflags --libs elementary` progressbar_example.c -o progressbar_example
12 #include <Elementary.h>
14 # include "elementary_config.h"
19 typedef struct Progressbar_Example
22 Evas_Object *pb2; /* pulsing */
25 Evas_Object *pb5; /* pulsing */
27 Evas_Object *pb7; /* pulsing */
31 } Progressbar_Example;
33 static Progressbar_Example example_data;
36 _progressbar_example_value_set(void *data __UNUSED__)
40 progress = elm_progressbar_value_get(example_data.pb1);
41 if (progress < 1.0) progress += 0.0123;
44 /* just the non-pulsing ones need an update */
45 elm_progressbar_value_set(example_data.pb1, progress);
46 elm_progressbar_value_set(example_data.pb3, progress);
47 elm_progressbar_value_set(example_data.pb4, progress);
48 elm_progressbar_value_set(example_data.pb6, progress);
50 if (progress < 1.0) return ECORE_CALLBACK_RENEW;
53 return ECORE_CALLBACK_CANCEL;
57 _progressbar_example_start(void *data __UNUSED__,
58 Evas_Object *obj __UNUSED__,
59 void *event_info __UNUSED__)
61 elm_progressbar_pulse(example_data.pb2, EINA_TRUE);
62 elm_progressbar_pulse(example_data.pb5, EINA_TRUE);
63 elm_progressbar_pulse(example_data.pb7, EINA_TRUE);
65 if (!example_data.run)
67 example_data.timer = ecore_timer_add(
68 0.1, _progressbar_example_value_set, NULL);
69 example_data.run = EINA_TRUE;
75 _progressbar_example_stop(void *data __UNUSED__,
76 Evas_Object *obj __UNUSED__,
77 void *event_info __UNUSED__)
79 elm_progressbar_pulse(example_data.pb2, EINA_FALSE);
80 elm_progressbar_pulse(example_data.pb5, EINA_FALSE);
81 elm_progressbar_pulse(example_data.pb7, EINA_FALSE);
85 ecore_timer_del(example_data.timer);
86 example_data.run = EINA_FALSE;
91 _on_done(void *data __UNUSED__,
92 Evas_Object *obj __UNUSED__,
93 void *event_info __UNUSED__)
95 _progressbar_example_stop(NULL, NULL, NULL);
100 elm_main(int argc __UNUSED__,
101 char **argv __UNUSED__)
103 Evas_Object *win, *bg, *pb, *bx, *hbx, *bt, *bt_bx, *ic1, *ic2;
106 win = elm_win_add(NULL, "progressbar", ELM_WIN_BASIC);
107 elm_win_title_set(win, "Progress bar example");
108 evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
110 bg = elm_bg_add(win);
111 elm_win_resize_object_add(win, bg);
112 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
113 evas_object_show(bg);
115 bx = elm_box_add(win);
116 elm_win_resize_object_add(win, bx);
117 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
118 evas_object_show(bx);
120 /* pb with no label, default unit label and no icon */
121 pb = elm_progressbar_add(win);
122 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
123 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
124 elm_box_pack_end(bx, pb);
125 evas_object_show(pb);
126 example_data.pb1 = pb;
128 /* pb with label, and set to pulse */
129 pb = elm_progressbar_add(win);
130 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
131 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
132 elm_object_text_set(pb, "Infinite bounce");
133 elm_progressbar_pulse_set(pb, EINA_TRUE);
134 elm_box_pack_end(bx, pb);
135 evas_object_show(pb);
136 example_data.pb2 = pb;
138 ic1 = elm_icon_add(win);
139 snprintf(buf, sizeof(buf), "%s/images/logo_small.png", PACKAGE_DATA_DIR);
140 elm_icon_file_set(ic1, buf, NULL);
141 evas_object_size_hint_aspect_set(ic1, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
143 /* pb with label, icon, custom unit label and span size set */
144 pb = elm_progressbar_add(win);
145 elm_object_text_set(pb, "Label");
146 elm_object_part_content_set(pb, "icon", ic1);
147 elm_progressbar_inverted_set(pb, EINA_TRUE);
148 elm_progressbar_unit_format_set(pb, "%1.1f units");
149 elm_progressbar_span_size_set(pb, 200);
150 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
151 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
152 elm_box_pack_end(bx, pb);
153 evas_object_show(ic1);
154 evas_object_show(pb);
155 example_data.pb3 = pb;
157 hbx = elm_box_add(win);
158 elm_box_horizontal_set(hbx, EINA_TRUE);
159 evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
160 evas_object_size_hint_align_set(hbx, EVAS_HINT_FILL, EVAS_HINT_FILL);
161 elm_box_pack_end(bx, hbx);
162 evas_object_show(hbx);
165 pb = elm_progressbar_add(win);
166 elm_progressbar_horizontal_set(pb, EINA_FALSE);
167 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, EVAS_HINT_FILL);
168 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
169 elm_box_pack_end(hbx, pb);
170 elm_object_text_set(pb, "percent");
171 evas_object_show(pb);
172 example_data.pb4 = pb;
174 /* vertical pb, with pulse and custom (small) span size */
175 pb = elm_progressbar_add(win);
176 elm_progressbar_horizontal_set(pb, EINA_FALSE);
177 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
178 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
179 elm_progressbar_span_size_set(pb, 80);
180 elm_progressbar_pulse_set(pb, EINA_TRUE);
181 elm_progressbar_unit_format_set(pb, NULL);
182 elm_object_text_set(pb, "Infinite bounce");
183 elm_box_pack_end(hbx, pb);
184 evas_object_show(pb);
185 example_data.pb5 = pb;
187 ic2 = elm_icon_add(win);
188 elm_icon_file_set(ic2, buf, NULL);
189 evas_object_size_hint_aspect_set(ic2, EVAS_ASPECT_CONTROL_HORIZONTAL, 1, 1);
191 /* vertical pb, inverted, with custom unit format and icon*/
192 pb = elm_progressbar_add(win);
193 elm_progressbar_horizontal_set(pb, EINA_FALSE);
194 elm_object_text_set(pb, "Label");
195 elm_object_part_content_set(pb, "icon", ic2);
196 elm_progressbar_inverted_set(pb, EINA_TRUE);
197 elm_progressbar_unit_format_set(pb, "%1.2f%%");
198 elm_progressbar_span_size_set(pb, 200);
199 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
200 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
201 elm_box_pack_end(hbx, pb);
202 evas_object_show(ic2);
203 evas_object_show(pb);
204 example_data.pb6 = pb;
206 /* "wheel" style progress bar */
207 pb = elm_progressbar_add(win);
208 elm_object_style_set(pb, "wheel");
209 elm_object_text_set(pb, "Style: wheel");
210 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
211 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
212 elm_box_pack_end(bx, pb);
213 evas_object_show(pb);
214 example_data.pb7 = pb;
216 bt_bx = elm_box_add(win);
217 elm_box_horizontal_set(bt_bx, EINA_TRUE);
218 evas_object_size_hint_weight_set(bt_bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
219 elm_box_pack_end(bx, bt_bx);
220 evas_object_show(bt_bx);
222 bt = elm_button_add(win);
223 elm_object_text_set(bt, "Start");
224 evas_object_smart_callback_add(bt, "clicked", _progressbar_example_start,
226 elm_box_pack_end(bt_bx, bt);
227 evas_object_show(bt);
229 bt = elm_button_add(win);
230 elm_object_text_set(bt, "Stop");
231 evas_object_smart_callback_add(bt, "clicked", _progressbar_example_stop,
233 elm_box_pack_end(bt_bx, bt);
234 evas_object_show(bt);
236 evas_object_show(win);