
\begin{DoxyCodeInclude}

\textcolor{preprocessor}{#include <Elementary.h>}

\textcolor{keyword}{static} \textcolor{keyword}{const} \textcolor{keywordtype}{char} *items[] =
\{
   \textcolor{stringliteral}{"Judith"},
   \textcolor{stringliteral}{"Paulina"},
   \textcolor{stringliteral}{"Cathy"},
   \textcolor{stringliteral}{"Vendella"},
   \textcolor{stringliteral}{"Naomi"},
   \textcolor{stringliteral}{"Ashley"},
   \textcolor{stringliteral}{"Stacey"},
   \textcolor{stringliteral}{"Gail"}
\};

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_index\_changed(\textcolor{keywordtype}{void}        *data,
               Evas\_Object *obj,
               \textcolor{keywordtype}{void}        *event\_info)
\{
   Elm_Object_Item *item = elm_object_item_data_get(event\_info);
   elm_gengrid_item_bring_in(item, ELM_GENGRID_ITEM_SCROLLTO_IN);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{char} *
\_grid\_label\_get(\textcolor{keywordtype}{void}        *data,
                Evas\_Object *obj,
                \textcolor{keyword}{const} \textcolor{keywordtype}{char}  *part)
\{
   \textcolor{keywordtype}{int} idx = (int)(uintptr\_t)data;
   \textcolor{keywordflow}{return} strdup(items[idx]);
\}

Evas\_Object *
\_grid\_content\_get(\textcolor{keywordtype}{void}        *data,
                  Evas\_Object *obj,
                  \textcolor{keyword}{const} \textcolor{keywordtype}{char}  *part)
\{
   \textcolor{keywordflow}{if} (!strcmp(part, \textcolor{stringliteral}{"elm.swallow.icon"}))
     \{
        \textcolor{keywordtype}{char} buf[PATH\_MAX];
        snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"%s/images/%s"}, elm_app_data_dir_get(),
                 \textcolor{stringliteral}{"sky\_01.jpg"});

        Evas\_Object *icon = elm_bg_add(obj);
        elm_bg_file_set(icon, buf, NULL);
        evas\_object\_size\_hint\_aspect\_set(icon, EVAS\_ASPECT\_CONTROL\_VERTICAL, 1,
                                         1);
        evas\_object\_show(icon);
        \textcolor{keywordflow}{return} icon;
     \}

   \textcolor{keywordflow}{return} NULL;
\}

\textcolor{comment}{/* ordering alphabetically */}
\textcolor{keyword}{static} \textcolor{keywordtype}{int}
\_index\_icmp(\textcolor{keyword}{const} \textcolor{keywordtype}{void} *data1,
            \textcolor{keyword}{const} \textcolor{keywordtype}{void} *data2)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *label1, *label2;

   \textcolor{keyword}{const} Elm_Object_Item *index\_it1 = data1;
   \textcolor{keyword}{const} Elm_Object_Item *index\_it2 = data2;

   label1 = elm_index_item_letter_get(index\_it1);
   label2 = elm_index_item_letter_get(index\_it2);

   \textcolor{keywordflow}{return} strcasecmp(label1, label2);
\}

EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int}    argc,
         \textcolor{keywordtype}{char} **argv)
\{
   Evas\_Object *win, *grid, *idx;
   Elm_Object_Item *gg\_it;
   \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} i;

   Elm_Gengrid_Item_Class gic;

   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
   elm_app_info_set(elm\_main, \textcolor{stringliteral}{"elementary"}, \textcolor{stringliteral}{"images"});

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"index"}, \textcolor{stringliteral}{"Index Example"});
   elm_win_autodel_set(win, EINA\_TRUE);

   grid = elm_gengrid_add(win);
   elm_gengrid_item_size_set(grid, 150, 150);

   gic.item\_style = \textcolor{stringliteral}{"default"};
   gic.func.text\_get = \_grid\_label\_get;
   gic.func.content\_get = \_grid\_content\_get;
   gic.func.state\_get = NULL;
   gic.func.del = NULL;

   evas\_object\_size\_hint\_weight\_set(grid, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_win_resize_object_add(win, grid);
   evas\_object\_show(grid);

   idx = elm_index_add(win);
   evas\_object\_size\_hint\_weight\_set(idx, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_win_resize_object_add(win, idx);
   evas\_object\_show(idx);

   \textcolor{keywordflow}{for} (i = 0; i < (\textcolor{keyword}{sizeof}(items) / \textcolor{keyword}{sizeof}(items[0])); i++)
     \{
        \textcolor{keywordtype}{char} buf[32];

        gg\_it = elm_gengrid_item_append(grid, &gic, (\textcolor{keywordtype}{void} *)(uintptr\_t)i, NULL, NULL);

        \textcolor{comment}{/* indexing by first letters */}
        snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"%c"}, items[i][0]);
        elm_index_item_sorted_insert(idx, buf, NULL, gg\_it, \_index\_icmp, NULL);
     \}

   evas\_object\_smart\_callback\_add(idx, \textcolor{stringliteral}{"delay,changed"}, \_index\_changed, NULL);

   elm_index_autohide_disabled_set(idx, EINA\_FALSE);
   elm_index_level_go(idx, 0);

   evas\_object\_resize(win, 320, 300);
   evas\_object\_show(win);

   elm_run();

   \textcolor{keywordflow}{return} 0;
\}
ELM_MAIN()
\end{DoxyCodeInclude}
 