When the separators exist in toolbar and the toolbar shrinks by resizing window,
[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 progressbar_example.c -o progressbar_example `pkg-config --cflags --libs elementary`
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    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);
105
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);
110
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);
115
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;
123
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;
133
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);
138
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;
152
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);
159
160    /* vertical pb */
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;
169
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;
182
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);
186
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;
201
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;
211
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);
217
218    bt = elm_button_add(win);
219    elm_object_text_set(bt, "Start");
220    evas_object_smart_callback_add(bt, "clicked", _progressbar_example_start,
221                                   NULL);
222    elm_box_pack_end(bt_bx, bt);
223    evas_object_show(bt);
224
225    bt = elm_button_add(win);
226    elm_object_text_set(bt, "Stop");
227    evas_object_smart_callback_add(bt, "clicked", _progressbar_example_stop,
228                                   NULL);
229    elm_box_pack_end(bt_bx, bt);
230    evas_object_show(bt);
231
232    evas_object_show(win);
233
234    elm_run();
235    elm_shutdown();
236
237    return 0;
238 }
239 ELM_MAIN()