tizen 2.4 release
[framework/uifw/elementary.git] / src / examples / slider_example.c
1 /**
2  * Simple Elementary's <b>slider widget</b> example, illustrating its
3  * usage and API.
4  *
5  * See stdout/stderr for output. Compile with:
6  *
7  * @verbatim
8  * gcc -g slider_example.c -o slider_example `pkg-config --cflags --libs elementary`
9  * @endverbatim
10  */
11
12 #include <Elementary.h>
13
14 static void
15 _changed_cb(void *data, Evas_Object *obj, void *event_info)
16 {
17    double val = elm_slider_value_get(obj);
18    printf("Changed to %1.2f\n", val);
19 }
20
21 static void
22 _delay_changed_cb(void *data, Evas_Object *obj, void *event_info)
23 {
24    double val = elm_slider_value_get(obj);
25    printf("Delay changed to %1.2f\n", val);
26 }
27
28 static char*
29 _indicator_format(double val)
30 {
31    char *indicator = malloc(sizeof(char) * 32);
32    snprintf(indicator, 32, "%1.2f u", val);
33    return indicator;
34 }
35
36 static void
37 _indicator_free(char *str)
38 {
39    free(str);
40 }
41
42 EAPI_MAIN int
43 elm_main(int argc, char **argv)
44 {
45    Evas_Object *win, *bx, *sl, *ic;
46
47    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
48
49    win = elm_win_util_standard_add("slider", "Slider Example");
50    elm_win_autodel_set(win, EINA_TRUE);
51
52    bx = elm_box_add(win);
53    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
54    elm_win_resize_object_add(win, bx);
55    evas_object_show(bx);
56
57    /* default */
58    sl = elm_slider_add(win);
59    evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
60    evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
61    elm_box_pack_end(bx, sl);
62    evas_object_show(sl);
63
64    /* with icon, end and label */
65    sl = elm_slider_add(win);
66    elm_object_text_set(sl, "Counter");
67
68    ic = elm_icon_add(win);
69    elm_icon_standard_set(ic, "home");
70    elm_image_resizable_set(ic, EINA_FALSE, EINA_FALSE);
71    elm_object_part_content_set(sl, "icon", ic);
72
73    ic = elm_icon_add(win);
74    elm_icon_standard_set(ic, "folder");
75    elm_image_resizable_set(ic, EINA_FALSE, EINA_FALSE);
76    elm_object_part_content_set(sl, "end", ic);
77
78    evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
79    evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
80    elm_box_pack_end(bx, sl);
81    evas_object_show(sl);
82
83    /* value set and span size */
84    sl = elm_slider_add(win);
85    elm_slider_value_set(sl, 1);
86    elm_slider_span_size_set(sl, 200);
87    evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
88    evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
89    elm_box_pack_end(bx, sl);
90    evas_object_show(sl);
91
92    /* with unit label and min - max */
93    sl = elm_slider_add(win);
94    elm_slider_unit_format_set(sl, "%1.0f units");
95    elm_slider_min_max_set(sl, 0, 100);
96    evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
97    evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
98    elm_box_pack_end(bx, sl);
99    evas_object_show(sl);
100
101    /* with indicator label and inverted */
102    sl = elm_slider_add(win);
103    elm_slider_indicator_format_set(sl, "%1.2f");
104    elm_slider_inverted_set(sl, EINA_TRUE);
105    evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
106    evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
107    elm_box_pack_end(bx, sl);
108    evas_object_show(sl);
109
110    /* vertical with indicator format func */
111    sl = elm_slider_add(win);
112    elm_slider_horizontal_set(sl, EINA_FALSE);
113    elm_slider_indicator_format_function_set(sl, _indicator_format,
114                                             _indicator_free);
115    evas_object_size_hint_align_set(sl, 0.5, EVAS_HINT_FILL);
116    evas_object_size_hint_weight_set(sl, 0, EVAS_HINT_EXPAND);
117    elm_box_pack_end(bx, sl);
118    evas_object_show(sl);
119
120    /* callbacks */
121    sl = elm_slider_add(win);
122    elm_slider_unit_format_set(sl, "%1.3f units");
123    evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
124    evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
125    elm_box_pack_end(bx, sl);
126    evas_object_show(sl);
127    evas_object_smart_callback_add(sl, "changed", _changed_cb, NULL);
128    evas_object_smart_callback_add(sl, "delay,changed", _delay_changed_cb, NULL);
129
130    evas_object_show(win);
131
132    elm_run();
133
134    return 0;
135 }
136 ELM_MAIN()