Toolbar Example - Items with Menus

Toolbar widgets have support to items with menus.

This kind of item will display a menu when selected by the user.

Let's start populating a toolbar with some regular items, the same way we started Toolbar Example 2.

tb = elm_toolbar_add(win);
Evas_Object * elm_toolbar_add(Evas_Object *parent)
Add a new toolbar widget to the given parent Elementary (container) object.
Definition: elm_toolbar.c:2979
elm_toolbar_item_append(tb, "document-print", "Print", NULL, NULL);
elm_toolbar_item_append(tb, "folder-new", "Folder", NULL, NULL);
elm_toolbar_item_append(tb, "clock", "Clock", NULL, NULL);
elm_toolbar_item_append(tb, "refresh", "Update", NULL, NULL);
#define EVAS_HINT_FILL
Use with evas_object_size_hint_align_set(), evas_object_size_hint_align_get(), evas_object_size_hint_...
Definition: Evas_Common.h:298
Elm_Widget_Item * elm_toolbar_item_append(Elm_Toolbar *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
Append item to the toolbar.
Definition: elm_toolbar_eo.legacy.c:129
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
EVAS_API void evas_object_size_hint_weight_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's weight.
Definition: evas_object_main.c:2638
EVAS_API void evas_object_size_hint_align_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's alignment.
Definition: evas_object_main.c:2650

The only difference is that we'll keep the default shrink mode, that adds an item with a menu of hidden items.

So, a important thing to do is to set a parent for toolbar menus, or they will use the toolbar as parent, and its size will be restricted to that.

void elm_toolbar_menu_parent_set(Elm_Toolbar *obj, Efl_Canvas_Object *parent)
Control the parent object of the toolbar items' menus.
Definition: elm_toolbar_eo.legacy.c:87

Not only items' menus will respect this parent, but also the own toolbar menu, used to show hidden items.

Next, let's add an item set to display a menu:

tb_it = elm_toolbar_item_append(tb, "mail-send", "Send Mail", NULL, NULL);
elm_toolbar_item_menu_set(tb_it, EINA_TRUE);
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:539

Now, to add two options to this item, we can get the menu object and use it as a regular elm_menu. See Menu example for more about menu widget.

menu = elm_toolbar_item_menu_get(tb_it);
elm_menu_item_add(menu, NULL, "emptytrash", "Empty Trash", NULL, NULL);
elm_menu_item_add(menu, NULL, "trashcan_full", "Full Trash", NULL, NULL);

See toolbar_example_03.c, whose window should look like this picture: