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_size_hint_weight_set(tb, 0.0, 0.0);
evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, 0.0);
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);

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.

elm_toolbar_menu_parent_set(tb, win);

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);

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:

elm_toolbar_add
Evas_Object * elm_toolbar_add(Evas_Object *parent)
Add a new toolbar widget to the given parent Elementary (container) object.
Definition: elm_toolbar.c:2984
evas_object_show
void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1853
EVAS_HINT_FILL
#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:293
EINA_TRUE
#define EINA_TRUE
Definition: eina_types.h:508