Tizen Native API  8.0
Genlist - items manipulation

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):

static char *
_group_label_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
{
   char buf[256];
   int i = (int)(uintptr_t)data;

   snprintf(buf, sizeof(buf), "Group %d (item #%d)", i / 7, i);

   return strdup(buf);
}

static Evas_Object *
_group_content_get(void *data EINA_UNUSED, Evas_Object *obj, const char *part)
{
   Evas_Object *ic = elm_icon_add(obj);

   if (!strcmp(part, "elm.swallow.icon"))
     elm_icon_standard_set(ic, "home");

   evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
   return ic;
}

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:

static void
_insert_after_cb(void *data, Evas_Object *o EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Evas_Object *list = data;
   Elm_Object_Item *glit = elm_genlist_selected_item_get(list);

   if (!glit) return;

   elm_genlist_item_insert_after(list, _itc,
                                 (void *)(uintptr_t)nitems++, NULL,
                                 glit, ELM_GENLIST_ITEM_NONE,
                                 _item_sel_cb, NULL);

}

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:

static Evas_Object *
_button_add(Evas_Object *list, Evas_Object *box, const char *label, Evas_Smart_Cb cb)
{
   Evas_Object *bt;

   bt = elm_button_add(elm_object_parent_widget_get(list));
   elm_object_text_set(bt, label);
   elm_box_pack_end(box, bt);
   evas_object_show(bt);

   if (cb)
     evas_object_smart_callback_add(bt, "clicked", cb, list);

   return bt;
}

In our 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.