This example is very similar to the \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 \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}
\textcolor{keyword}{static} \textcolor{keywordtype}{char} *
\_item\_label\_get(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *part)
\{
   time\_t t = (time\_t)ecore\_time\_unix\_get();
   \textcolor{keywordtype}{char} buf[256];
   \textcolor{keywordtype}{int} i = (int)(\textcolor{keywordtype}{long})data;
   \textcolor{keywordflow}{if} (i % 2)
     \{
        \textcolor{keywordtype}{int} n;
        snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"Very Long Item # %i - realized at %s"}, i, ctime(&t));
        n = strlen(buf);
        buf[n - 1] = \textcolor{charliteral}{'\(\backslash\)0'};
     \}
   \textcolor{keywordflow}{else}
     snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"short item # %i"}, i);
   \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}
   list = elm_genlist_add(win);

   \textcolor{keywordflow}{if} (!\_itc)
     \{
        \_itc = elm_genlist_item_class_new();
        \_itc->item\_style = \textcolor{stringliteral}{"default"};
        \_itc->func.text\_get = \_item\_label\_get;
        \_itc->func.content\_get = \_item\_content\_get;
        \_itc->func.state\_get = NULL;
        \_itc->func.del = NULL;
     \}

   Eina\_Bool hbounce, vbounce, always, no\_sel;
   Elm_Scroller_Policy hp, vp;
   Elm\_Object\_Select\_Mode sel\_mode;

   always = no\_sel = EINA\_FALSE;
   sel\_mode = elm_genlist_select_mode_get(list);
   \textcolor{keywordflow}{if} (sel\_mode == ELM\_OBJECT\_SELECT\_MODE\_ALWAYS)
     always = EINA\_TRUE;
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (sel\_mode == ELM\_OBJECT\_SELECT\_MODE\_NONE)
     no\_sel = EINA\_TRUE;

   printf(\textcolor{stringliteral}{"default values:\(\backslash\)n"});
   printf(\textcolor{stringliteral}{"always select: %d\(\backslash\)n"}, always);
   elm_scroller_bounce_get(list, &hbounce, &vbounce);
   printf(\textcolor{stringliteral}{"bounce - horizontal: %d, vertical: %d\(\backslash\)n"}, hbounce, vbounce);
   printf(\textcolor{stringliteral}{"homogeneous: %d\(\backslash\)n"}, elm_genlist_homogeneous_get(list));
   printf(\textcolor{stringliteral}{"horizontal mode: %d\(\backslash\)n"}, elm_genlist_mode_get(list));
   printf(\textcolor{stringliteral}{"longpress timeout: %0.3f\(\backslash\)n"},
          elm_genlist_longpress_timeout_get(list));
   printf(\textcolor{stringliteral}{"multi selection: %d\(\backslash\)n"}, elm_genlist_multi_select_get(list));
   printf(\textcolor{stringliteral}{"no selection mode: %d\(\backslash\)n"}, no\_sel);
   elm_scroller_policy_get(list, &hp, &vp);
   printf(\textcolor{stringliteral}{"scroller policy - horizontal: %d, vertical: %d\(\backslash\)n"}, hp, vp);
   printf(\textcolor{stringliteral}{"block count: %d\(\backslash\)n"}, elm_genlist_block_count_get(list));
   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 \hyperlink{group__Elm__Genlist_gaf037c92717b93ea122ae26c757a23c65}{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 \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\+: \hyperlink{group__Elm__Genlist_gae988081f5d93d0916cd659395dec07c9}{elm\+\_\+genlist\+\_\+homogeneous\+\_\+set()} is set to false.

Since the compress mode is active, the call to \hyperlink{group__Elm__Genlist_ga7749546e6666dd50ab7d1b8a4dbb99ad}{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 \hyperlink{group__Elm__Genlist_gaa59068079de22ed91758085dae25367b}{elm\+\_\+genlist\+\_\+multi\+\_\+select\+\_\+set()} on it.

The option \hyperlink{group__Elm__Genlist_ga7749546e6666dd50ab7d1b8a4dbb99ad}{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 \hyperlink{group__Elm__Genlist_ga2336370da936f94b6b161093a2e62516}{elm\+\_\+genlist\+\_\+scroller\+\_\+policy\+\_\+set()}.

The timeout to consider a longpress is set to half of a second with \hyperlink{group__Elm__Genlist_ga794379f1622c52fb7815afe89559ffa6}{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}

   elm_scroller_bounce_set(list, EINA\_FALSE, EINA\_FALSE);
   elm_genlist_homogeneous_set(list, EINA\_FALSE);
   elm_genlist_mode_set(list, ELM_LIST_LIMIT);
   elm_genlist_multi_select_set(list, EINA\_TRUE);
   elm_genlist_select_mode_set(list, ELM\_OBJECT\_SELECT\_MODE\_DEFAULT);
   elm_scroller_policy_set(list, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_ON);
   elm_genlist_longpress_timeout_set(list, 0.5);
   elm_genlist_block_count_set(list, 16);

\end{DoxyCodeInclude}


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


\begin{DoxyCodeInclude}

   \textcolor{keywordflow}{for} (i = 0; i < N\_ITEMS; i++)
     \{
        elm_genlist_item_append(list, \_itc,
                                (\textcolor{keywordtype}{void} *)(\textcolor{keywordtype}{long})i, NULL,
                                ELM\_GENLIST\_ITEM\_NONE,
                                \_item\_sel\_cb, NULL);
     \}

\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}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_show\_status\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *o, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *list = data;
   Evas\_Coord x, y, w, h, mx, my;
   Elm_Object_Item *glit = elm_genlist_selected_item_get(list);

   \textcolor{keyword}{const} Eina\_List *selected, *l, *realized;
   printf(\textcolor{stringliteral}{"\(\backslash\)nfirst selected item: %p\(\backslash\)n"}, glit);

   selected = elm_genlist_selected_items_get(list);
   printf(\textcolor{stringliteral}{"all selected items (%d): "}, eina\_list\_count(selected));
   EINA\_LIST\_FOREACH(selected, l, glit)
     printf("%p ", glit);
   printf("\(\backslash\)n");

   realized = elm_genlist_realized_items_get(list);
   printf("realized items (%d): ", eina\_list\_count(realized));
   EINA\_LIST\_FOREACH(realized, l, glit)
     printf("%p  ", glit);
   printf("\(\backslash\)n");
   printf("genlist mode: %d\(\backslash\)n", elm_genlist_decorate_mode_get(list));
   printf("mode item: %p\(\backslash\)n", elm_genlist_decorated_item_get(list));

   evas\_object\_geometry\_get(list, &x, &y, &w, &h);
   mx = w / 2 + x;
   my = h / 2 + y;
   glit = elm_genlist_at_xy_item_get(list, mx, my, NULL);
   printf("item in the middle of the screen: %p\(\backslash\)n", glit);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_realize\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *o, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *list = data;
   elm_genlist_realized_items_update(list);
\}

\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 \hyperlink{group__Elm__Genlist_ga97abf26033fe2041450aa26b6f138c8a}{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}
 