This example is also similar ot the \mbox{\hyperlink{genlist_example_01}{Genlist -\/ basic usage}}, but it demonstrates most of the item manipulation functions. See the full source code at \mbox{\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}{0}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{char} *}
\DoxyCodeLine{\_group\_label\_get(\textcolor{keywordtype}{void} *data, \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *obj \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *part \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keywordtype}{char} buf[256];}
\DoxyCodeLine{   \textcolor{keywordtype}{int} i = (int)(uintptr\_t)data;}
\DoxyCodeLine{}
\DoxyCodeLine{   snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"Group \%d (item \#\%d)"}, i / 7, i);}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} strdup(buf);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *}
\DoxyCodeLine{\_group\_content\_get(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *obj, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *part)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *ic = \mbox{\hyperlink{group__Elm__Icon_ga5739728c1209f90422cf65a778a16502}{elm\_icon\_add}}(obj);}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (!strcmp(part, \textcolor{stringliteral}{"elm.swallow.icon"}))}
\DoxyCodeLine{     \mbox{\hyperlink{group__Elm__Icon_gab764b4c6c90543f254c013eff6a6db66}{elm\_icon\_standard\_set}}(ic, \textcolor{stringliteral}{"home"});}
\DoxyCodeLine{}
\DoxyCodeLine{   evas\_object\_size\_hint\_aspect\_set(ic, \mbox{\hyperlink{Evas__Common_8h_ac68b577b7c0b79c356f01926e4a8099faeaf1e019f2dbfbbc2da9ab1fe1f175f6}{EVAS\_ASPECT\_CONTROL\_VERTICAL}}, 1, 1);}
\DoxyCodeLine{   \textcolor{keywordflow}{return} ic;}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}


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


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_insert\_after\_cb(\textcolor{keywordtype}{void} *data, \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *o \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{void} *event\_info \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *list = data;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_ga13a0c231414b86e62f68afe3c6fb462b}{Elm\_Object\_Item}} *glit = elm\_genlist\_selected\_item\_get(list);}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (!glit) \textcolor{keywordflow}{return};}
\DoxyCodeLine{}
\DoxyCodeLine{   elm\_genlist\_item\_insert\_after(list, \_itc,}
\DoxyCodeLine{                                 (\textcolor{keywordtype}{void} *)(uintptr\_t)nitems++, NULL,}
\DoxyCodeLine{                                 glit, \mbox{\hyperlink{group__Elm__General_gga9727d3b92987319ac981247bc196bd0fa1ffe76fc4e7fd2bb40e47290c01ac0df}{ELM\_GENLIST\_ITEM\_NONE}},}
\DoxyCodeLine{                                 \_item\_sel\_cb, NULL);}
\DoxyCodeLine{}
\DoxyCodeLine{\}}

\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}{0}
\DoxyCodeLine{\textcolor{keyword}{static} \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *}
\DoxyCodeLine{\_button\_add(\mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *list, \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *box, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *label, \mbox{\hyperlink{Evas__Common_8h_afbde245aa36db11d8280b266235c25b2}{Evas\_Smart\_Cb}} cb)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *bt;}
\DoxyCodeLine{}
\DoxyCodeLine{   bt = \mbox{\hyperlink{group__Elm__Button_ga0021b9d86d822367035843ed18bc6ea9}{elm\_button\_add}}(\mbox{\hyperlink{group__Elm__WidgetNavigation_ga0b5f83c403948f1418e434f3ed94973f}{elm\_object\_parent\_widget\_get}}(list));}
\DoxyCodeLine{   elm\_object\_text\_set(bt, label);}
\DoxyCodeLine{   elm\_box\_pack\_end(box, bt);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(bt);}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (cb)}
\DoxyCodeLine{     \mbox{\hyperlink{group__Evas__Smart__Object__Group_ga18a8b179f94d21b2b09e19db11741061}{evas\_object\_smart\_callback\_add}}(bt, \textcolor{stringliteral}{"clicked"}, cb, list);}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} bt;}
\DoxyCodeLine{\}}

\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}{0}

\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\textquotesingle{}s add the buttons with their respective callbacks\+:


\begin{DoxyCodeInclude}{0}

\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}{0}

\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}{0}

\end{DoxyCodeInclude}


Once you understand the code from the \mbox{\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{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth]{screenshots/genlist_example_04}}
\end{DoxyImageNoCaption}
 