9d92312ae39faad96abda8ba32ebcc42f14f638d
[framework/uifw/elementary.git] / src / examples / progressbar_example.c
1 /**
2  * Simple Elementary's <b>progress bar widget</b> example, illustrating its
3  * usage and API.
4  *
5  * See stdout/stderr for output. Compile with:
6  *
7  * @verbatim
8  * gcc -g `pkg-config --cflags --libs elementary` progressbar_example.c -o progressbar_example
9  * @endverbatim
10  */
11
12 #include <Elementary.h>
13
14 typedef struct Progressbar_Example
15 {
16    Evas_Object *pb1;
17    Evas_Object *pb2; /* pulsing */
18    Evas_Object *pb3;
19    Evas_Object *pb4;
20    Evas_Object *pb5; /* pulsing */
21    Evas_Object *pb6;
22    Evas_Object *pb7; /* pulsing */
23
24    Eina_Bool    run;
25    Ecore_Timer *timer;
26 } Progressbar_Example;
27
28 static Progressbar_Example example_data;
29
30 static Eina_Bool
31 _progressbar_example_value_set(void *data)
32 {
33    double progress;
34
35    progress = elm_progressbar_value_get(example_data.pb1);
36    if (progress < 1.0) progress += 0.0123;
37    else progress = 0.0;
38
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);
44
45    if (progress < 1.0) return ECORE_CALLBACK_RENEW;
46
47    example_data.run = 0;
48    return ECORE_CALLBACK_CANCEL;
49 }
50
51 static void
52 _progressbar_example_start(void        *data,
53                            Evas_Object *obj,
54                            void        *event_info)
55 {
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);
59
60    if (!example_data.run)
61      {
62         example_data.timer = ecore_timer_add(
63             0.1, _progressbar_example_value_set, NULL);
64         example_data.run = EINA_TRUE;
65      }
66 }
67
68 /* end of show */
69 static void
70 _progressbar_example_stop(void        *data,
71                           Evas_Object *obj,
72                           void        *event_info)
73 {
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);
77
78    if (example_data.run)
79      {
80         ecore_timer_del(example_data.timer);
81         example_data.run = EINA_FALSE;
82      }
83 }
84
85 static void
86 _on_done(void        *data,
87          Evas_Object *obj,
88          void        *event_info)
89 {
90    _progressbar_example_stop(NULL, NULL, NULL);
91    elm_exit();
92 }
93
94 EAPI_MAIN int
95 elm_main(int    argc,
96          char **argv)
97 {
98    Evas_Object *win, *bg, *pb, *bx, *hbx, *bt, *bt_bx, *ic1, *ic2;
99    char buf[PATH_MAX];
100
101    win = elm_win_add(NULL, "progressbar", ELM_WIN_BASIC);
102    elm_win_title_set(win, "Progress bar example");
103    evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
104
105    bg = elm_bg_add(win);
106    elm_win_resize_object_add(win, bg);
107    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
108    evas_object_show(bg);
109
110    bx = elm_box_add(win);
111    elm_win_resize_object_add(win, bx);
112    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
113    evas_object_show(bx);
114
115    /* pb with no label, default unit label and no icon */
116    pb = elm_progressbar_add(win);
117    evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
118    evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
119    elm_box_pack_end(bx, pb);
120    evas_object_show(pb);
121    example_data.pb1 = pb;
122
123    /* pb with label, and set to pulse */
124    pb = elm_progressbar_add(win);
125    evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
126    evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
127    elm_object_text_set(pb, "Infinite bounce");
128    elm_progressbar_pulse_set(pb, EINA_TRUE);
129    elm_box_pack_end(bx, pb);
130    evas_object_show(pb);
131    example_data.pb2 = pb;
132
133    ic1 = elm_icon_add(win);
134    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", PACKAGE_DATA_DIR);
135    elm_icon_file_set(ic1, buf, NULL);
136    evas_object_size_hint_aspect_set(ic1, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
137
138    /* pb with label, icon, custom unit label and span size set */
139    pb = elm_progressbar_add(win);
140    elm_object_text_set(pb, "Label");
141    elm_object_part_content_set(pb, "icon", ic1);
142    elm_progressbar_inverted_set(pb, EINA_TRUE);
143    elm_progressbar_unit_format_set(pb, "%1.1f units");
144    elm_progressbar_span_size_set(pb, 200);
145    evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
146    evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
147    elm_box_pack_end(bx, pb);
148    evas_object_show(ic1);
149    evas_object_show(pb);
150    example_data.pb3 = pb;
151
152    hbx = elm_box_add(win);
153    elm_box_horizontal_set(hbx, EINA_TRUE);
154    evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
155    evas_object_size_hint_align_set(hbx, EVAS_HINT_FILL, EVAS_HINT_FILL);
156    elm_box_pack_end(bx, hbx);
157    evas_object_show(hbx);
158
159    /* vertical pb */
160    pb = elm_progressbar_add(win);
161    elm_progressbar_horizontal_set(pb, EINA_FALSE);
162    evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, EVAS_HINT_FILL);
163    evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
164    elm_box_pack_end(hbx, pb);
165    elm_object_text_set(pb, "percent");
166    evas_object_show(pb);
167    example_data.pb4 = pb;
168
169    /* vertical pb, with pulse and custom (small) span size */
170    pb = elm_progressbar_add(win);
171    elm_progressbar_horizontal_set(pb, EINA_FALSE);
172    evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
173    evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
174    elm_progressbar_span_size_set(pb, 80);
175    elm_progressbar_pulse_set(pb, EINA_TRUE);
176    elm_progressbar_unit_format_set(pb, NULL);
177    elm_object_text_set(pb, "Infinite bounce");
178    elm_box_pack_end(hbx, pb);
179    evas_object_show(pb);
180    example_data.pb5 = pb;
181
182    ic2 = elm_icon_add(win);
183    elm_icon_file_set(ic2, buf, NULL);
184    evas_object_size_hint_aspect_set(ic2, EVAS_ASPECT_CONTROL_HORIZONTAL, 1, 1);
185
186    /* vertical pb, inverted, with custom unit format and icon*/
187    pb = elm_progressbar_add(win);
188    elm_progressbar_horizontal_set(pb, EINA_FALSE);
189    elm_object_text_set(pb, "Label");
190    elm_object_part_content_set(pb, "icon", ic2);
191    elm_progressbar_inverted_set(pb, EINA_TRUE);
192    elm_progressbar_unit_format_set(pb, "%1.2f%%");
193    elm_progressbar_span_size_set(pb, 200);
194    evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
195    evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
196    elm_box_pack_end(hbx, pb);
197    evas_object_show(ic2);
198    evas_object_show(pb);
199    example_data.pb6 = pb;
200
201    /* "wheel" style progress bar */
202    pb = elm_progressbar_add(win);
203    elm_object_style_set(pb, "wheel");
204    elm_object_text_set(pb, "Style: wheel");
205    evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
206    evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
207    elm_box_pack_end(bx, pb);
208    evas_object_show(pb);
209    example_data.pb7 = pb;
210
211    bt_bx = elm_box_add(win);
212    elm_box_horizontal_set(bt_bx, EINA_TRUE);
213    evas_object_size_hint_weight_set(bt_bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
214    elm_box_pack_end(bx, bt_bx);
215    evas_object_show(bt_bx);
216
217    bt = elm_button_add(win);
218    elm_object_text_set(bt, "Start");
219    evas_object_smart_callback_add(bt, "clicked", _progressbar_example_start,
220                                   NULL);
221    elm_box_pack_end(bt_bx, bt);
222    evas_object_show(bt);
223
224    bt = elm_button_add(win);
225    elm_object_text_set(bt, "Stop");
226    evas_object_smart_callback_add(bt, "clicked", _progressbar_example_stop,
227                                   NULL);
228    elm_box_pack_end(bt_bx, bt);
229    evas_object_show(bt);
230
231    evas_object_show(win);
232
233    elm_run();
234    elm_shutdown();
235
236    return 0;
237 }
238 ELM_MAIN()