In this example we will create a hoversel with 3 items, one with a label but no icon and two with both a label and an icon. Every item that is clicked will be deleted, but everytime the hoversel is activated we will also add an item. In addition our first item will print all items when clicked and our third item will clear all items in the hoversel.
We will start with the normal creation of window stuff:
//Compile with: //gcc -o hoversel_example_01 hoversel_example_01.c -g `pkg-config --cflags --libs elementary` #include <Elementary.h> static void _print_items(void *data, Evas_Object *obj, void *event_info); static void _rm_items(void *data, Evas_Object *obj, void *event_info); static void _sel(void *data, Evas_Object *obj, void *event_info); static void _free(void *data, Evas_Object *obj, void *event_info); static void _add_item(void *data, Evas_Object *obj, void *event_info); EAPI_MAIN int elm_main(int argc, char **argv) { Evas_Object *win, *bg, *rect, *hoversel; Elm_Object_Item *hoversel_it; win = elm_win_add(NULL, "hoversel", ELM_WIN_BASIC); elm_win_title_set(win, "Hoversel"); elm_win_autodel_set(win, EINA_TRUE); elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); evas_object_resize(win, 200, 300); evas_object_show(win); bg = elm_bg_add(win); evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); elm_win_resize_object_add(win, bg); evas_object_show(bg);
Next we will create a red rectangle to use as the icon of our hoversel:
rect = evas_object_rectangle_add(evas_object_evas_get(win)); evas_object_color_set(rect, 255, 0, 0, 255); evas_object_show(rect);
And now we create our hoversel and set some of it's properties. We set win
as its parent, ask it to not be horizontal(be vertical) and give it a label and icon:
hoversel = elm_hoversel_add(win); elm_hoversel_hover_parent_set(hoversel, win); elm_hoversel_horizontal_set(hoversel, EINA_FALSE); elm_object_text_set(hoversel, "Hoversel"); elm_object_part_content_set(hoversel, "icon", rect);
Next we will add our three items, setting a callback to be called for the first and third:
elm_hoversel_item_add(hoversel, "Print items", NULL, ELM_ICON_NONE, _print_items, NULL); elm_hoversel_item_add(hoversel, "Option 2", "home", ELM_ICON_STANDARD, NULL, NULL); hoversel_it = elm_hoversel_item_add(hoversel, "Clear all items", "close", ELM_ICON_STANDARD, _rm_items, NULL);
We also set a pair of callbacks to be called whenever any item is selected or when the hoversel is activated:
evas_object_smart_callback_add(hoversel, "selected", _sel, hoversel_it); evas_object_smart_callback_add(hoversel, "clicked", _add_item, NULL);
And then ask that our hoversel be shown and run the main loop:
evas_object_resize(hoversel, 180, 30); evas_object_move(hoversel, 10, 10); evas_object_show(hoversel); elm_run(); elm_shutdown(); return 0; } ELM_MAIN()
We now have the callback for our first item which prints all items in the hoversel:
static void _print_items(void *data, Evas_Object *obj, void *event_info) { const Eina_List *items = elm_hoversel_items_get(obj); const Eina_List *l; Elm_Object_Item *hoversel_it; EINA_LIST_FOREACH(items, l, hoversel_it) printf("%s\n", elm_object_item_text_get(hoversel_it)); }
Next we have the callback for our third item which removes all items from the hoversel:
static void _rm_items(void *data, Evas_Object *obj, void *event_info) { if (!elm_hoversel_expanded_get(obj)) elm_hoversel_clear(obj); }
Next we have the callback that is called whenever an item is clicked and deletes that item:
static void _sel(void *data, Evas_Object *obj, void *event_info) { if (!elm_hoversel_expanded_get(obj) && event_info != data) elm_object_item_del(event_info); }
And the callback that is called when the hoversel is activated and adds an item to the hoversel. Note that since we allocate memory for the item we need to know when the item dies so we can free that memory:
static void _add_item(void *data, Evas_Object *obj, void *event_info) { static int num = 0; char *str = malloc(sizeof(char) * 10); Elm_Object_Item *hoversel_it; snprintf(str, 10, "item %d", ++num); hoversel_it = elm_hoversel_item_add(obj, str, NULL, ELM_ICON_NONE, NULL, str); elm_object_item_del_cb_set(hoversel_it, _free); }
And finally the callback that frees the memory we allocated for items created in the _add_item
callback:
static void _free(void *data, Evas_Object *obj, void *event_info) { free(data); }
Our example will initially look like this:

And when the hoversel is clicked it will look like this:
