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_list_item_label_get(data),
40 data == elm_index_item_data_get(event_info) ? "OK" :
41 "FAIL, something went wrong");
43 elm_list_item_del(data);
46 /* delete an index item */
48 _item_del(void *data __UNUSED__,
49 Evas_Object *obj __UNUSED__,
50 void *event_info __UNUSED__)
53 Elm_List_Item *lit = elm_index_item_selected_get(d.index, 0);
55 iit = elm_index_item_find(d.index, lit);
59 fprintf(stdout, "Deleting last selected index item, which had letter"
60 " %s (pointing to %s)\n", elm_index_item_letter_get(iit),
61 elm_list_item_label_get(lit));
63 elm_index_item_del(d.index, lit);
67 _item_del_all(void *data __UNUSED__,
68 Evas_Object *obj __UNUSED__,
69 void *event_info __UNUSED__)
71 elm_index_item_clear(d.index);
75 _active_set(void *data __UNUSED__,
76 Evas_Object *obj __UNUSED__,
77 void *event_info __UNUSED__)
79 elm_index_active_set(d.index, !elm_index_active_get(d.index));
81 fprintf(stdout, "Toggling index programmatically.\n");
84 /* "delay,changed" hook */
86 _index_changed(void *data __UNUSED__,
87 Evas_Object *obj __UNUSED__,
90 elm_list_item_bring_in(event_info);
94 _index_selected(void *data __UNUSED__,
98 Elm_List_Item *it = event_info;
100 fprintf(stdout, "New index item selected. Comparing item reported"
101 " via callback with the selection returned by the API: "
102 "%s.\n", it == elm_index_item_selected_get(obj, 0) ? "OK" :
103 "FAIL, something went wrong");
107 _on_done(void *data __UNUSED__,
108 Evas_Object *obj __UNUSED__,
109 void *event_info __UNUSED__)
115 elm_main(int argc __UNUSED__,
116 char **argv __UNUSED__)
118 Evas_Object *win, *bg, *hbox, *vbox, *bt, *sep;
123 win = elm_win_add(NULL, "index", ELM_WIN_BASIC);
124 elm_win_title_set(win, "Index Example");
125 evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
127 bg = elm_bg_add(win);
128 elm_win_resize_object_add(win, bg);
129 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
130 evas_object_show(bg);
132 vbox = elm_box_add(win);
133 elm_win_resize_object_add(win, vbox);
134 evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
135 evas_object_show(vbox);
137 d.list = elm_list_add(win);
138 evas_object_size_hint_weight_set(d.list, EVAS_HINT_EXPAND,
140 evas_object_size_hint_align_set(d.list, EVAS_HINT_FILL, EVAS_HINT_FILL);
141 evas_object_show(d.list);
142 elm_box_pack_end(vbox, d.list);
144 d.index = elm_index_add(win);
145 elm_win_resize_object_add(win, d.index);
146 evas_object_size_hint_weight_set(d.index, EVAS_HINT_EXPAND,
148 evas_object_size_hint_align_set(d.list, EVAS_HINT_FILL, EVAS_HINT_FILL);
149 evas_object_show(d.index);
151 for (i = 0; i < (sizeof(dict) / sizeof(dict[0])); i++)
153 it = elm_list_item_append(d.list, dict[i], NULL, NULL, NULL, NULL);
155 if (curr != dict[i][0])
157 Elm_Object_Item *index_it;
161 /* indexing by first letters */
163 snprintf(buf, sizeof(buf), "%c", curr);
164 elm_index_item_append(d.index, buf, it);
165 index_it = elm_index_item_find(d.index, it);
167 elm_object_item_del_cb_set(index_it, _index_item_del);
171 evas_object_smart_callback_add(d.index, "delay,changed", _index_changed,
173 evas_object_smart_callback_add(d.index, "selected", _index_selected, NULL);
175 /* attribute setting knobs */
176 sep = elm_separator_add(win);
177 elm_separator_horizontal_set(sep, EINA_TRUE);
178 elm_box_pack_end(vbox, sep);
179 evas_object_show(sep);
181 hbox = elm_box_add(win);
182 elm_box_horizontal_set(hbox, EINA_TRUE);
183 evas_object_size_hint_weight_set(hbox, EVAS_HINT_EXPAND, 0);
184 evas_object_size_hint_fill_set(hbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
185 elm_box_pack_end(vbox, hbox);
186 evas_object_show(hbox);
188 bt = elm_button_add(win);
189 elm_object_text_set(bt, "bring in index");
190 evas_object_smart_callback_add(bt, "clicked", _active_set, NULL);
191 elm_box_pack_end(hbox, bt);
192 evas_object_show(bt);
194 bt = elm_button_add(win);
195 elm_object_text_set(bt, "delete last selected item");
196 evas_object_smart_callback_add(bt, "clicked", _item_del, NULL);
197 elm_box_pack_end(hbox, bt);
198 evas_object_show(bt);
200 bt = elm_button_add(win);
201 elm_object_text_set(bt, "delete all items");
202 evas_object_smart_callback_add(bt, "clicked", _item_del_all, NULL);
203 elm_box_pack_end(hbox, bt);
204 evas_object_show(bt);
206 evas_object_resize(win, 320, 600);
207 evas_object_show(win);