2 * Simple Elementary's <b>index widget</b> example, illustrating its
5 * See stdout/stderr for output. Compile with:
8 * gcc -g `pkg-config --cflags --libs elementary` index_example.c -o index_example
12 #include <Elementary.h>
14 # include "elementary_config.h"
21 Evas_Object *list, *index;
24 struct example_data d = {NULL, NULL};
26 static const char *dict[] = \
32 _index_item_del(void *data,
33 Evas_Object *obj __UNUSED__,
36 fprintf(stdout, "Deleting associated list node (%s). Comparing index "
37 "item data reported via callback with the one returned by "
38 "index's API on items: %s.\n",
39 elm_object_item_text_get(data),
40 data == elm_index_item_data_get(event_info) ? "OK" :
41 "FAIL, something went wrong");
44 elm_list_item_del(data);
46 elm_object_item_del(data);
47 >>>>>>> remotes/origin/upstream
50 /* delete an index item */
52 _item_del(void *data __UNUSED__,
53 Evas_Object *obj __UNUSED__,
54 void *event_info __UNUSED__)
57 Elm_Object_Item *lit = elm_index_item_selected_get(d.index, 0);
59 iit = elm_index_item_find(d.index, lit);
63 fprintf(stdout, "Deleting last selected index item, which had letter"
64 " %s (pointing to %s)\n", elm_index_item_letter_get(iit),
65 elm_object_item_text_get(lit));
67 elm_object_item_del(lit);
71 _item_del_all(void *data __UNUSED__,
72 Evas_Object *obj __UNUSED__,
73 void *event_info __UNUSED__)
75 elm_index_item_clear(d.index);
79 _active_set(void *data __UNUSED__,
80 Evas_Object *obj __UNUSED__,
81 void *event_info __UNUSED__)
83 elm_index_active_set(d.index, !elm_index_active_get(d.index));
85 fprintf(stdout, "Toggling index programmatically.\n");
88 /* "delay,changed" hook */
90 _index_changed(void *data __UNUSED__,
91 Evas_Object *obj __UNUSED__,
94 elm_list_item_bring_in(event_info);
98 _index_selected(void *data __UNUSED__,
102 Elm_Object_Item *lit = event_info;
104 fprintf(stdout, "New index item selected. Comparing item reported"
105 " via callback with the selection returned by the API: "
106 "%s.\n", lit == elm_index_item_selected_get(obj, 0) ? "OK" :
107 "FAIL, something went wrong");
111 _on_done(void *data __UNUSED__,
112 Evas_Object *obj __UNUSED__,
113 void *event_info __UNUSED__)
119 elm_main(int argc __UNUSED__,
120 char **argv __UNUSED__)
122 Evas_Object *win, *bg, *hbox, *vbox, *bt, *sep;
123 Elm_Object_Item *lit;
127 >>>>>>> remotes/origin/upstream
131 win = elm_win_add(NULL, "index", ELM_WIN_BASIC);
132 elm_win_title_set(win, "Index Example");
133 evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
135 bg = elm_bg_add(win);
136 elm_win_resize_object_add(win, bg);
137 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
138 evas_object_show(bg);
140 vbox = elm_box_add(win);
141 elm_win_resize_object_add(win, vbox);
142 evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
143 evas_object_show(vbox);
145 d.list = elm_list_add(win);
146 evas_object_size_hint_weight_set(d.list, EVAS_HINT_EXPAND,
148 evas_object_size_hint_align_set(d.list, EVAS_HINT_FILL, EVAS_HINT_FILL);
149 evas_object_show(d.list);
150 elm_box_pack_end(vbox, d.list);
152 d.index = elm_index_add(win);
153 elm_win_resize_object_add(win, d.index);
154 evas_object_size_hint_weight_set(d.index, EVAS_HINT_EXPAND,
156 evas_object_size_hint_align_set(d.list, EVAS_HINT_FILL, EVAS_HINT_FILL);
157 evas_object_show(d.index);
159 for (i = 0; i < (sizeof(dict) / sizeof(dict[0])); i++)
161 lit = elm_list_item_append(d.list, dict[i], NULL, NULL, NULL, NULL);
163 if (curr != dict[i][0])
165 Elm_Object_Item *index_it;
169 /* indexing by first letters */
171 snprintf(buf, sizeof(buf), "%c", curr);
174 elm_index_item_append(d.index, buf, lit);
176 elm_index_item_append(d.index, buf, NULL, lit);
177 >>>>>>> remotes/origin/upstream
178 index_it = elm_index_item_find(d.index, lit);
180 elm_object_item_del_cb_set(index_it, _index_item_del);
184 evas_object_smart_callback_add(d.index, "delay,changed", _index_changed,
186 evas_object_smart_callback_add(d.index, "selected", _index_selected, NULL);
188 /* attribute setting knobs */
189 sep = elm_separator_add(win);
190 elm_separator_horizontal_set(sep, EINA_TRUE);
191 elm_box_pack_end(vbox, sep);
192 evas_object_show(sep);
194 hbox = elm_box_add(win);
195 elm_box_horizontal_set(hbox, EINA_TRUE);
196 evas_object_size_hint_weight_set(hbox, EVAS_HINT_EXPAND, 0);
197 evas_object_size_hint_fill_set(hbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
198 elm_box_pack_end(vbox, hbox);
199 evas_object_show(hbox);
201 bt = elm_button_add(win);
202 elm_object_text_set(bt, "bring in index");
203 evas_object_smart_callback_add(bt, "clicked", _active_set, NULL);
204 elm_box_pack_end(hbox, bt);
205 evas_object_show(bt);
207 bt = elm_button_add(win);
208 elm_object_text_set(bt, "delete last selected item");
209 evas_object_smart_callback_add(bt, "clicked", _item_del, NULL);
210 elm_box_pack_end(hbox, bt);
211 evas_object_show(bt);
213 bt = elm_button_add(win);
214 elm_object_text_set(bt, "delete all items");
215 evas_object_smart_callback_add(bt, "clicked", _item_del_all, NULL);
216 elm_box_pack_end(hbox, bt);
217 evas_object_show(bt);
219 evas_object_resize(win, 320, 600);
220 evas_object_show(win);