2 * Simple Elementary's <b>slider widget</b> example, illustrating its
5 * See stdout/stderr for output. Compile with:
8 * gcc -g `pkg-config --cflags --libs elementary` slider_example.c -o slider_example
12 #include <Elementary.h>
14 # include "elementary_config.h"
20 _on_done(void *data __UNUSED__,
21 Evas_Object *obj __UNUSED__,
22 void *event_info __UNUSED__)
28 _changed_cb(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
30 double val = elm_slider_value_get(obj);
31 printf("Changed to %1.2f\n", val);
35 _delay_changed_cb(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
37 double val = elm_slider_value_get(obj);
38 printf("Delay changed to %1.2f\n", val);
42 _indicator_format(double val)
44 char *indicator = malloc(sizeof(char) * 32);
45 snprintf(indicator, 32, "%1.2f u", val);
50 _indicator_free(char *str)
56 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
58 Evas_Object *win, *bg, *bx, *sl, *ic;
60 win = elm_win_add(NULL, "slider", ELM_WIN_BASIC);
61 elm_win_title_set(win, "Slider Example");
62 evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
65 elm_win_resize_object_add(win, bg);
66 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
69 bx = elm_box_add(win);
70 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
71 elm_win_resize_object_add(win, bx);
75 sl = elm_slider_add(win);
76 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
77 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
78 elm_box_pack_end(bx, sl);
81 /* with icon, end and label */
82 sl = elm_slider_add(win);
83 elm_object_text_set(sl, "Counter");
85 ic = elm_icon_add(win);
86 elm_icon_standard_set(ic, "home");
87 elm_icon_resizable_set(ic, EINA_FALSE, EINA_FALSE);
88 elm_object_part_content_set(sl, "icon", ic);
90 ic = elm_icon_add(win);
91 elm_icon_standard_set(ic, "folder");
92 elm_icon_resizable_set(ic, EINA_FALSE, EINA_FALSE);
93 elm_object_part_content_set(sl, "end", ic);
95 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
96 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
97 elm_box_pack_end(bx, sl);
100 /* value set and span size */
101 sl = elm_slider_add(win);
102 elm_slider_value_set(sl, 1);
103 elm_slider_span_size_set(sl, 200);
104 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
105 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
106 elm_box_pack_end(bx, sl);
107 evas_object_show(sl);
109 /* with unit label and min - max */
110 sl = elm_slider_add(win);
111 elm_slider_unit_format_set(sl, "%1.0f units");
112 elm_slider_min_max_set(sl, 0, 100);
113 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
114 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
115 elm_box_pack_end(bx, sl);
116 evas_object_show(sl);
118 /* with indicator label and inverted */
119 sl = elm_slider_add(win);
120 elm_slider_indicator_format_set(sl, "%1.2f");
121 elm_slider_inverted_set(sl, EINA_TRUE);
122 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
123 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
124 elm_box_pack_end(bx, sl);
125 evas_object_show(sl);
127 /* vertical with indicator format func */
128 sl = elm_slider_add(win);
129 elm_slider_horizontal_set(sl, EINA_FALSE);
130 elm_slider_indicator_format_function_set(sl, _indicator_format,
132 evas_object_size_hint_align_set(sl, 0.5, EVAS_HINT_FILL);
133 evas_object_size_hint_weight_set(sl, 0, EVAS_HINT_EXPAND);
134 elm_box_pack_end(bx, sl);
135 evas_object_show(sl);
138 sl = elm_slider_add(win);
139 elm_slider_unit_format_set(sl, "%1.3f units");
140 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
141 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
142 elm_box_pack_end(bx, sl);
143 evas_object_show(sl);
144 evas_object_smart_callback_add(sl, "changed", _changed_cb, NULL);
145 evas_object_smart_callback_add(sl, "delay,changed", _delay_changed_cb, NULL);
147 evas_object_show(win);