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 -DDATA_DIR="\"<directory>\'""
12 #include <Elementary.h>
14 # define DATA_DIR "/usr/share/elementary"
17 typedef struct Progressbar_Example
20 Evas_Object *pb2; /* pulsing */
23 Evas_Object *pb5; /* pulsing */
25 Evas_Object *pb7; /* 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.pb6, progress);
48 if (progress < 1.0) return ECORE_CALLBACK_RENEW;
51 return ECORE_CALLBACK_CANCEL;
55 _progressbar_example_start(void *data,
59 elm_progressbar_pulse(example_data.pb2, EINA_TRUE);
60 elm_progressbar_pulse(example_data.pb5, EINA_TRUE);
61 elm_progressbar_pulse(example_data.pb7, EINA_TRUE);
63 if (!example_data.run)
65 example_data.timer = ecore_timer_add(
66 0.1, _progressbar_example_value_set, NULL);
67 example_data.run = EINA_TRUE;
73 _progressbar_example_stop(void *data,
77 elm_progressbar_pulse(example_data.pb2, EINA_FALSE);
78 elm_progressbar_pulse(example_data.pb5, EINA_FALSE);
79 elm_progressbar_pulse(example_data.pb7, EINA_FALSE);
83 ecore_timer_del(example_data.timer);
84 example_data.run = EINA_FALSE;
93 _progressbar_example_stop(NULL, NULL, NULL);
101 Evas_Object *win, *bg, *pb, *bx, *hbx, *bt, *bt_bx, *ic1, *ic2;
104 win = elm_win_add(NULL, "progressbar", ELM_WIN_BASIC);
105 elm_win_title_set(win, "Progress bar example");
106 evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
108 bg = elm_bg_add(win);
109 elm_win_resize_object_add(win, bg);
110 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
111 evas_object_show(bg);
113 bx = elm_box_add(win);
114 elm_win_resize_object_add(win, bx);
115 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
116 evas_object_show(bx);
118 /* pb with no label, default unit label and no icon */
119 pb = elm_progressbar_add(win);
120 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
121 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
122 elm_box_pack_end(bx, pb);
123 evas_object_show(pb);
124 example_data.pb1 = pb;
126 /* pb with label, and set to pulse */
127 pb = elm_progressbar_add(win);
128 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
129 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
130 elm_object_text_set(pb, "Infinite bounce");
131 elm_progressbar_pulse_set(pb, EINA_TRUE);
132 elm_box_pack_end(bx, pb);
133 evas_object_show(pb);
134 example_data.pb2 = pb;
136 ic1 = elm_icon_add(win);
137 snprintf(buf, sizeof(buf), "%s/images/logo_small.png", DATA_DIR);
138 elm_icon_file_set(ic1, buf, NULL);
139 evas_object_size_hint_aspect_set(ic1, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
141 /* pb with label, icon, custom unit label and span size set */
142 pb = elm_progressbar_add(win);
143 elm_object_text_set(pb, "Label");
144 elm_object_part_content_set(pb, "icon", ic1);
145 elm_progressbar_inverted_set(pb, EINA_TRUE);
146 elm_progressbar_unit_format_set(pb, "%1.1f units");
147 elm_progressbar_span_size_set(pb, 200);
148 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
149 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
150 elm_box_pack_end(bx, pb);
151 evas_object_show(ic1);
152 evas_object_show(pb);
153 example_data.pb3 = pb;
155 hbx = elm_box_add(win);
156 elm_box_horizontal_set(hbx, EINA_TRUE);
157 evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
158 evas_object_size_hint_align_set(hbx, EVAS_HINT_FILL, EVAS_HINT_FILL);
159 elm_box_pack_end(bx, hbx);
160 evas_object_show(hbx);
163 pb = elm_progressbar_add(win);
164 elm_progressbar_horizontal_set(pb, EINA_FALSE);
165 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, EVAS_HINT_FILL);
166 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
167 elm_box_pack_end(hbx, pb);
168 elm_object_text_set(pb, "percent");
169 evas_object_show(pb);
170 example_data.pb4 = pb;
172 /* vertical pb, with pulse and custom (small) span size */
173 pb = elm_progressbar_add(win);
174 elm_progressbar_horizontal_set(pb, EINA_FALSE);
175 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
176 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
177 elm_progressbar_span_size_set(pb, 80);
178 elm_progressbar_pulse_set(pb, EINA_TRUE);
179 elm_progressbar_unit_format_set(pb, NULL);
180 elm_object_text_set(pb, "Infinite bounce");
181 elm_box_pack_end(hbx, pb);
182 evas_object_show(pb);
183 example_data.pb5 = pb;
185 ic2 = elm_icon_add(win);
186 elm_icon_file_set(ic2, buf, NULL);
187 evas_object_size_hint_aspect_set(ic2, EVAS_ASPECT_CONTROL_HORIZONTAL, 1, 1);
189 /* vertical pb, inverted, with custom unit format and icon*/
190 pb = elm_progressbar_add(win);
191 elm_progressbar_horizontal_set(pb, EINA_FALSE);
192 elm_object_text_set(pb, "Label");
193 elm_object_part_content_set(pb, "icon", ic2);
194 elm_progressbar_inverted_set(pb, EINA_TRUE);
195 elm_progressbar_unit_format_set(pb, "%1.2f%%");
196 elm_progressbar_span_size_set(pb, 200);
197 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
198 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
199 elm_box_pack_end(hbx, pb);
200 evas_object_show(ic2);
201 evas_object_show(pb);
202 example_data.pb6 = pb;
204 /* "wheel" style progress bar */
205 pb = elm_progressbar_add(win);
206 elm_object_style_set(pb, "wheel");
207 elm_object_text_set(pb, "Style: wheel");
208 evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
209 evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
210 elm_box_pack_end(bx, pb);
211 evas_object_show(pb);
212 example_data.pb7 = pb;
214 bt_bx = elm_box_add(win);
215 elm_box_horizontal_set(bt_bx, EINA_TRUE);
216 evas_object_size_hint_weight_set(bt_bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
217 elm_box_pack_end(bx, bt_bx);
218 evas_object_show(bt_bx);
220 bt = elm_button_add(win);
221 elm_object_text_set(bt, "Start");
222 evas_object_smart_callback_add(bt, "clicked", _progressbar_example_start,
224 elm_box_pack_end(bt_bx, bt);
225 evas_object_show(bt);
227 bt = elm_button_add(win);
228 elm_object_text_set(bt, "Stop");
229 evas_object_smart_callback_add(bt, "clicked", _progressbar_example_stop,
231 elm_box_pack_end(bt_bx, bt);
232 evas_object_show(bt);
234 evas_object_show(win);