This example creates a simple genlist with a small number of items and a callback that is called whenever an item is selected.

All the properties of this genlist are the default ones. The full code for this example can be seen at \mbox{\hyperlink{genlist_example_01_c}{genlist\+\_\+example\+\_\+01.\+c}}.

For the simplest list that you plan to create, it\textquotesingle{}s necessary to define some of the basic functions that are used for creating each list item, and associating them with the \char`\"{}item class\char`\"{} for that list. The item class is just an struct that contains pointers to the specific list item functions that are common to all the items of the list.

Let\textquotesingle{}s show it by example. Our item class is declared globally and static as it will be the only item class that we need (we are just creating one list)\+:

 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{struct__Elm__Gen__Item__Class}{Elm\_Genlist\_Item\_Class}}\ *\_itc\ =\ NULL;}

\end{DoxyCodeInclude}
 This item class will be used for every item that we create. The only functions that we are going to set are {\ttfamily label\+\_\+get} and {\ttfamily icon\+\_\+get}. As the name suggests, they are used by the genlist to generate the label for the respective item, and to generate icon(s) to it too. Both the label and icon get functions can be called more than once for each item, with different {\ttfamily part} parameters, which represent where in the theme of the item that label or icon is going to be set.

The default theme for the genlist contains only one area for label, and two areas for icon (\char`\"{}elm.\+swallow.\+icon\char`\"{} and \char`\"{}elm.\+swallow.\+end\char`\"{}). Since we just want to set the first icon (that will be at the left side of the label), we compare the part name given with \char`\"{}elm.\+swallow.\+icon\char`\"{}. Notice that the {\ttfamily label\+\_\+get} function must return a strduped string, that will be freed later automatically by the list. Here\textquotesingle{}s the code for {\ttfamily label\+\_\+get} and {\ttfamily icon\+\_\+get\+:} 


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{char}\ *}
\DoxyCodeLine{\_item\_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{\ \ \ snprintf(buf,\ \textcolor{keyword}{sizeof}(buf),\ \textcolor{stringliteral}{"{}Item\ \#\ \%i"{}},\ (\textcolor{keywordtype}{int})(uintptr\_t)data);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ strdup(buf);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}}\ *}
\DoxyCodeLine{\_item\_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_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}{"{}clock"{}});}
\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{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}

\end{DoxyCodeInclude}
 We will also provide a function that will be called whenever an item is selected in the genlist. However, this function is not part of the item class, it will be passed for each item being added to the genlist explicitly. Notice the similarity of the function signature with those used by {\ttfamily evas\+\_\+object\+\_\+smart\+\_\+callback\+\_\+add\+:} 


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\_item\_sel\_cb(\textcolor{keywordtype}{void}\ *data,\ \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}}\ *obj,\ \textcolor{keywordtype}{void}\ *event\_info)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}sel\ item\ data\ [\%p]\ on\ genlist\ obj\ [\%p],\ item\ pointer\ [\%p]\(\backslash\)n"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ data,\ obj,\ event\_info);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 Now let\textquotesingle{}s show the code used for really creating the list. Skipping boilerplate code used for creating a window and background, the first piece of code specific to our genlist example is setting the pointer functions of the item class to our above defined functions\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!\_itc)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \_itc\ =\ \mbox{\hyperlink{group__Elm__Genlist__Group_gaddc052cd4804afe97c2c6a4ac68eb8a4}{elm\_genlist\_item\_class\_new}}();}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \_itc-\/>\mbox{\hyperlink{struct__Elm__Gen__Item__Class_aa611ea90d00c3e0f9abe25ff56fc420f}{item\_style}}\ =\ \textcolor{stringliteral}{"{}default"{}};}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \_itc-\/>\mbox{\hyperlink{struct__Elm__Gen__Item__Class_a457622de444f6539822387321996418d}{func}}.\mbox{\hyperlink{struct__Elm__Gen__Item__Class__Functions_ae7a3a244fab9e126b3ac264615535c41}{text\_get}}\ =\ \_item\_label\_get;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \_itc-\/>\mbox{\hyperlink{struct__Elm__Gen__Item__Class_a457622de444f6539822387321996418d}{func}}.\mbox{\hyperlink{struct__Elm__Gen__Item__Class__Functions_a796220b356374cd6395bcd2c3668f8d8}{content\_get}}\ =\ \_item\_content\_get;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \_itc-\/>\mbox{\hyperlink{struct__Elm__Gen__Item__Class_a457622de444f6539822387321996418d}{func}}.\mbox{\hyperlink{struct__Elm__Gen__Item__Class__Functions_a23a335ae22003578adc536313f21e6e5}{state\_get}}\ =\ NULL;}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \_itc-\/>\mbox{\hyperlink{struct__Elm__Gen__Item__Class_a457622de444f6539822387321996418d}{func}}.\mbox{\hyperlink{struct__Elm__Gen__Item__Class__Functions_a29069fe3b82c13e822a3ce515e12dac0}{del}}\ =\ NULL;}

\end{DoxyCodeInclude}
 Notice that we also choose to use the \char`\"{}default\char`\"{} style for our genlist items. Another interesting point is that {\ttfamily state\+\_\+get} and {\ttfamily del} are set to {\ttfamily NULL}, since we don\textquotesingle{}t need these functions now. {\ttfamily del} doesn\textquotesingle{}t need to be used because we don\textquotesingle{}t add any data that must be freed to our items, and {\ttfamily state\+\_\+get} is also not used since all of our items are the same and don\textquotesingle{}t need to have different states to be used for each item. Finally we create our list\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ list\ =\ \mbox{\hyperlink{group__Elm__Genlist__Group_ga450dfb84aa3e9c092b9c003db1e1c47f}{elm\_genlist\_add}}(win);}

\end{DoxyCodeInclude}
 Now we append several items to the list, and for all of them we need to give the list pointer, a pointer to the item class, the data that will be used with that item, a pointer to the parent of this item if it is in a group type list (this is not the case so we pass {\ttfamily NULL}), possible flags for this item, the callback for when the item is selected, and the data pointer that will be given to the selected callback.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{for}\ (i\ =\ 0;\ i\ <\ N\_ITEMS;\ i++)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Elm__Genlist__Group_ga869214cf76896bc311c9464ad21126e0}{elm\_genlist\_item\_append}}(list,\ \_itc,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (\textcolor{keywordtype}{void}\ *)(uintptr\_t)i,\ NULL,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Elm__Genlist__Item__Group_gga9727d3b92987319ac981247bc196bd0fa1ffe76fc4e7fd2bb40e47290c01ac0df}{ELM\_GENLIST\_ITEM\_NONE}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_item\_sel\_cb,\ NULL);}
\DoxyCodeLine{\ \ \ \ \ \}}

\end{DoxyCodeInclude}
 The rest of the code is also common to all the other examples, so it will be omitted here (look at the full source code link above if you need it).

You can try to play with this example, and see the selected callback being called whenever an item is clicked. It also already has some features enabled by default, like vertical bounce animation when reaching the end of the list, automatically visible/invisible scrollbar, etc. Look at the \mbox{\hyperlink{genlist_example_02}{Genlist -\/ list setup functions}} to see an example of setting these properties to the list.

The current example will look like this when running\+:

 
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth]{screenshots/genlist_example_01}}
\end{DoxyImageNoCaption}
 