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__,
38 elm_gengrid_item_bring_in(event_info);
40 elm_gengrid_item_bring_in(event_info, ELM_GENGRID_ITEM_SCROLLTO_IN);
41 >>>>>>> remotes/origin/upstream
45 _on_done(void *data __UNUSED__,
46 Evas_Object *obj __UNUSED__,
47 void *event_info __UNUSED__)
53 _grid_label_get(void *data,
54 Evas_Object *obj __UNUSED__,
55 const char *part __UNUSED__)
58 return strdup(items[idx]);
62 _grid_content_get(void *data __UNUSED__,
66 if (!strcmp(part, "elm.swallow.icon"))
69 snprintf(buf, sizeof(buf), "%s/images/%s", PACKAGE_DATA_DIR,
72 Evas_Object *icon = elm_bg_add(obj);
73 elm_bg_file_set(icon, buf, NULL);
74 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1,
76 evas_object_show(icon);
83 /* ordering alphabetically */
85 _index_icmp(const void *data1,
88 const char *label1, *label2;
90 const Elm_Object_Item *index_it1 = data1;
91 const Elm_Object_Item *index_it2 = data2;
93 label1 = elm_index_item_letter_get(index_it1);
94 label2 = elm_index_item_letter_get(index_it2);
96 return strcasecmp(label1, label2);
100 elm_main(int argc __UNUSED__,
101 char **argv __UNUSED__)
103 Evas_Object *win, *bg, *grid, *index;
105 Elm_Gengrid_Item *it;
107 Elm_Object_Item *gg_it;
108 >>>>>>> remotes/origin/upstream
111 Elm_Gengrid_Item_Class gic;
113 win = elm_win_add(NULL, "index", ELM_WIN_BASIC);
114 elm_win_title_set(win, "Index Example");
115 evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
117 bg = elm_bg_add(win);
118 elm_win_resize_object_add(win, bg);
119 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
120 evas_object_show(bg);
122 grid = elm_gengrid_add(win);
123 elm_gengrid_item_size_set(grid, 150, 150);
125 gic.item_style = "default";
126 gic.func.text_get = _grid_label_get;
127 gic.func.content_get = _grid_content_get;
128 gic.func.state_get = NULL;
131 evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
132 elm_win_resize_object_add(win, grid);
133 evas_object_show(grid);
135 index = elm_index_add(win);
136 evas_object_size_hint_weight_set(index, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
137 elm_win_resize_object_add(win, index);
139 evas_object_show(index);
141 for (i = 0; i < (sizeof(items) / sizeof(items[0])); i++)
146 it = elm_gengrid_item_append(grid, &gic, (void *)i, NULL, NULL);
148 /* indexing by first letters */
149 snprintf(buf, sizeof(buf), "%c", items[i][0]);
150 elm_index_item_sorted_insert(index, buf, it, _index_icmp, NULL);
152 gg_it = elm_gengrid_item_append(grid, &gic, (void *)i, NULL, NULL);
154 /* indexing by first letters */
155 snprintf(buf, sizeof(buf), "%c", items[i][0]);
156 elm_index_item_sorted_insert(index, buf, NULL, gg_it, _index_icmp, NULL);
157 >>>>>>> remotes/origin/upstream
160 evas_object_smart_callback_add(index, "delay,changed", _index_changed, NULL);
162 evas_object_resize(win, 320, 300);
163 evas_object_show(win);
165 elm_index_active_set(index, EINA_TRUE);