This example is very similar to the \mbox{\hyperlink{genlist_example_01}{Genlist -\/ basic usage}}, but it fetch most of the properties of the genlist and displays them on startup (thus getting the default value for them) and then set them to some other values, to show how to use that A\+PI. The full source code is at \mbox{\hyperlink{genlist_example_02_c}{genlist\+\_\+example\+\_\+02.\+c}}.

Considering that the base code for instantiating a genlist was already described in the previous example, we are going to focus on the new code.

Just a small difference for the {\ttfamily \+\_\+item\+\_\+label\+\_\+get} function, we are going to store the time that this function was called. This is the \char`\"{}realized\char`\"{} time, the time when the visual representation of this item was created. This is the code for the {\ttfamily label\+\_\+get} function\+:

 
\begin{DoxyCodeInclude}{0}
\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{   time\_t t = (time\_t)\mbox{\hyperlink{group__Ecore__Time__Group_ga0b8030aa39eb3701b6b30816ee9c45df}{ecore\_time\_unix\_get}}();}
\DoxyCodeLine{   \textcolor{keywordtype}{char} buf[256];}
\DoxyCodeLine{   \textcolor{keywordtype}{int} i = (int)(uintptr\_t)data;}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (i \% 2)}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        \textcolor{keywordtype}{int} n;}
\DoxyCodeLine{        snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"Very Long Item \# \%i -\/ realized at \%s"}, i, ctime(\&t));}
\DoxyCodeLine{        n = strlen(buf);}
\DoxyCodeLine{        buf[n -\/ 1] = \textcolor{charliteral}{'\(\backslash\)0'};}
\DoxyCodeLine{     \}}
\DoxyCodeLine{   \textcolor{keywordflow}{else}}
\DoxyCodeLine{     snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"short item \# \%i"}, i);}
\DoxyCodeLine{   \textcolor{keywordflow}{return} strdup(buf);}

\end{DoxyCodeInclude}


Now let\textquotesingle{}s go to the list creation and setup. First, just after creating the list, we get most of the default properties from it, and print them on the console\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{   list = \mbox{\hyperlink{group__Elm__Genlist_ga8845cb5425deadec54558b7badd16a6f}{elm\_genlist\_add}}(win);}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (!\_itc)}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        \_itc = \mbox{\hyperlink{group__Elm__Genlist_gabb8088ee2d6660c5d934ce3153493eb1}{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;}
\DoxyCodeLine{     \}}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}} hbounce, vbounce, always, no\_sel;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Scroller_gae4532876fde43d8d37fc9440a1e36a84}{Elm\_Scroller\_Policy}} hp, vp;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_ga8e4aa5aa238e472f33813babfff0d56f}{Elm\_Object\_Select\_Mode}} sel\_mode;}
\DoxyCodeLine{}
\DoxyCodeLine{   always = no\_sel = \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}};}
\DoxyCodeLine{   sel\_mode = elm\_genlist\_select\_mode\_get(list);}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (sel\_mode == \mbox{\hyperlink{group__Elm__General_gga8e4aa5aa238e472f33813babfff0d56fab3cfbf566fdbea2079f3081969f0c59c}{ELM\_OBJECT\_SELECT\_MODE\_ALWAYS}})}
\DoxyCodeLine{     always = \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};}
\DoxyCodeLine{   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (sel\_mode == \mbox{\hyperlink{group__Elm__General_gga8e4aa5aa238e472f33813babfff0d56fa0f0e25088d651a379b4eb8b915d2e13f}{ELM\_OBJECT\_SELECT\_MODE\_NONE}})}
\DoxyCodeLine{     no\_sel = \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};}
\DoxyCodeLine{}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"default values:\(\backslash\)n"});}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"always select: \%d\(\backslash\)n"}, always);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Scroller_gae74537077c42537037834d4d4bdae634}{elm\_scroller\_bounce\_get}}(list, \&hbounce, \&vbounce);}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"bounce -\/ horizontal: \%d, vertical: \%d\(\backslash\)n"}, hbounce, vbounce);}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"homogeneous: \%d\(\backslash\)n"}, elm\_genlist\_homogeneous\_get(list));}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"horizontal mode: \%d\(\backslash\)n"}, elm\_genlist\_mode\_get(list));}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"longpress timeout: \%0.3f\(\backslash\)n"},}
\DoxyCodeLine{          elm\_genlist\_longpress\_timeout\_get(list));}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"multi selection: \%d\(\backslash\)n"}, elm\_genlist\_multi\_select\_get(list));}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"no selection mode: \%d\(\backslash\)n"}, no\_sel);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Scroller_gae5d37ebf0a5540326b2b56ae41f24c97}{elm\_scroller\_policy\_get}}(list, \&hp, \&vp);}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"scroller policy -\/ horizontal: \%d, vertical: \%d\(\backslash\)n"}, hp, vp);}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"block count: \%d\(\backslash\)n"}, elm\_genlist\_block\_count\_get(list));}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"\(\backslash\)n"});}

\end{DoxyCodeInclude}


We are going to change some of the properties of our list.

There\textquotesingle{}s no need to call the selected callback at every click, just when the selected item changes, thus we call elm\+\_\+genlist\+\_\+select\+\_\+mode\+\_\+set() with E\+L\+M\+\_\+\+O\+B\+J\+E\+C\+T\+\_\+\+S\+E\+L\+E\+C\+T\+\_\+\+M\+O\+D\+E\+\_\+\+A\+L\+W\+A\+YS.

For this list we don\textquotesingle{}t want bounce animations at all, so we set both the horizontal bounce and the vertical bounce to false with \mbox{\hyperlink{group__Elm__Genlist_gafb9732835a97e9a781e1b680aee06844}{elm\+\_\+genlist\+\_\+bounce\+\_\+set()}}.

We also want our list to compress items if they are wider than the list width (thus we call elm\+\_\+genlist\+\_\+mode\+\_\+set(obj, E\+L\+M\+\_\+\+L\+I\+S\+T\+\_\+\+C\+O\+M\+P\+R\+E\+S\+S).

The items have different width, so they are not homogeneous\+: elm\+\_\+genlist\+\_\+homogeneous\+\_\+set() is set to false.

Since the compress mode is active, the call to elm\+\_\+genlist\+\_\+mode\+\_\+set() doesn\textquotesingle{}t make difference, but the current option would make the list to have at least the width of the largest item.

This list will support multiple selection, so we call elm\+\_\+genlist\+\_\+multi\+\_\+select\+\_\+set() on it.

The option elm\+\_\+genlist\+\_\+mode\+\_\+set() would allow text block to wrap lines if the Edje part is configured with \char`\"{}text.\+min\+: 0 1\char`\"{}, for example. But since we are compressing the elements to the width of the list, this option wouldn\textquotesingle{}t take any effect.

We want the vertical scrollbar to be always displayed, and the orizontal one to never be displayed, and set this with \mbox{\hyperlink{group__Elm__Genlist_ga2336370da936f94b6b161093a2e62516}{elm\+\_\+genlist\+\_\+scroller\+\_\+policy\+\_\+set()}}.

The timeout to consider a longpress is set to half of a second with elm\+\_\+genlist\+\_\+longpress\+\_\+timeout\+\_\+set().

We also change the block count to a smaller value, but that should have not impact on performance since the number of visible items is too small. We just increase the granularity of the block count (setting it to have at most 4 items).


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Scroller_gae69101dbdb089598ca790c73bd9d7a42}{elm\_scroller\_bounce\_set}}(list, \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}}, \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}});}
\DoxyCodeLine{   elm\_genlist\_homogeneous\_set(list, \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}});}
\DoxyCodeLine{   elm\_genlist\_mode\_set(list, \mbox{\hyperlink{group__Elm__List_ggad05499f0b0c907a953ef8650823ae428a9d8b034ab975f9a14d542069271408a1}{ELM\_LIST\_LIMIT}});}
\DoxyCodeLine{   elm\_genlist\_multi\_select\_set(list, \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}});}
\DoxyCodeLine{   elm\_genlist\_select\_mode\_set(list, \mbox{\hyperlink{group__Elm__General_gga8e4aa5aa238e472f33813babfff0d56fa69bb485be5448b469c86485fd884d649}{ELM\_OBJECT\_SELECT\_MODE\_DEFAULT}});}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Scroller_ga4105c0d6adca64ed3d38e7e4116b09e4}{elm\_scroller\_policy\_set}}(list, \mbox{\hyperlink{group__Elm__Scroller_ggae4532876fde43d8d37fc9440a1e36a84a4453d6502d28a1157c19301deaa8f565}{ELM\_SCROLLER\_POLICY\_OFF}}, \mbox{\hyperlink{group__Elm__Scroller_ggae4532876fde43d8d37fc9440a1e36a84a74e67e8e341f5069ec27244c2a41053f}{ELM\_SCROLLER\_POLICY\_ON}});}
\DoxyCodeLine{   elm\_genlist\_longpress\_timeout\_set(list, 0.5);}
\DoxyCodeLine{   elm\_genlist\_block\_count\_set(list, 16);}

\end{DoxyCodeInclude}


Now let\textquotesingle{}s add elements to the list\+:


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

\end{DoxyCodeInclude}


It\textquotesingle{}s exactly the same as the previous example. The difference is on the behavior of the list, if you try to scroll, select items and so.

In this example we also need two buttons. One of them, when clicked, will display several status info about the current selection, the \char`\"{}realized\char`\"{} items, the item in the middle of the screen, and the current mode and active item of that mode for the genlist.

The other button will ask the genlist to \char`\"{}realize\char`\"{} again the items already \char`\"{}realized\char`\"{}, so their respective label\+\_\+get and icon\+\_\+get functions will be called again.

These are the callbacks for both of these buttons\+:

 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_show\_status\_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{Evas__Common_8h_a2453e92182bad3b0e0d84e5aff433b07}{Evas\_Coord}} x, y, w, h, mx, my;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_ga13a0c231414b86e62f68afe3c6fb462b}{Elm\_Object\_Item}} *glit = elm\_genlist\_selected\_item\_get(list);}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keyword}{const} \mbox{\hyperlink{struct__Eina__List}{Eina\_List}} *selected, *l;}
\DoxyCodeLine{   \mbox{\hyperlink{struct__Eina__List}{Eina\_List}} *realized;}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"\(\backslash\)nfirst selected item: \%p\(\backslash\)n"}, glit);}
\DoxyCodeLine{}
\DoxyCodeLine{   selected = elm\_genlist\_selected\_items\_get(list);}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"all selected items (\%d): "}, \mbox{\hyperlink{group__Eina__List__Group_ga301729054a498a2df09a5f1dd760697e}{eina\_list\_count}}(selected));}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__List__Group_gac6efafc19f526d916cdb9757240a8773}{EINA\_LIST\_FOREACH}}(selected, l, glit)}
\DoxyCodeLine{     printf(\textcolor{stringliteral}{"\%p "}, glit);}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"\(\backslash\)n"});}
\DoxyCodeLine{}
\DoxyCodeLine{   realized = elm\_genlist\_realized\_items\_get(list);}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"realized items (\%d): "}, \mbox{\hyperlink{group__Eina__List__Group_ga301729054a498a2df09a5f1dd760697e}{eina\_list\_count}}(realized));}
\DoxyCodeLine{   \textcolor{comment}{// The realized items list should be freed by either eina\_list\_free() or EINA\_LIST\_FREE when it is no longer needed}}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__List__Group_gae27a2c686a0a11693f9b06957c9bba83}{EINA\_LIST\_FREE}}(realized, glit)}
\DoxyCodeLine{     printf(\textcolor{stringliteral}{"\%p  "}, glit);}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"\(\backslash\)n"});}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"genlist mode: \%d\(\backslash\)n"}, elm\_genlist\_decorate\_mode\_get(list));}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"mode item: \%p\(\backslash\)n"}, elm\_genlist\_decorated\_item\_get(list));}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga6f52fab1a96dc58c85ee481d84bac871}{evas\_object\_geometry\_get}}(list, \&x, \&y, \&w, \&h);}
\DoxyCodeLine{   mx = w / 2 + x;}
\DoxyCodeLine{   my = h / 2 + y;}
\DoxyCodeLine{   glit = elm\_genlist\_at\_xy\_item\_get(list, mx, my, NULL);}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"item in the middle of the screen: \%p\(\backslash\)n"}, glit);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_realize\_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{   elm\_genlist\_realized\_items\_update(list);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}


Try to scroll, select some items and click on the \char`\"{}\+Show status\char`\"{} button. You\textquotesingle{}ll notice that not all items of the list are \char`\"{}realized\char`\"{}, thus consuming just a small amount of memory. The selected items are listed in the order that they were selected, and the current selected item printed using elm\+\_\+genlist\+\_\+selected\+\_\+item\+\_\+get() is the first selected item of the multiple selection.

Now resize the window so that you can see the \char`\"{}realized time\char`\"{} of some items. This is the time of when the label\+\_\+get function was called. If you click on the \char`\"{}\+Realize\char`\"{} button, all the already realized items will be rebuilt, so the time will be updated for all of them.

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

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