This example is also similar ot the \hyperlink{genlist_example_01}{Genlist -\/ basic usage}, but it demonstrates most of the item manipulation functions.

See the full source code at \hyperlink{genlist_example_04_c}{genlist\-\_\-example\-\_\-04.\-c}.

In this example, we also will use the concept of creating groups of items in the genlist. Each group of items is composed by a parent item (which will be the index of the group) and several children of this item. Thus, for the children, we declare a normal item class. But we also are going to declare a different item class for the group index (which in practice is another type of item in the genlist)\-:

 
\begin{DoxyCodeInclude}
\textcolor{keyword}{static} \textcolor{keywordtype}{char} *
\_group\_label\_get(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *part)
\{
   \textcolor{keywordtype}{char} buf[256];
   \textcolor{keywordtype}{int} i = (int)(\textcolor{keywordtype}{long})data;

   snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"Group %d (item #%d)"}, i / 7, i);

   \textcolor{keywordflow}{return} strdup(buf);
\}

\textcolor{keyword}{static} Evas\_Object *
\_group\_content\_get(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *part)
\{
   Evas\_Object *ic = elm_icon_add(obj);

   \textcolor{keywordflow}{if} (!strcmp(part, \textcolor{stringliteral}{"elm.swallow.icon"}))
     elm_icon_standard_set(ic, \textcolor{stringliteral}{"home"});

   evas\_object\_size\_hint\_aspect\_set(ic, EVAS\_ASPECT\_CONTROL\_VERTICAL, 1, 1);
   \textcolor{keywordflow}{return} ic;
\}

\end{DoxyCodeInclude}


We will add buttons to the window, where each button provides one functionality of the genlist item A\-P\-I. Each button will have a callback attached, that will really execute this functionality. An example of these callbacks is the next one, for the \hyperlink{group__Genlist_ga3f2ea12e5ab7122124d04c3454955911}{elm\-\_\-genlist\-\_\-item\-\_\-insert\-\_\-after()} function\-:


\begin{DoxyCodeInclude}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_insert\_after\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *o, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *list = data;
   Elm_Object_Item *glit = elm_genlist_selected_item_get(list);

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

   elm_genlist_item_insert_after(list, \_itc,
                                 (\textcolor{keywordtype}{void} *)(\textcolor{keywordtype}{long})nitems++, NULL,
                                 glit, ELM_GENLIST_ITEM_NONE,
                                 \_item\_sel\_cb, NULL);

\}

\end{DoxyCodeInclude}


If you want ot see the other button functions, look at the full source code link above.

Each button will be created with a function that already creates the button, add it to an elementary box, and attach the specified callback. This is the function that does it\-:


\begin{DoxyCodeInclude}
\textcolor{keyword}{static} Evas\_Object *
\_button\_add(Evas\_Object *list, Evas\_Object *box, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *label, Evas\_Smart\_Cb cb)
\{
   Evas\_Object *bt;

   bt = elm_button_add(elm_object_parent_widget_get(list));
   elm\_object\_text\_set(bt, label);
   elm_box_pack_end(box, bt);
   evas\_object\_show(bt);

   \textcolor{keywordflow}{if} (cb)
     evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, cb, list);

   \textcolor{keywordflow}{return} bt;
\}

\end{DoxyCodeInclude}


In our {\ttfamily elm\-\_\-main} function, besides the code for setting up the window, box and background, we also initialize our two item classes\-:


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


This example uses a different style for the items, the {\itshape double\-\_\-label}, which provides a text field for the item text, and another text field for a subtext.

For the group index we use the {\itshape group\-\_\-index} style, which provides a different appearance, helping to identify the end of a group and beginning of another one.

Now, after the code for creating the list, setting up the box and other stuff, let's add the buttons with their respective callbacks\-:


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


The main code for adding items to the list is a bit more complex than the one from the previous examples. We check if each item is multiple of 7, and if so, they are group indexes (thus each group has 6 elements by default, in this example)\-:


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Then we also check for specific items, and add callbacks to them on the respective buttons, so we can show, bring in, etc.\-:


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Once you understand the code from the \hyperlink{genlist_example_01}{Genlist -\/ basic usage}, it should be easy to understand this one too. Look at the full code, and also try to play a bit with the buttons, adding items, bringing them to the viewport, and so.

The example will look like this when running\-:

 
\begin{DoxyImage}
\includegraphics{screenshots/genlist_example_04}
\caption{width=}
\end{DoxyImage}
 