efl
182 строки · 5.1 Кб
1/**
2* Simple Elementary's <b>flip selector widget</b> example, illustrating its
3* usage and API.
4*
5* See stdout/stderr for output. Compile with:
6*
7* @verbatim
8* gcc -g flipselector_example.c -o flipselector_example `pkg-config --cflags --libs elementary`
9* @endverbatim
10*/
11
12#include <Elementary.h>
13
14static const char *commands = \
15"commands are:\n"
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"
21"\th - print help\n";
22
23void /* unselect the item shown in the flip selector */
24_unsel_cb(void *data,
25Evas_Object *obj EINA_UNUSED,
26void *event_info EINA_UNUSED)
27{
28Elm_Object_Item *it;
29Evas_Object *fp = data;
30
31it = elm_flipselector_selected_item_get(fp);
32elm_flipselector_item_selected_set(it, EINA_FALSE);
33}
34
35void /* delete the item shown in the flip selector */
36_del_cb(void *data,
37Evas_Object *obj EINA_UNUSED,
38void *event_info EINA_UNUSED)
39{
40Elm_Object_Item *it;
41Evas_Object *fp = data;
42
43it = elm_flipselector_selected_item_get(fp);
44if (it) elm_object_item_del(it);
45}
46
47void /* underflow callback */
48_underflow_cb(void *data EINA_UNUSED,
49Evas_Object *obj EINA_UNUSED,
50void *event_info EINA_UNUSED)
51{
52printf("Underflow!\n");
53}
54
55void /* overflow callback */
56_overflow_cb(void *data EINA_UNUSED,
57Evas_Object *obj EINA_UNUSED,
58void *event_info EINA_UNUSED)
59{
60printf("Overflow!\n");
61}
62
63static Eina_Bool
64_on_keydown(void *data,
65Evas_Object *object EINA_UNUSED,
66Evas_Object *src EINA_UNUSED,
67Evas_Callback_Type type,
68void *event_info)
69{
70Evas_Object *fs = data;
71Evas_Event_Key_Down *ev = event_info;
72
73if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
74
75if (strcmp(ev->keyname, "h") == 0) /* print help */
76{
77printf("%s", commands);
78}
79else if (strcmp(ev->keyname, "n") == 0) /* flip to next item */
80{
81elm_flipselector_flip_next(fs);
82
83printf("Flipping to next item\n");
84}
85else if (strcmp(ev->keyname, "p") == 0) /* flip to previous item */
86{
87elm_flipselector_flip_prev(fs);
88
89printf("Flipping to previous item\n");
90}
91else if (strcmp(ev->keyname, "f") == 0) /* print first item's label */
92{
93Elm_Object_Item *it;
94
95it = elm_flipselector_first_item_get(fs);
96
97printf("Flip selector's first item is: %s\n", it ?
98elm_object_item_text_get(it) : "none");
99}
100else if (strcmp(ev->keyname, "l") == 0) /* print last item's label */
101{
102Elm_Object_Item *it;
103
104it = elm_flipselector_last_item_get(fs);
105
106printf("Flip selector's last item is: %s\n", it ?
107elm_object_item_text_get(it) : "none");
108}
109else if (strcmp(ev->keyname, "s") == 0) /* print selected item's label */
110{
111Elm_Object_Item *it;
112
113it = elm_flipselector_selected_item_get(fs);
114
115printf("Flip selector's selected item is: %s\n", it ?
116elm_object_item_text_get(it) : "none");
117}
118else
119return EINA_FALSE;
120
121ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
122return EINA_TRUE;
123}
124
125EAPI_MAIN int
126elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
127{
128unsigned int i;
129Evas_Object *win, *bx, *fp, *bt;
130static const char *lbl[] =
131{
132"Elementary",
133"Evas",
134"Eina",
135"Edje",
136"Eet",
137"Ecore",
138"Efreet",
139"Eldbus"
140};
141
142elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
143
144win = elm_win_util_standard_add("flipselector", "Flip Selector Example");
145elm_win_autodel_set(win, EINA_TRUE);
146
147bx = elm_box_add(win);
148evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
149elm_win_resize_object_add(win, bx);
150evas_object_show(bx);
151
152fp = elm_flipselector_add(win);
153evas_object_size_hint_weight_set(fp, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
154evas_object_smart_callback_add(fp, "underflowed", _overflow_cb, NULL);
155evas_object_smart_callback_add(fp, "overflowed", _underflow_cb, NULL);
156for (i = 0; i < sizeof(lbl) / sizeof(lbl[0]); i++)
157elm_flipselector_item_append(fp, lbl[i], NULL, NULL);
158elm_box_pack_end(bx, fp);
159evas_object_show(fp);
160
161bt = elm_button_add(win);
162elm_object_text_set(bt, "Unselect item");
163evas_object_smart_callback_add(bt, "clicked", _unsel_cb, fp);
164elm_box_pack_end(bx, bt);
165evas_object_show(bt);
166
167bt = elm_button_add(win);
168elm_object_text_set(bt, "Delete item");
169evas_object_smart_callback_add(bt, "clicked", _del_cb, fp);
170elm_box_pack_end(bx, bt);
171evas_object_show(bt);
172
173elm_object_event_callback_add(win, _on_keydown, fp);
174
175evas_object_show(win);
176
177printf("%s", commands);
178elm_run();
179
180return 0;
181}
182ELM_MAIN()
183