2 * Simple Elementary's <b>index widget</b> example, illustrating its
3 * usage and API -- now with sorted insertions.
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"
17 # define PACKAGE_DATA_DIR "../../data"
20 static const char *items[] = \
33 _index_changed(void *data __UNUSED__,
34 Evas_Object *obj __UNUSED__,
37 elm_gengrid_item_bring_in(event_info);
41 _on_done(void *data __UNUSED__,
42 Evas_Object *obj __UNUSED__,
43 void *event_info __UNUSED__)
49 _grid_label_get(void *data,
50 Evas_Object *obj __UNUSED__,
51 const char *part __UNUSED__)
54 return strdup(items[idx]);
58 _grid_content_get(void *data __UNUSED__,
62 if (!strcmp(part, "elm.swallow.icon"))
65 snprintf(buf, sizeof(buf), "%s/images/%s", PACKAGE_DATA_DIR,
68 Evas_Object *icon = elm_bg_add(obj);
69 elm_bg_file_set(icon, buf, NULL);
70 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1,
72 evas_object_show(icon);
79 /* ordering alphabetically */
81 _index_icmp(const void *data1,
84 const char *label1, *label2;
86 const Elm_Index_Item *it1 = data1;
87 const Elm_Index_Item *it2 = data2;
89 label1 = elm_index_item_letter_get(it1);
90 label2 = elm_index_item_letter_get(it2);
92 return strcasecmp(label1, label2);
96 elm_main(int argc __UNUSED__,
97 char **argv __UNUSED__)
99 Evas_Object *win, *bg, *grid, *index;
100 Elm_Gengrid_Item *it;
103 Elm_Gengrid_Item_Class gic;
105 win = elm_win_add(NULL, "index", ELM_WIN_BASIC);
106 elm_win_title_set(win, "Index Example");
107 evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
109 bg = elm_bg_add(win);
110 elm_win_resize_object_add(win, bg);
111 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
112 evas_object_show(bg);
114 grid = elm_gengrid_add(win);
115 elm_gengrid_item_size_set(grid, 150, 150);
117 gic.item_style = "default";
118 gic.func.label_get = _grid_label_get;
119 gic.func.content_get = _grid_content_get;
120 gic.func.state_get = NULL;
123 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
124 elm_win_resize_object_add(win, grid);
125 evas_object_show(grid);
127 index = elm_index_add(win);
128 evas_object_size_hint_weight_set(index, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
129 elm_win_resize_object_add(win, index);
131 evas_object_show(index);
133 for (i = 0; i < (sizeof(items) / sizeof(items[0])); i++)
137 it = elm_gengrid_item_append(grid, &gic, (void *)i, NULL, NULL);
139 /* indexing by first letters */
140 snprintf(buf, sizeof(buf), "%c", items[i][0]);
141 elm_index_item_sorted_insert(index, buf, it, _index_icmp, NULL);
144 evas_object_smart_callback_add(index, "delay,changed", _index_changed, NULL);
146 evas_object_resize(win, 320, 300);
147 evas_object_show(win);
149 elm_index_active_set(index, EINA_TRUE);