elm examples: Adjust directory names.
[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 -DDATA_DIR="\"<directory>\'""
9  * @endverbatim
10  */
11
12 #include <Elementary.h>
13 #ifndef DATA_DIR
14 # define DATA_DIR "/usr/share/elementary"
15 #endif
16
17 typedef struct Progressbar_Example
18 {
19    Evas_Object *pb1;
20    Evas_Object *pb2; /* pulsing */
21    Evas_Object *pb3;
22    Evas_Object *pb4;
23    Evas_Object *pb5; /* pulsing */
24    Evas_Object *pb6;
25    Evas_Object *pb7; /* pulsing */
26
27    Eina_Bool    run;
28    Ecore_Timer *timer;
29 } Progressbar_Example;
30
31 static Progressbar_Example example_data;
32
33 static Eina_Bool
34 _progressbar_example_value_set(void *data)
35 {
36    double progress;
37
38    progress = elm_progressbar_value_get(example_data.pb1);
39    if (progress < 1.0) progress += 0.0123;
40    else progress = 0.0;
41
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);
47
48    if (progress < 1.0) return ECORE_CALLBACK_RENEW;
49
50    example_data.run = 0;
51    return ECORE_CALLBACK_CANCEL;
52 }
53
54 static void
55 _progressbar_example_start(void        *data,
56                            Evas_Object *obj,
57                            void        *event_info)
58 {
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);
62
63    if (!example_data.run)
64      {
65         example_data.timer = ecore_timer_add(
66             0.1, _progressbar_example_value_set, NULL);
67         example_data.run = EINA_TRUE;
68      }
69 }
70
71 /* end of show */
72 static void
73 _progressbar_example_stop(void        *data,
74                           Evas_Object *obj,
75                           void        *event_info)
76 {
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);
80
81    if (example_data.run)
82      {
83         ecore_timer_del(example_data.timer);
84         example_data.run = EINA_FALSE;
85      }
86 }
87
88 static void
89 _on_done(void        *data,
90          Evas_Object *obj,
91          void        *event_info)
92 {
93    _progressbar_example_stop(NULL, NULL, NULL);
94    elm_exit();
95 }
96
97 EAPI_MAIN int
98 elm_main(int    argc,
99          char **argv)
100 {
101    Evas_Object *win, *bg, *pb, *bx, *hbx, *bt, *bt_bx, *ic1, *ic2;
102    char buf[PATH_MAX];
103
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);
107
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);
112
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);
117
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;
125
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;
135
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);
140
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;
154
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);
161
162    /* vertical pb */
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;
171
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;
184
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);
188
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;
203
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;
213
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);
219
220    bt = elm_button_add(win);
221    elm_object_text_set(bt, "Start");
222    evas_object_smart_callback_add(bt, "clicked", _progressbar_example_start,
223                                   NULL);
224    elm_box_pack_end(bt_bx, bt);
225    evas_object_show(bt);
226
227    bt = elm_button_add(win);
228    elm_object_text_set(bt, "Stop");
229    evas_object_smart_callback_add(bt, "clicked", _progressbar_example_stop,
230                                   NULL);
231    elm_box_pack_end(bt_bx, bt);
232    evas_object_show(bt);
233
234    evas_object_show(win);
235
236    elm_run();
237    elm_shutdown();
238
239    return 0;
240 }
241 ELM_MAIN()