genlist_example_03.c
//Compile with:
//gcc -g genlist_example_03.c -o genlist_example_03 `pkg-config --cflags --libs elementary`
#include <Elementary.h>
#define N_ITEMS 30
static Elm_Genlist_Item_Class *_itc = NULL;
static char *
_item_label_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part)
{
time_t t = (time_t)ecore_time_unix_get();
char buf[256];
int i = (int)(uintptr_t)data;
if (!strcmp(part, "elm.text"))
snprintf(buf, sizeof(buf), "Item # %i", i);
else
{
int n;
snprintf(buf, sizeof(buf), "created at %s", ctime(&t));
n = strlen(buf);
buf[n - 1] = '\0';
}
return strdup(buf);
}
static Evas_Object *
_item_content_get(void *data EINA_UNUSED, Evas_Object *obj, const char *part)
{
if (!strcmp(part, "elm.swallow.icon"))
elm_icon_standard_set(ic, "clock");
return ic;
}
static void
_item_sel_cb(void *data, Evas_Object *obj, void *event_info)
{
printf("sel item data [%p] on genlist obj [%p], item pointer [%p]\n",
data, obj, event_info);
}
static Evas_Object *
_genlist_add(Evas_Object *box)
{
elm_box_pack_end(box, list);
return list;
}
static void
_genlist_fill(Evas_Object *list)
{
unsigned int i;
for (i = 0; i < N_ITEMS; i++)
{
(void *)(uintptr_t)i, NULL,
_item_sel_cb, NULL);
}
}
EAPI_MAIN int
elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
{
Evas_Object *win, *box;
Evas_Object *list;
win = elm_win_util_standard_add("genlist", "Genlist");
box = elm_box_add(win);
if (!_itc)
{
_itc->item_style = "double_label";
_itc->func.text_get = _item_label_get;
_itc->func.content_get = _item_content_get;
_itc->func.state_get = NULL;
_itc->func.del = NULL;
}
list = _genlist_add(box);
_genlist_fill(list);
list = _genlist_add(box);
_genlist_fill(list);
list = _genlist_add(box);
_genlist_fill(list);
evas_object_resize(win, 800, 320);
return 0;
}