2 * Simple Elementary's <b>slider widget</b> example, illustrating its
5 * See stdout/stderr for output. Compile with:
8 * gcc -g slider_example.c -o slider_example `pkg-config --cflags --libs elementary`
12 #include <Elementary.h>
15 _changed_cb(void *data, Evas_Object *obj, void *event_info)
17 double val = elm_slider_value_get(obj);
18 printf("Changed to %1.2f\n", val);
22 _delay_changed_cb(void *data, Evas_Object *obj, void *event_info)
24 double val = elm_slider_value_get(obj);
25 printf("Delay changed to %1.2f\n", val);
29 _indicator_format(double val)
31 char *indicator = malloc(sizeof(char) * 32);
32 snprintf(indicator, 32, "%1.2f u", val);
37 _indicator_free(char *str)
43 elm_main(int argc, char **argv)
45 Evas_Object *win, *bx, *sl, *ic;
47 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
49 win = elm_win_util_standard_add("slider", "Slider Example");
50 elm_win_autodel_set(win, EINA_TRUE);
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);
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);
64 /* with icon, end and label */
65 sl = elm_slider_add(win);
66 elm_object_text_set(sl, "Counter");
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);
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);
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);
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);
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);
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);
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,
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);
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);
130 evas_object_show(win);