This example is also similar ot the Genlist - basic usage, but it demonstrates most of the item manipulation functions.
See the full source code at genlist_example_04.c.
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):
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 elm_genlist_item_insert_after() function:
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:
elm_main function, besides the code for setting up the window, box and background, we also initialize our two item classes:
This example uses a different style for the items, the 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 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's add the buttons with their respective callbacks:
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):
Then we also check for specific items, and add callbacks to them on the respective buttons, so we can show, bring in, etc.:
Once you understand the code from the Genlist - basic usage, 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: