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>
14 typedef struct Progressbar_Example
17 Evas_Object *pb2; /* pulsing */
20 Evas_Object *pb5; /* pulsing */
22 Evas_Object *pb7; /* pulsing */
26 } Progressbar_Example;
28 static Progressbar_Example example_data;
31 _progressbar_example_value_set(void *data)
35 progress = elm_progressbar_value_get(example_data.pb1);
36 if (progress < 1.0) progress += 0.0123;
39 /* just the non-pulsing ones need an update */
40 elm_progressbar_value_set(example_data.pb1, progress);
41 elm_progressbar_value_set(example_data.pb3, progress);
42 elm_progressbar_value_set(example_data.pb4, progress);
43 elm_progressbar_value_set(example_data.pb6, progress);
45 if (progress < 1.0) return ECORE_CALLBACK_RENEW;
48 return ECORE_CALLBACK_CANCEL;
52 _progressbar_example_start(void *data,
56 elm_progressbar_pulse(example_data.pb2, EINA_TRUE);
57 elm_progressbar_pulse(example_data.pb5, EINA_TRUE);
58 elm_progressbar_pulse(example_data.pb7, EINA_TRUE);
60 if (!example_data.run)
62 example_data.timer = ecore_timer_add(
63 0.1, _progressbar_example_value_set, NULL);
64 example_data.run = EINA_TRUE;
70 _progressbar_example_stop(void *data,
74 elm_progressbar_pulse(example_data.pb2, EINA_FALSE);
75 elm_progressbar_pulse(example_data.pb5, EINA_FALSE);
76 elm_progressbar_pulse(example_data.pb7, EINA_FALSE);
80 ecore_timer_del(example_data.timer);
81 example_data.run = EINA_FALSE;
90 _progressbar_example_stop(NULL, NULL, NULL);
98 Evas_Object *win, *bg, *pb, *bx, *hbx, *bt, *bt_bx, *ic1, *ic2;
101 elm_app_info_set(elm_main, "elementary", "images/logo_small.png");
102 win = elm_win_add(NULL, "progressbar", ELM_WIN_BASIC);
103 elm_win_title_set(win, "Progress bar example");
104 evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
106 bg = elm_bg_add(win);
107 elm_win_resize_object_add(win, bg);
108 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
109 evas_object_show(bg);
111 bx = elm_box_add(win);
112 elm_win_resize_object_add(win, bx);
113 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
114 evas_object_show(bx);
116 /* pb with no label, default unit label and no icon */
117 pb = elm_progressbar_add(win);
118 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
119 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
120 elm_box_pack_end(bx, pb);
121 evas_object_show(pb);
122 example_data.pb1 = pb;
124 /* pb with label, and set to pulse */
125 pb = elm_progressbar_add(win);
126 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
127 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
128 elm_object_text_set(pb, "Infinite bounce");
129 elm_progressbar_pulse_set(pb, EINA_TRUE);
130 elm_box_pack_end(bx, pb);
131 evas_object_show(pb);
132 example_data.pb2 = pb;
134 ic1 = elm_icon_add(win);
135 snprintf(buf, sizeof(buf), "%s/images/logo_small.png", elm_app_data_dir_get());
136 elm_icon_file_set(ic1, buf, NULL);
137 evas_object_size_hint_aspect_set(ic1, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
139 /* pb with label, icon, custom unit label and span size set */
140 pb = elm_progressbar_add(win);
141 elm_object_text_set(pb, "Label");
142 elm_object_part_content_set(pb, "icon", ic1);
143 elm_progressbar_inverted_set(pb, EINA_TRUE);
144 elm_progressbar_unit_format_set(pb, "%1.1f units");
145 elm_progressbar_span_size_set(pb, 200);
146 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
147 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
148 elm_box_pack_end(bx, pb);
149 evas_object_show(ic1);
150 evas_object_show(pb);
151 example_data.pb3 = pb;
153 hbx = elm_box_add(win);
154 elm_box_horizontal_set(hbx, EINA_TRUE);
155 evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
156 evas_object_size_hint_align_set(hbx, EVAS_HINT_FILL, EVAS_HINT_FILL);
157 elm_box_pack_end(bx, hbx);
158 evas_object_show(hbx);
161 pb = elm_progressbar_add(win);
162 elm_progressbar_horizontal_set(pb, EINA_FALSE);
163 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, EVAS_HINT_FILL);
164 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
165 elm_box_pack_end(hbx, pb);
166 elm_object_text_set(pb, "percent");
167 evas_object_show(pb);
168 example_data.pb4 = pb;
170 /* vertical pb, with pulse and custom (small) span size */
171 pb = elm_progressbar_add(win);
172 elm_progressbar_horizontal_set(pb, EINA_FALSE);
173 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
174 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
175 elm_progressbar_span_size_set(pb, 80);
176 elm_progressbar_pulse_set(pb, EINA_TRUE);
177 elm_progressbar_unit_format_set(pb, NULL);
178 elm_object_text_set(pb, "Infinite bounce");
179 elm_box_pack_end(hbx, pb);
180 evas_object_show(pb);
181 example_data.pb5 = pb;
183 ic2 = elm_icon_add(win);
184 elm_icon_file_set(ic2, buf, NULL);
185 evas_object_size_hint_aspect_set(ic2, EVAS_ASPECT_CONTROL_HORIZONTAL, 1, 1);
187 /* vertical pb, inverted, with custom unit format and icon*/
188 pb = elm_progressbar_add(win);
189 elm_progressbar_horizontal_set(pb, EINA_FALSE);
190 elm_object_text_set(pb, "Label");
191 elm_object_part_content_set(pb, "icon", ic2);
192 elm_progressbar_inverted_set(pb, EINA_TRUE);
193 elm_progressbar_unit_format_set(pb, "%1.2f%%");
194 elm_progressbar_span_size_set(pb, 200);
195 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
196 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
197 elm_box_pack_end(hbx, pb);
198 evas_object_show(ic2);
199 evas_object_show(pb);
200 example_data.pb6 = pb;
202 /* "wheel" style progress bar */
203 pb = elm_progressbar_add(win);
204 elm_object_style_set(pb, "wheel");
205 elm_object_text_set(pb, "Style: wheel");
206 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
207 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
208 elm_box_pack_end(bx, pb);
209 evas_object_show(pb);
210 example_data.pb7 = pb;
212 bt_bx = elm_box_add(win);
213 elm_box_horizontal_set(bt_bx, EINA_TRUE);
214 evas_object_size_hint_weight_set(bt_bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
215 elm_box_pack_end(bx, bt_bx);
216 evas_object_show(bt_bx);
218 bt = elm_button_add(win);
219 elm_object_text_set(bt, "Start");
220 evas_object_smart_callback_add(bt, "clicked", _progressbar_example_start,
222 elm_box_pack_end(bt_bx, bt);
223 evas_object_show(bt);
225 bt = elm_button_add(win);
226 elm_object_text_set(bt, "Stop");
227 evas_object_smart_callback_add(bt, "clicked", _progressbar_example_stop,
229 elm_box_pack_end(bt_bx, bt);
230 evas_object_show(bt);
232 evas_object_show(win);