This code places an Elementary index widget on a window, which also has a very long list of arbitrary strings on it.

The list is sorted alphabetically and the index will be used to index the first items of each set of strings beginning with an alphabet letter.

Below the list are some buttons, which are there just to exercise some index widget\textquotesingle{}s A\+PI.

Here\textquotesingle{}s how we instantiate it\+:  
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}
 where we\textquotesingle{}re showing also the list being created. Note that we issue \hyperlink{group__Elm__Win_gacdfbf68cb25f78e2884c2886ecb829dd}{elm\+\_\+win\+\_\+resize\+\_\+object\+\_\+add()} on the index, so that it\textquotesingle{}s set to have the whole window as its container. Then, we have to populate both list and index widgets\+:  
\begin{DoxyCodeInclude}
   \textcolor{keywordflow}{for} (i = 0; i < (\textcolor{keyword}{sizeof}(dict) / \textcolor{keyword}{sizeof}(dict[0])); i++)
     \{
        lit = elm_list_item_append(list, dict[i], NULL, NULL, NULL, NULL);

        \textcolor{keywordflow}{if} (curr != dict[i][0])
          \{
             Elm_Object_Item *index\_it;
             \textcolor{keywordtype}{char} buf[32];

             curr = dict[i][0];
             \textcolor{comment}{/* indexing by first letters */}

             snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"%c"}, curr);
             index\_it = elm_index_item_append(\textcolor{keywordtype}{id}, buf, NULL, lit);

             \textcolor{comment}{/* this is here just to demostrate the API call */}
             (void)elm_index_item_find(\textcolor{keywordtype}{id}, lit);
             assert(elm_index_item_find(\textcolor{keywordtype}{id}, lit) == index\_it);

             elm\_object\_item\_del\_cb\_set(index\_it, \_index\_item\_del);
          \}
     \}

\end{DoxyCodeInclude}


The strings populating the list come from a file  
\begin{DoxyCodeInclude}
\textcolor{keyword}{static} \textcolor{keyword}{const} \textcolor{keywordtype}{char} *dict[] = \(\backslash\)
\{
\textcolor{preprocessor}{#include "dict.txt"}
\};

\end{DoxyCodeInclude}


We use the {\ttfamily curr} char variable to hold the last initial letter seen on that ordered list of strings, so that we\textquotesingle{}re able to have an index item pointing to each list item starting a new letter \char`\"{}section\char`\"{}. Note that our index item data pointers will be the list item handles. We are also setting a callback function to index items deletion events\+:  
\begin{DoxyCodeInclude}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_index\_item\_del(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   fprintf(stdout, \textcolor{stringliteral}{"Deleting index node (%s). Comparing index "}
           \textcolor{stringliteral}{"item data reported via callback with the one returned by "}
           \textcolor{stringliteral}{"index's API on items: %s.\(\backslash\)n"},
           elm\_index\_item\_letter\_get(event\_info),
           data == elm_object_item_data_get(event\_info) ? \textcolor{stringliteral}{"OK"} :
           \textcolor{stringliteral}{"FAIL, something went wrong"});
\}

\end{DoxyCodeInclude}


There, we show you that the {\ttfamily event\+\_\+info} pointer will contain the item in question\textquotesingle{}s data, i.\+e., a given list item\textquotesingle{}s pointer. Because item data is also returned in the {\ttfamily data} argument on {\ttfamily Evas\+\_\+\+Smart\+\_\+\+Cb} functions, those two pointers must have the same values. On this deletion callback, we\textquotesingle{}re deleting the referred list item too, just to exemplify that anything could be done there.

Next, we hook to two smart events of the index object\+:  
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}
  
\begin{DoxyCodeInclude}
\textcolor{comment}{/* "delay,changed" hook */}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_index\_changed(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   elm\_list\_item\_bring\_in(elm_object_item_data_get(event\_info));
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_index\_selected(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *lit = event\_info;

   fprintf(stdout, \textcolor{stringliteral}{"New index item selected. Comparing item reported"}
           \textcolor{stringliteral}{" via callback with the selection returned by the API: "}
           \textcolor{stringliteral}{"%s.\(\backslash\)n"}, lit == elm_index_selected_item_get(obj, 0) ? \textcolor{stringliteral}{"OK"} :
           \textcolor{stringliteral}{"FAIL, something went wrong"});
\}

\end{DoxyCodeInclude}


Check that, whenever one holds the mouse pressed over a given index letter for some time, the list beneath it will roll down to the item pointed to by that index item. When one releases the mouse button, the second callback takes place. There, we check that the reported item data, on {\ttfamily event\+\_\+info}, is the same reported by \hyperlink{group__Elm__Index_gada78a8c8a3908f9ce8e97c3aa03e0db0}{elm\+\_\+index\+\_\+selected\+\_\+item\+\_\+get()}, which gives the last selection\textquotesingle{}s data on the index widget.

The first of the three buttons that follow will call \hyperlink{group__Elm__Index_ga6569179b38d11fb5fb1286815cf846fb}{elm\+\_\+index\+\_\+autohide\+\_\+disabled\+\_\+set()}, thus showing the index automatically for you, if it\textquotesingle{}s not already visible, what is checked with \hyperlink{group__Elm__Index_ga4b1a080a5ddba56e53d16f97cdcfb3a1}{elm\+\_\+index\+\_\+autohide\+\_\+disabled\+\_\+get()}. The second button will exercise {\bfseries deletion} of index item objects, by the following code\+:  
\begin{DoxyCodeInclude}
\textcolor{comment}{/* delete an index item */}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_item\_del(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *it = elm_index_selected_item_get(data, 0);

   \textcolor{keywordflow}{if} (!it) \textcolor{keywordflow}{return};

   fprintf(stdout, \textcolor{stringliteral}{"Deleting last selected index item, which had letter"}
           \textcolor{stringliteral}{" %s (pointing to %p)\(\backslash\)n"}, elm\_index\_item\_letter\_get(it),
           elm_object_item_data_get(it));

   elm\_object\_item\_del(it);
   elm_index_level_go(data, 0);
\}

\end{DoxyCodeInclude}


It will get the last index item selected\textquotesingle{}s data and find the respective index item handle(\hyperlink{group__Elm__General_ga13a0c231414b86e62f68afe3c6fb462b}{Elm\+\_\+\+Object\+\_\+\+Item}) with \hyperlink{group__Elm__Index_ga2a9bccce5e3aa9a6928fb9aa74bf6579}{elm\+\_\+index\+\_\+item\+\_\+find()}. We need the latter to query the indexing letter string from, with elm\+\_\+index\+\_\+item\+\_\+letter\+\_\+get(). Next, comes the delition, itself, which will also trigger the {\ttfamily \+\_\+index\+\_\+item\+\_\+del} callback function, as said above.

The third button, finally, will exercise \hyperlink{group__Elm__Index_ga9c0c1ff500522b62a674b36beafe7a19}{elm\+\_\+index\+\_\+item\+\_\+clear()}, which will delete {\bfseries all} of the index\textquotesingle{}s items.

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


When it\textquotesingle{}s shown, it\textquotesingle{}s like the following figure\+:  
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth,height=\textheight/2,keepaspectratio=true]{screenshots/index_example_01}}
\end{DoxyImageNoCaption}


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