|
这个代码片段展示了如何创建一个工具栏的项目可以有不同的状态。 状态之间的转换是通过回调。 年底回调需要取消项目,这样它就可以被点击。
- //callbcak for item pressed, we have to change item's state and deselect it
- static void item_pressed_callback(void *data, Evas_Object *obj, void *event_info) {
- Elm_Object_Item *item = event_info;
- elm_toolbar_item_state_set(item, elm_toolbar_item_state_next(item));
- elm_toolbar_item_selected_set(item, EINA_FALSE);
- }
- static void toolbar_test(appdata_s *ad) {
- Evas_Object *box = elm_box_add(ad->win);
- evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- elm_win_resize_object_add(ad->win, box);
- evas_object_show(box);
- //some content
- Evas_Object* label = elm_label_add(ad->win);
- elm_object_text_set(label, "Content");
- evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(label, 0.5, 0.5);
- evas_object_show(label);
- //toolbar
- Evas_Object* toolbar = elm_toolbar_add(ad->win);
- evas_object_size_hint_weight_set(toolbar, 0.0, 0.0);
- evas_object_size_hint_align_set(toolbar, EVAS_HINT_FILL, 0.0);
- evas_object_show(toolbar);
- //item with different states
- Elm_Object_Item *item = elm_toolbar_item_append(toolbar, NULL, "STATE 1", item_pressed_callback, NULL);
- elm_toolbar_item_state_add(item, NULL, "STATE 2", item_pressed_callback, NULL);
- elm_toolbar_item_state_add(item, NULL, "STATE 3", item_pressed_callback, NULL);
- //create another state and delete it
- Elm_Toolbar_Item_State *state = elm_toolbar_item_state_add(item, NULL, "STATE 4", item_pressed_callback, NULL);
- elm_toolbar_item_state_del(item, state);
- //some more items to the toolbar
- elm_toolbar_item_append(toolbar, NULL, "ITEM 1", NULL, NULL);
- elm_toolbar_item_append(toolbar, NULL, "ITEM 2", NULL, NULL);
- elm_box_pack_end(box, toolbar);
- elm_box_pack_end(box, label);
- }
复制代码
|
|