This example shows how to create a menu with regular items, object items, submenus and how to delete items from a menu. The full source for this example is menu_example_01.c.
We'll start looking at the menu creation and how to create a very simple item:
elm_menu_item_add(menu, NULL, NULL, "first item", NULL, NULL);
For our next item we are going to add an icon:
menu_it = elm_menu_item_add(menu, NULL, "mail-reply-all", "second item", NULL, NULL);
Now we are going to add more items, but these icons are going to have a parent, which will put them in a sub-menu. First just another item with an icon:
elm_menu_item_add(menu, menu_it, "object-rotate-left", "menu 1", NULL, NULL);
Next we are going to add a button to our menu(any elm widget can be added to a menu):
elm_object_text_set(button, "button - delete items");
menu_it1 = elm_menu_item_add(menu, menu_it, NULL, NULL, NULL, NULL);
We are also going to have the button delete the first item of our sub-menu when clicked:
elm_object_item_content_set(menu_it1, button);
static void
{
menu_it = elm_menu_item_next_get(menu_it);
l = elm_menu_item_subitems_get(menu_it);
}
We now add a separator and three more regular items:
static void
{
}
EAPI_MAIN int
{
elm_menu_item_add(menu, NULL, NULL, "first item", NULL, NULL);
menu_it = elm_menu_item_add(menu, NULL, "mail-reply-all", "second item", NULL, NULL);
elm_menu_item_add(menu, menu_it, "object-rotate-left", "menu 1", NULL, NULL);
We now add another item, however this time it won't go the sub-menu and it'll be disabled:
elm_object_text_set(button, "button - delete items");
menu_it1 = elm_menu_item_add(menu, menu_it, NULL, NULL, NULL, NULL);
elm_object_item_content_set(menu_it1, button);
elm_menu_item_separator_add(menu, menu_it);
elm_menu_item_add(menu, menu_it, NULL, "third item", NULL, NULL);
elm_menu_item_add(menu, menu_it, NULL, "fourth item", NULL, NULL);
elm_menu_item_add(menu, menu_it, "window-new", "sub menu", NULL, NULL);
menu_it = elm_menu_item_add(menu, NULL, NULL, "third item", NULL, NULL);
To make sure that our menu is shown whenever the window is clicked(and where clicked) we use the following callback:
static void
{
menu_it = elm_menu_item_next_get(menu_it);
l = elm_menu_item_subitems_get(menu_it);
}
Our example will look like this: