2 * Simple Elementary's <b>flip selector widget</b> example, illustrating its
5 * See stdout/stderr for output. Compile with:
8 * gcc -g `pkg-config --cflags --libs elementary` flipselector_example.c -o flipselector_example
12 #include <Elementary.h>
14 # include "elementary_config.h"
19 static const char *commands = \
21 "\tn - flip to next item\n"
22 "\tp - flip to previous item\n"
23 "\tf - print first item's label\n"
24 "\tl - print last item's label\n"
25 "\ts - print selected item's label\n"
29 _on_done(void *data __UNUSED__,
30 Evas_Object *obj __UNUSED__,
31 void *event_info __UNUSED__)
36 void /* unselect the item shown in the flip selector */
38 Evas_Object *obj __UNUSED__,
39 void *event_info __UNUSED__)
42 Evas_Object *fp = data;
44 it = elm_flipselector_selected_item_get(fp);
45 elm_flipselector_item_selected_set(it, EINA_FALSE);
48 void /* delete the item shown in the flip selector */
50 Evas_Object *obj __UNUSED__,
51 void *event_info __UNUSED__)
54 Evas_Object *fp = data;
56 it = elm_flipselector_selected_item_get(fp);
57 if (it) elm_object_item_del(it);
60 void /* underflow callback */
61 _underflow_cb(void *data __UNUSED__,
62 Evas_Object *obj __UNUSED__,
63 void *event_info __UNUSED__)
65 fprintf(stdout, "Underflow!\n");
68 void /* overflow callback */
69 _overflow_cb(void *data __UNUSED__,
70 Evas_Object *obj __UNUSED__,
71 void *event_info __UNUSED__)
73 fprintf(stdout, "Overflow!\n");
77 _on_keydown(void *data,
78 Evas_Object *object __UNUSED__,
79 Evas_Object *src __UNUSED__,
80 Evas_Callback_Type type,
83 Evas_Object *fs = data;
84 Evas_Event_Key_Down *ev = event_info;
86 if (type != EVAS_CALLBACK_KEY_DOWN) return;
88 if (strcmp(ev->keyname, "h") == 0) /* print help */
90 fprintf(stdout, commands);
94 if (strcmp(ev->keyname, "n") == 0) /* flip to next item */
96 elm_flipselector_flip_next(fs);
98 fprintf(stdout, "Flipping to next item\n");
103 if (strcmp(ev->keyname, "p") == 0) /* flip to previous item */
105 elm_flipselector_flip_prev(fs);
107 fprintf(stdout, "Flipping to previous item\n");
112 if (strcmp(ev->keyname, "f") == 0) /* print first item's label */
116 it = elm_flipselector_first_item_get(fs);
118 fprintf(stdout, "Flip selector's first item is: %s\n", it ?
119 elm_object_item_text_get(it) : "none");
124 if (strcmp(ev->keyname, "l") == 0) /* print last item's label */
128 it = elm_flipselector_last_item_get(fs);
130 fprintf(stdout, "Flip selector's last item is: %s\n", it ?
131 elm_object_item_text_get(it) : "none");
136 if (strcmp(ev->keyname, "s") == 0) /* print selected item's label */
140 it = elm_flipselector_selected_item_get(fs);
142 fprintf(stdout, "Flip selector's selected item is: %s\n", it ?
143 elm_object_item_text_get(it) : "none");
150 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
153 Evas_Object *win, *bg, *bx, *fp, *bt;
154 static const char *lbl[] =
166 win = elm_win_add(NULL, "flipselector", ELM_WIN_BASIC);
167 elm_win_title_set(win, "Flip Selector Example");
168 evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
170 bg = elm_bg_add(win);
171 elm_win_resize_object_add(win, bg);
172 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
173 evas_object_show(bg);
175 bx = elm_box_add(win);
176 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
177 elm_win_resize_object_add(win, bx);
178 evas_object_show(bx);
180 fp = elm_flipselector_add(win);
181 evas_object_size_hint_weight_set(fp, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
182 evas_object_smart_callback_add(fp, "underflowed", _overflow_cb, NULL);
183 evas_object_smart_callback_add(fp, "overflowed", _underflow_cb, NULL);
184 for (i = 0; i < sizeof(lbl) / sizeof(lbl[0]); i++)
185 elm_flipselector_item_append(fp, lbl[i], NULL, NULL);
186 elm_box_pack_end(bx, fp);
187 evas_object_show(fp);
189 bt = elm_button_add(win);
190 elm_object_text_set(bt, "Unselect item");
191 evas_object_smart_callback_add(bt, "clicked", _unsel_cb, fp);
192 elm_box_pack_end(bx, bt);
193 evas_object_show(bt);
195 bt = elm_button_add(win);
196 elm_object_text_set(bt, "Delete item");
197 evas_object_smart_callback_add(bt, "clicked", _del_cb, fp);
198 elm_box_pack_end(bx, bt);
199 evas_object_show(bt);
201 elm_object_event_callback_add(win, (Elm_Event_Cb)_on_keydown, fp);
203 evas_object_show(win);
205 fprintf(stdout, commands);