This code places an Elementary index widget on a window, indexing grid items.

The items are placed so that their labels {\bfseries don't} follow any order, but the index itself is ordered (through \hyperlink{group__Index_ga8164b9ce017161ec2431481ea54d198d}{elm\-\_\-index\-\_\-item\-\_\-sorted\-\_\-insert()}). This is a complement to to \hyperlink{index_example_01}{the first example on indexes}.

Here's the list of item labels to be used on the grid (in that order)\-:  
\begin{DoxyCodeInclude}
\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"}
\};

\end{DoxyCodeInclude}


In the interesting part of the code, here, we first instantiate the grid (more on grids on their examples) and, after creating our index, for each grid item we also create an index one to reference it\-:  
\begin{DoxyCodeInclude}
   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} *)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);

\end{DoxyCodeInclude}


The order in which they'll appear in the index, though, is {\bfseries alphabetical}, becase of \hyperlink{group__Index_ga8164b9ce017161ec2431481ea54d198d}{elm\-\_\-index\-\_\-item\-\_\-sorted\-\_\-insert()} usage together with the comparing function, where we take the letters of each index item to base our ordering on. The parameters on {\ttfamily \-\_\-index\-\_\-cmp} have to be declared as void pointers because of the {\ttfamily Eina\-\_\-\-Compare\-\_\-\-Cb} prototype requisition, but in this case we know they'll be index item(\hyperlink{group__General_ga13a0c231414b86e62f68afe3c6fb462b}{Elm\-\_\-\-Object\-\_\-\-Item})'s\-:  
\begin{DoxyCodeInclude}
\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);
\}

\end{DoxyCodeInclude}


The last interesting bit is the callback in the {\ttfamily \char`\"{}delay,changed\char`\"{}} smart event, which will bring the given grid item to the grid's visible area\-:  
\begin{DoxyCodeInclude}
\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);
\}

\end{DoxyCodeInclude}


Note how the grid will move kind of randomly while you move your mouse pointer held over the index from top to bottom -- that's because of the the random order the items have in the grid itself.

This is how the example program's window looks like\-:  
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics{screenshots/index_example_03}}
\end{DoxyImageNoCaption}


See the full \hyperlink{index_example_02_8c-example}{source code} for this example. 