2 * Simple Elementary's <b>flip selector widget</b> example, illustrating its
5 * See stdout/stderr for output. Compile with:
8 * gcc -g flipselector_example.c -o flipselector_example `pkg-config --cflags --libs elementary`
12 #include <Elementary.h>
14 static const char *commands = \
16 "\tn - flip to next item\n"
17 "\tp - flip to previous item\n"
18 "\tf - print first item's label\n"
19 "\tl - print last item's label\n"
20 "\ts - print selected item's label\n"
23 void /* unselect the item shown in the flip selector */
29 Evas_Object *fp = data;
31 it = elm_flipselector_selected_item_get(fp);
32 elm_flipselector_item_selected_set(it, EINA_FALSE);
35 void /* delete the item shown in the flip selector */
41 Evas_Object *fp = data;
43 it = elm_flipselector_selected_item_get(fp);
44 if (it) elm_object_item_del(it);
47 void /* underflow callback */
48 _underflow_cb(void *data,
52 fprintf(stdout, "Underflow!\n");
55 void /* overflow callback */
56 _overflow_cb(void *data,
60 fprintf(stdout, "Overflow!\n");
64 _on_keydown(void *data,
67 Evas_Callback_Type type,
70 Evas_Object *fs = data;
71 Evas_Event_Key_Down *ev = event_info;
73 if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
75 if (strcmp(ev->keyname, "h") == 0) /* print help */
77 fprintf(stdout, "%s", commands);
79 else if (strcmp(ev->keyname, "n") == 0) /* flip to next item */
81 elm_flipselector_flip_next(fs);
83 fprintf(stdout, "Flipping to next item\n");
85 else if (strcmp(ev->keyname, "p") == 0) /* flip to previous item */
87 elm_flipselector_flip_prev(fs);
89 fprintf(stdout, "Flipping to previous item\n");
91 else if (strcmp(ev->keyname, "f") == 0) /* print first item's label */
95 it = elm_flipselector_first_item_get(fs);
97 fprintf(stdout, "Flip selector's first item is: %s\n", it ?
98 elm_object_item_text_get(it) : "none");
100 else if (strcmp(ev->keyname, "l") == 0) /* print last item's label */
104 it = elm_flipselector_last_item_get(fs);
106 fprintf(stdout, "Flip selector's last item is: %s\n", it ?
107 elm_object_item_text_get(it) : "none");
109 else if (strcmp(ev->keyname, "s") == 0) /* print selected item's label */
113 it = elm_flipselector_selected_item_get(fs);
115 fprintf(stdout, "Flip selector's selected item is: %s\n", it ?
116 elm_object_item_text_get(it) : "none");
121 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
126 elm_main(int argc, char **argv)
129 Evas_Object *win, *bx, *fp, *bt;
130 static const char *lbl[] =
142 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
144 win = elm_win_util_standard_add("flipselector", "Flip Selector Example");
145 elm_win_autodel_set(win, EINA_TRUE);
147 bx = elm_box_add(win);
148 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
149 elm_win_resize_object_add(win, bx);
150 evas_object_show(bx);
152 fp = elm_flipselector_add(win);
153 evas_object_size_hint_weight_set(fp, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
154 evas_object_smart_callback_add(fp, "underflowed", _overflow_cb, NULL);
155 evas_object_smart_callback_add(fp, "overflowed", _underflow_cb, NULL);
156 for (i = 0; i < sizeof(lbl) / sizeof(lbl[0]); i++)
157 elm_flipselector_item_append(fp, lbl[i], NULL, NULL);
158 elm_box_pack_end(bx, fp);
159 evas_object_show(fp);
161 bt = elm_button_add(win);
162 elm_object_text_set(bt, "Unselect item");
163 evas_object_smart_callback_add(bt, "clicked", _unsel_cb, fp);
164 elm_box_pack_end(bx, bt);
165 evas_object_show(bt);
167 bt = elm_button_add(win);
168 elm_object_text_set(bt, "Delete item");
169 evas_object_smart_callback_add(bt, "clicked", _del_cb, fp);
170 elm_box_pack_end(bx, bt);
171 evas_object_show(bt);
173 elm_object_event_callback_add(win, _on_keydown, fp);
175 evas_object_show(win);
177 fprintf(stdout, "%s", commands);