Navigation style toolbar

This code snippet shows how to create a navigation style toolbar. It is just a skeleton, without any real changing views functionality.
//find out which item was clicked
static void toolbar_item_cb(void *data, Evas_Object *obj, void *event_info) {
	Evas_Object *toolbar = data;
	Elm_Object_Item *item = event_info;
	const char *item_name = elm_object_item_text_get(item);

	//remove items after the selected one
	Elm_Object_Item *last = elm_toolbar_last_item_get(toolbar);
	while(last!=item){
		elm_object_item_del(last);
		last = elm_toolbar_last_item_get(toolbar);
	}
	dlog_print(DLOG_DEBUG, LOG_TAG, "Toolbar item clicked: %s", item_name);
}

static void create_toolbar(Evas_Object *parent) {
	//create the toolbar
	Evas_Object *toolbar = elm_toolbar_add(parent);
	elm_object_style_set(toolbar, "navigationbar");
	elm_win_resize_object_add(parent, toolbar);
	elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_SCROLL);
	elm_toolbar_align_set(toolbar, 0.0);
	elm_toolbar_homogeneous_set(toolbar, EINA_FALSE);
	elm_toolbar_select_mode_set(toolbar, ELM_OBJECT_SELECT_MODE_NONE);

	//populate toolbar with items
	elm_toolbar_item_append(toolbar, NULL, "Book", toolbar_item_cb, toolbar);
	elm_toolbar_item_append(toolbar, NULL, "Chapter 1", toolbar_item_cb, toolbar);
	elm_toolbar_item_append(toolbar, NULL, "Section 2", toolbar_item_cb, toolbar);
	elm_toolbar_item_append(toolbar, NULL, "Paragraph 2", toolbar_item_cb, toolbar);
	elm_toolbar_item_append(toolbar, NULL, "Sentence 5", toolbar_item_cb, toolbar);


	evas_object_show(toolbar);
}

Responses

0 Replies