\chapter{Genlist -\/ items manipulation}
\hypertarget{genlist_example_04}{}\label{genlist_example_04}\index{Genlist -\/ items manipulation@{Genlist -\/ items manipulation}}
This example is also similar ot the \doxysectlink{genlist_example_01}{Genlist -\/ basic usage}{0}, but it demonstrates most of the item manipulation functions. See the full source code at \doxysectlink{genlist_example_04_c}{genlist\+\_\+example\+\_\+04.\+c}{0}.

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,\ 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}\ Evas\_Object\ *}
\DoxyCodeLine{\_group\_content\_get(\textcolor{keywordtype}{void}\ *data\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},\ Evas\_Object\ *obj,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *part)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ Evas\_Object\ *ic\ =\ \mbox{\hyperlink{group__Elm__Icon_gac369f2d67be417e5cff81e8f001ff326}{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{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gab09d6bf93b5435230b41ceca2abe783a}{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 API. Each button will have a callback attached, that will really execute this functionality. An example of these callbacks is the next one, for the \doxylink{group__Elm__Genlist__Group_gaeacc50b0856eece0534ce6f6094119e5}{elm\+\_\+genlist\+\_\+item\+\_\+insert\+\_\+after()} function\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_insert\_after\_cb(\textcolor{keywordtype}{void}\ *data,\ 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{\ \ \ Evas\_Object\ *list\ =\ data;}
\DoxyCodeLine{\ \ \ Elm\_Object\_Item\ *glit\ =\ \mbox{\hyperlink{group__Elm__Genlist__Group_ga2dbee1d6bf7a36751d288cf95e1e6eb0}{elm\_genlist\_selected\_item\_get}}(list);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!glit)\ \textcolor{keywordflow}{return};}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Genlist__Group_gaeacc50b0856eece0534ce6f6094119e5}{elm\_genlist\_item\_insert\_after}}(list,\ \_itc,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (\textcolor{keywordtype}{void}\ *)(uintptr\_t)nitems++,\ NULL,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ glit,\ \mbox{\hyperlink{group__Elm__Genlist__Item__Group_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}\ Evas\_Object\ *}
\DoxyCodeLine{\_button\_add(Evas\_Object\ *list,\ Evas\_Object\ *box,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *label,\ \mbox{\hyperlink{Evas__Common_8h_afbde245aa36db11d8280b266235c25b2}{Evas\_Smart\_Cb}}\ cb)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ Evas\_Object\ *bt;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ bt\ =\ \mbox{\hyperlink{group__Elm__Button_gaf5caf46d74c4e122a18da323935d25e4}{elm\_button\_add}}(\mbox{\hyperlink{group__Elm__WidgetNavigation_ga958eee73092bf0da7ba0f422519fdb72}{elm\_object\_parent\_widget\_get}}(list));}
\DoxyCodeLine{\ \ \ elm\_object\_text\_set(bt,\ label);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Box__Group_ga66a10dd861578521af2ab7b8c2ca65c5}{elm\_box\_pack\_end}}(box,\ bt);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(bt);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (cb)}
\DoxyCodeLine{\ \ \ \ \ \mbox{\hyperlink{group__Evas__Smart__Object__Group_gac12dd6655f488cc47ce6cf00eb7d12b2}{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 \doxysectlink{genlist_example_01}{Genlist -\/ basic usage}{0}, 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}
 