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

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

Here\textquotesingle{}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} *)(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);

\end{DoxyCodeInclude}


The order in which they\textquotesingle{}ll appear in the index, though, is {\bfseries alphabetical}, becase of 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\textquotesingle{}ll be index item(\hyperlink{group__General_ga13a0c231414b86e62f68afe3c6fb462b}{Elm\+\_\+\+Object\+\_\+\+Item})\textquotesingle{}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\textquotesingle{}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\textquotesingle{}s because of the the random order the items have in the grid itself.

This is how the example program\textquotesingle{}s window looks like\+:  
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth,height=\textheight/2,keepaspectratio=true]{screenshots/index_example_03}}
\end{DoxyImageNoCaption}


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