4c67d037497c1a6f1debd4585fc766d167b09728
[framework/uifw/elementary.git] / src / examples / index_example_02.c
1 /**
2  * Simple Elementary's <b>index widget</b> example, illustrating its
3  * usage and API -- now with sorted insertions.
4  *
5  * See stdout/stderr for output. Compile with:
6  *
7  * @verbatim
8  * gcc -g `pkg-config --cflags --libs elementary` index_example.c -o index_example
9  * @endverbatim
10  */
11
12 #include <Elementary.h>
13 #ifdef HAVE_CONFIG_H
14 # include "elementary_config.h"
15 #else
16 # define __UNUSED__
17 # define PACKAGE_DATA_DIR "../../data"
18 #endif
19
20 static const char *items[] = \
21 {
22    "Judith",
23    "Paulina",
24    "Cathy",
25    "Vendella",
26    "Naomi",
27    "Ashley",
28    "Stacey",
29    "Gail"
30 };
31
32 static void
33 _index_changed(void        *data __UNUSED__,
34                Evas_Object *obj __UNUSED__,
35                void        *event_info)
36 {
37 <<<<<<< HEAD
38    elm_gengrid_item_bring_in(event_info);
39 =======
40    elm_gengrid_item_bring_in(event_info, ELM_GENGRID_ITEM_SCROLLTO_IN);
41 >>>>>>> remotes/origin/upstream
42 }
43
44 static void
45 _on_done(void        *data __UNUSED__,
46          Evas_Object *obj __UNUSED__,
47          void        *event_info __UNUSED__)
48 {
49    elm_exit();
50 }
51
52 static char *
53 _grid_label_get(void        *data,
54                 Evas_Object *obj __UNUSED__,
55                 const char  *part __UNUSED__)
56 {
57    int idx = (int)data;
58    return strdup(items[idx]);
59 }
60
61 Evas_Object *
62 _grid_content_get(void        *data __UNUSED__,
63                Evas_Object *obj,
64                const char  *part)
65 {
66    if (!strcmp(part, "elm.swallow.icon"))
67      {
68         char buf[PATH_MAX];
69         snprintf(buf, sizeof(buf), "%s/images/%s", PACKAGE_DATA_DIR,
70                  "sky_01.jpg");
71
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,
75                                          1);
76         evas_object_show(icon);
77         return icon;
78      }
79
80    return NULL;
81 }
82
83 /* ordering alphabetically */
84 static int
85 _index_icmp(const void *data1,
86             const void *data2)
87 {
88    const char *label1, *label2;
89
90    const Elm_Object_Item *index_it1 = data1;
91    const Elm_Object_Item *index_it2 = data2;
92
93    label1 = elm_index_item_letter_get(index_it1);
94    label2 = elm_index_item_letter_get(index_it2);
95
96    return strcasecmp(label1, label2);
97 }
98
99 int
100 elm_main(int    argc __UNUSED__,
101          char **argv __UNUSED__)
102 {
103    Evas_Object *win, *bg, *grid, *index;
104 <<<<<<< HEAD
105    Elm_Gengrid_Item *it;
106 =======
107    Elm_Object_Item *gg_it;
108 >>>>>>> remotes/origin/upstream
109    unsigned int i;
110
111    Elm_Gengrid_Item_Class gic;
112
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);
116
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);
121
122    grid = elm_gengrid_add(win);
123    elm_gengrid_item_size_set(grid, 150, 150);
124
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;
129    gic.func.del = NULL;
130
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);
134
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);
138
139    evas_object_show(index);
140
141    for (i = 0; i < (sizeof(items) / sizeof(items[0])); i++)
142      {
143         char buf[32];
144
145 <<<<<<< HEAD
146         it = elm_gengrid_item_append(grid, &gic, (void *)i, NULL, NULL);
147
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);
151 =======
152         gg_it = elm_gengrid_item_append(grid, &gic, (void *)i, NULL, NULL);
153
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
158      }
159
160    evas_object_smart_callback_add(index, "delay,changed", _index_changed, NULL);
161
162    evas_object_resize(win, 320, 300);
163    evas_object_show(win);
164
165    elm_index_active_set(index, EINA_TRUE);
166
167    elm_run();
168    return 0;
169 }
170
171 ELM_MAIN()