1 /*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include <Efl_Ui.hh>
17
18 EAPI_MAIN int
elm_main(int argc EINA_UNUSED,char * argv[]EINA_UNUSED)19 elm_main (int argc EINA_UNUSED, char *argv[] EINA_UNUSED)
20 {
21 efl::eina::eina_init eina_init;
22
23 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN);
24
25 efl::ui::Win win(efl::eo::instantiate);
26 win.text_set("Menu Example");
27 win.autohide_set(true);
28
29 #if 0
30 evas::rectangle rect(efl::eo::parent = win);
31 win.resize_object_add(rect);
32 rect.size_hint_min_set(0, 0);
33 rect.color_set( 0, 0, 0, 0);
34 rect.visible_set(true);
35
36 ::elm::widget_item no_parent(nullptr);
37 ::elm::menu menu(efl::eo::parent = win);
38 menu.item_add(no_parent, nullptr, "first item", nullptr, nullptr);
39 elm::widget_item
40 menu_it = menu.item_add(no_parent, "mail-reply-all", "second item", nullptr, nullptr);
41
42 menu.item_add(menu_it, "object-rotate-left", "menu 1", NULL, NULL);
43 ::elm::button button(efl::eo::parent = win);
44 button.text_set("elm.text", "button - delete items");
45 elm::widget_item menu_it1
46 = menu.item_add(menu_it, nullptr, nullptr, NULL, NULL);
47 menu_it1.part_content_set(nullptr, button);
48
49 auto del_it = std::bind([&] ()
50 {
51 auto list = efl::eo::downcast<elm::menu_item>(menu_it).subitems_get();
52 for(auto& item : list)
53 {
54 elm_object_item_del(item._eo_ptr());
55 }
56 });
57
58 button.callback_clicked_add(del_it);
59 menu.item_separator_add(menu_it);
60 menu.item_add(menu_it, nullptr, "third item", NULL, NULL);
61 menu.item_add(menu_it, nullptr, "fourth item", NULL, NULL);
62 menu.item_add(menu_it, "window-new", "sub menu", NULL, NULL);
63
64 elm::widget_item menu_it2 = menu.item_add(no_parent, nullptr, "third item", nullptr, nullptr);
65 menu_it2.disabled_set(EINA_TRUE);
66
67 auto show = std::bind([&] (void *event_info)
68 {
69 Evas_Event_Mouse_Down *ev = static_cast<Evas_Event_Mouse_Down*>(event_info);
70 menu.move(ev->canvas.x, ev->canvas.y);
71 menu.visible_set(true);
72 }, std::placeholders::_3);
73
74 rect.callback_mouse_down_add( show );
75 menu.visible_set(true);
76
77 #endif
78 win.size_set({250, 350});
79
80 elm_run();
81 return 0;
82 }
83 ELM_MAIN()
84