//Compile with:
//gcc -g genlist_example_02.c -o genlist_example_02 `pkg-config --cflags --libs elementary`
#include <Elementary.h>
#include <time.h>
#define N_ITEMS 300
static Elm_Genlist_Item_Class *_itc = NULL;
static char *
_item_label_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
time_t t = (time_t)ecore_time_unix_get();
char buf[256];
int i = (int)(uintptr_t)data;
if (i % 2)
int n;
snprintf(buf, sizeof(buf), "Very Long Item # %i - realized at %s", i, ctime(&t));
n = strlen(buf);
buf[n - 1] = '\0';
snprintf(buf, sizeof(buf), "short item # %i", i);
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 void
_show_status_cb(void *data, Evas_Object *o EINA_UNUSED, void *event_info EINA_UNUSED)
Evas_Object *list = data;
Evas_Coord x, y, w, h, mx, my;
const Eina_List *selected, *l;
Eina_List *realized;
printf("\nfirst selected item: %p\n", glit);
printf("all selected items (%d): ", eina_list_count(selected));
EINA_LIST_FOREACH(selected, l, glit)
printf("%p ", glit);
printf("realized items (%d): ", eina_list_count(realized));
// The realized items list should be freed by either eina_list_free() or EINA_LIST_FREE when it is no longer needed
EINA_LIST_FREE(realized, glit)
printf("%p ", glit);
printf("genlist mode: %d\n", elm_genlist_decorate_mode_get(list));
printf("mode item: %p\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\n", glit);
static void
_realize_cb(void *data, Evas_Object *o EINA_UNUSED, void *event_info EINA_UNUSED)
Evas_Object *list = data;
elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
Evas_Object *win, *box, *hbox;
Evas_Object *list, *btn;
unsigned int i;
win = elm_win_util_standard_add("genlist", "Genlist - simple");
box = elm_box_add(win);
list = elm_genlist_add(win);
if (!_itc)
_itc->item_style = "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;
always = no_sel = EINA_FALSE;
sel_mode = elm_genlist_select_mode_get(list);
always = EINA_TRUE;
else if (sel_mode == ELM_OBJECT_SELECT_MODE_NONE)
no_sel = EINA_TRUE;
printf("default values:\n");
printf("always select: %d\n", always);
elm_scroller_bounce_get(list, &hbounce, &vbounce);
printf("bounce - horizontal: %d, vertical: %d\n", hbounce, vbounce);
printf("homogeneous: %d\n", elm_genlist_homogeneous_get(list));
printf("horizontal mode: %d\n", elm_genlist_mode_get(list));
printf("longpress timeout: %0.3f\n",
printf("multi selection: %d\n", elm_genlist_multi_select_get(list));
printf("no selection mode: %d\n", no_sel);
elm_scroller_policy_get(list, &hp, &vp);
printf("scroller policy - horizontal: %d, vertical: %d\n", hp, vp);
printf("block count: %d\n", elm_genlist_block_count_get(list));
for (i = 0; i < N_ITEMS; i++)
(void *)(uintptr_t)i, NULL,
_item_sel_cb, NULL);
elm_box_pack_end(box, list);
hbox = elm_box_add(win);
elm_box_pack_end(box, hbox);
btn = elm_button_add(win);
elm_object_text_set(btn, "Show status");
evas_object_smart_callback_add(btn, "clicked", _show_status_cb, list);
elm_box_pack_end(hbox, btn);
btn = elm_button_add(win);
elm_object_text_set(btn, "Realize");
evas_object_smart_callback_add(btn, "clicked", _realize_cb, list);
elm_box_pack_end(hbox, btn);
evas_object_resize(win, 200, 320);
return 0;