This example is very similar to the 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 API.
The full source code is at 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
_item_label_get function, we are going to store the time that this function was called. This is the "realized" time, the time when the visual representation of this item was created. This is the code for the
Now let'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:
We are going to change some of the properties of our list.
There'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 ELM_OBJECT_SELECT_MODE_ALWAYS.
For this list we don't want bounce animations at all, so we set both the horizontal bounce and the vertical bounce to false with 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, ELM_LIST_COMPRESS).
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'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 "text.min: 0 1", for example. But since we are compressing the elements to the width of the list, this option wouldn'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 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).
Now let's add elements to the list:
It'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 "realized" 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 "realize" again the items already "realized", so their respective label_get and icon_get functions will be called again.
These are the callbacks for both of these buttons:
Try to scroll, select some items and click on the "Show status" button. You'll notice that not all items of the list are "realized", 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 "realized time" of some items. This is the time of when the label_get function was called. If you click on the "Realize" 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: