

This example shows how to create a menu with regular items, object items, submenus and how to delete items from a menu. The full source for this example is \hyperlink{menu_example_01_8c-example}{menu\+\_\+example\+\_\+01.c}.

We\textquotesingle{}ll start looking at the menu creation and how to create a very simple item\+: 
\begin{DoxyCodeInclude}
   menu = elm_menu_add(win);
   elm_menu_item_add(menu, NULL, NULL, \textcolor{stringliteral}{"first item"}, NULL, NULL);

\end{DoxyCodeInclude}


For our next item we are going to add an icon\+: 
\begin{DoxyCodeInclude}
   menu\_it = elm_menu_item_add(menu, NULL, \textcolor{stringliteral}{"mail-reply-all"}, \textcolor{stringliteral}{"second item"}, NULL, NULL);

\end{DoxyCodeInclude}


Now we are going to add more items, but these icons are going to have a parent, which will put them in a sub-\/menu. First just another item with an icon\+: 
\begin{DoxyCodeInclude}

   elm_menu_item_add(menu, menu\_it, \textcolor{stringliteral}{"object-rotate-left"}, \textcolor{stringliteral}{"menu 1"}, NULL, NULL);

\end{DoxyCodeInclude}


Next we are going to add a button to our menu(any elm widget can be added to a menu)\+: 
\begin{DoxyCodeInclude}
   button = elm_button_add(win);
   elm\_object\_text\_set(button, \textcolor{stringliteral}{"button - delete items"});
   menu\_it1 = elm_menu_item_add(menu, menu\_it, NULL, NULL, NULL, NULL);

\end{DoxyCodeInclude}


We are also going to have the button delete the first item of our sub-\/menu when clicked\+: 
\begin{DoxyCodeInclude}
   elm\_object\_item\_content\_set(menu\_it1, button);
   evas\_object\_smart\_callback\_add(button, \textcolor{stringliteral}{"clicked"}, \_del\_it, menu);

\end{DoxyCodeInclude}
  
\begin{DoxyCodeInclude}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_del\_it(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keyword}{const} Eina\_List *l;
   Elm_Object_Item *menu\_it = elm_menu_first_item_get(data);
   menu\_it = elm_menu_item_next_get(menu\_it);
   l = elm_menu_item_subitems_get(menu\_it);
   elm\_object\_item\_del(eina\_list\_data\_get(l));
\}

\end{DoxyCodeInclude}


We now add a separator and three more regular items\+: 
\begin{DoxyCodeInclude}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_show(\textcolor{keywordtype}{void} *data, Evas *e, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Event\_Mouse\_Down *ev = event\_info;
   elm_menu_move(data, ev->canvas.x, ev->canvas.y);
   evas\_object\_show(data);
\}

EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   Evas\_Object *win, *menu, *button, *rect;
   Elm_Object_Item *menu\_it, *menu\_it1;

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"menu"}, \textcolor{stringliteral}{"Menu"});
   elm_win_autodel_set(win, EINA\_TRUE);
   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);

   rect = evas\_object\_rectangle\_add(evas\_object\_evas\_get(win));
   elm_win_resize_object_add(win, rect);
   evas\_object\_size\_hint\_min\_set(rect, 0, 0);
   evas\_object\_color\_set(rect, 0, 0, 0, 0);
   evas\_object\_show(rect);

   menu = elm_menu_add(win);
   elm_menu_item_add(menu, NULL, NULL, \textcolor{stringliteral}{"first item"}, NULL, NULL);
   menu\_it = elm_menu_item_add(menu, NULL, \textcolor{stringliteral}{"mail-reply-all"}, \textcolor{stringliteral}{"second item"}, NULL, NULL);

   elm_menu_item_add(menu, menu\_it, \textcolor{stringliteral}{"object-rotate-left"}, \textcolor{stringliteral}{"menu 1"}, NULL, NULL);

\end{DoxyCodeInclude}


We now add another item, however this time it won\textquotesingle{}t go the sub-\/menu and it\textquotesingle{}ll be disabled\+: 
\begin{DoxyCodeInclude}
   button = elm_button_add(win);
   elm\_object\_text\_set(button, \textcolor{stringliteral}{"button - delete items"});
   menu\_it1 = elm_menu_item_add(menu, menu\_it, NULL, NULL, NULL, NULL);
   elm\_object\_item\_content\_set(menu\_it1, button);
   evas\_object\_smart\_callback\_add(button, \textcolor{stringliteral}{"clicked"}, \_del\_it, menu);
   elm_menu_item_separator_add(menu, menu\_it);
   elm_menu_item_add(menu, menu\_it, NULL, \textcolor{stringliteral}{"third item"}, NULL, NULL);
   elm_menu_item_add(menu, menu\_it, NULL, \textcolor{stringliteral}{"fourth item"}, NULL, NULL);
   elm_menu_item_add(menu, menu\_it, \textcolor{stringliteral}{"window-new"}, \textcolor{stringliteral}{"sub menu"}, NULL, NULL);

   menu\_it = elm_menu_item_add(menu, NULL, NULL, \textcolor{stringliteral}{"third item"}, NULL, NULL);
   elm\_object\_item\_disabled\_set(menu\_it, EINA\_TRUE);

\end{DoxyCodeInclude}


To make sure that our menu is shown whenever the window is clicked(and where clicked) we use the following callback\+:  
\begin{DoxyCodeInclude}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_del\_it(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keyword}{const} Eina\_List *l;
   Elm_Object_Item *menu\_it = elm_menu_first_item_get(data);
   menu\_it = elm_menu_item_next_get(menu\_it);
   l = elm_menu_item_subitems_get(menu\_it);
   elm\_object\_item\_del(eina\_list\_data\_get(l));
\}

\end{DoxyCodeInclude}


Our example will look like this\+:

 
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth]{screenshots/menu_example_01}}
\end{DoxyImageNoCaption}
 