Toolbar Example - Items with States

This code places an Elementary toolbar widget on a window, to exemplify part of the widget's API.

Toolbar widgets has support to items with states. Each state can have it's own label, icon, and callback function.

Let's start populating a toolbar with some regular items. If you don't know how to do that, see Toolbar Example 1.

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
void elm_toolbar_shrink_mode_set(Elm_Toolbar *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
Control the item displaying mode of a given toolbar widget obj.
Definition: elm_toolbar_eo.legacy.c:75
@ ELM_TOOLBAR_SHRINK_HIDE
Hide exceeding items.
Definition: elm_toolbar_eo.h:31
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 here is that we set shrink mode to ELM_TOOLBAR_SHRINK_HIDE, that won't display items that doesn't fit to the window.

Now, let's add an item with states. First, add the item just as any other.

tb_it = elm_toolbar_item_append(tb, "mail-send", "Send Mail",
_item_pressed, NULL);

After that states can be added to this item:

elm_toolbar_item_state_add(tb_it, "emptytrash", "Empty Trash",
_item_pressed, NULL);
elm_toolbar_item_state_add(tb_it, "trashcan_full", "Full Trash",
_item_pressed, NULL);

The both states and the item are using the same callback function, that will cycle between states and unselect the item. Unseleting is required because it won't call the callback if a user clicks over an item already selected:

On our example, some items are hidden because we set the window to be small. But if an item should be displayed anyway, is needed to set its priority to be higher than others. Any positive value will be enough in our case. Let's force the item with multiple states to be displayed.

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