In this example we will create a combobox with 1000 items.
We will start with the normal creation of window stuff:
#ifndef _GNU_SOURCE
# define _GNU_SOURCE
#endif
#include <string.h>
#include <Elementary.h>
static void
_combobox_clicked_cb(
void *data EINA_UNUSED,
Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
printf("Hover button is clicked and 'clicked' callback is called.\n");
}
static void
_combobox_selected_cb(
void *data EINA_UNUSED,
Evas_Object *obj EINA_UNUSED,
void *event_info)
{
const char *txt = elm_object_item_text_get(event_info);
printf("'selected' callback is called. (selected item : %s)\n", txt);
}
static void
_combobox_dismissed_cb(
void *data EINA_UNUSED,
Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
printf("'dismissed' callback is called.\n");
}
static void
_combobox_expanded_cb(
void *data EINA_UNUSED,
Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
printf("'expanded' callback is called.\n");
}
static void
_combobox_item_pressed_cb(
void *data EINA_UNUSED,
Evas_Object *obj,
void *event_info)
{
const char *txt = elm_object_item_text_get(event_info);
printf("'item,pressed' callback is called. (selected item : %s)\n", txt);
elm_object_text_set(obj, txt);
elm_combobox_hover_end(obj);
}
static char *
gl_text_get(
void *data,
Evas_Object *obj EINA_UNUSED,
const char *part EINA_UNUSED)
{
char buf[256];
snprintf(buf, sizeof(buf), "Item # %i", (int)(uintptr_t)data);
return strdup(buf);
}
static Eina_Bool gl_state_get(
void *data EINA_UNUSED,
const char *part EINA_UNUSED)
{
}
gl_filter_get(
void *data,
Evas_Object *obj EINA_UNUSED,
void *key)
{
char buf[256];
snprintf(buf, sizeof(buf), "Item # %i", (int)(uintptr_t)data);
}
EAPI_MAIN int
elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
{
Next we will create a box.
And now we create our combobox and set some of it's properties. We set win
as its parent, set a text "A Simple List" (which acts as a placeholder). We pack the combobox in box.
elm_box_pack_end(bx, combobox);
Next we create a new genlist item class and sets its properties: item_style as deafult , callback for text_get and set others as NULL.
Next we will append 1000 items to the combobox, this is similar to appending items to the genlist
for (int i = 0; i < 1000; i++)
elm_genlist_item_append(combobox, itc, (void *)(uintptr_t)i,
(void*)(uintptr_t)(i * 10));
We also set a pair of callbacks to be called whenever any item is selected or pressed. when the combobox is activated, dismissed, expanded :
_combobox_clicked_cb, NULL);
_combobox_selected_cb, NULL);
_combobox_dismissed_cb, NULL);
_combobox_expanded_cb, NULL);
_combobox_item_pressed_cb, NULL);
And then ask that our combobox be shown and run the main loop:
We now have the callback for setting text in the each item of genlist:
Next we have the callback which is called when the combobox is clicked:
Next we have the callback that is called whenever an item is selected and text of that item is set on combobox:
Next we have the callback that is called whenever an item is pressed and text of that item is set on combobox and the hover is closed:
Next we have the callback that is called whenever an item is double-clicked or pressing (enter|return|spacebar) on an item also the text(event_info) of that item is set on combobox and the hover is closed:
And the callback that is called when the hover,genlist are closed.
And finally the callback is called when hover,genlist are shown.
Our example will initially look like this: