\chapter{Toolbar Example -\/ Simple Items}
\hypertarget{toolbar_example_01}{}\label{toolbar_example_01}\index{Toolbar Example -\/ Simple Items@{Toolbar Example -\/ Simple Items}}
This code places an Elementary toolbar widget on a window, to exemplify part of the widget\textquotesingle{}s API.

Let\textquotesingle{}s start adding a button to our window, that will have its text modified depending on which item is selected. It\textquotesingle{}s used just to exemplify how to change a window content from the toolbar.  
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ bt\ =\ \mbox{\hyperlink{group__Elm__Button_gaf5caf46d74c4e122a18da323935d25e4}{elm\_button\_add}}(win);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga9379629ad8ad2860aa786d838a4a106a}{evas\_object\_size\_hint\_weight\_set}}(bt,\ \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}},\ \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}});}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gaaf1d3e26e36b316977336066b6f56632}{evas\_object\_size\_hint\_align\_set}}(bt,\ \mbox{\hyperlink{Evas__Common_8h_aecbac710f36d52911fc34dcdaf8e729c}{EVAS\_HINT\_FILL}},\ \mbox{\hyperlink{Evas__Common_8h_aecbac710f36d52911fc34dcdaf8e729c}{EVAS\_HINT\_FILL}});}
\DoxyCodeLine{\ \ \ elm\_object\_text\_set(bt,\ \textcolor{stringliteral}{"{}Button"{}});}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(bt);}

\end{DoxyCodeInclude}
 Also, we\textquotesingle{}ll need a toolbar widget, obviously\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ tb\ =\ \mbox{\hyperlink{group__Elm__Toolbar_ga5132198a651cc7a87bde22d5a707f9a5}{elm\_toolbar\_add}}(win);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Toolbar_ga31deb1999afd41648100d3e816c69553}{elm\_toolbar\_shrink\_mode\_set}}(tb,\ ELM\_TOOLBAR\_SHRINK\_SCROLL);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga9379629ad8ad2860aa786d838a4a106a}{evas\_object\_size\_hint\_weight\_set}}(tb,\ 0.0,\ 0.0);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gaaf1d3e26e36b316977336066b6f56632}{evas\_object\_size\_hint\_align\_set}}(tb,\ \mbox{\hyperlink{Evas__Common_8h_aecbac710f36d52911fc34dcdaf8e729c}{EVAS\_HINT\_FILL}},\ 0.0);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(tb);}

\end{DoxyCodeInclude}
 When appending an item is possible to set an icon, label, and a callback function that will receive passed data. 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Toolbar_ga0e6a56df529b9d7e8dbc3d17613b9b22}{elm\_toolbar\_item\_append}}(tb,\ \textcolor{stringliteral}{"{}document-\/print"{}},\ \textcolor{stringliteral}{"{}Print"{}},\ \_item\_1\_pressed,\ bt);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Toolbar_ga0e6a56df529b9d7e8dbc3d17613b9b22}{elm\_toolbar\_item\_append}}(tb,\ \textcolor{stringliteral}{"{}folder-\/new"{}},\ \textcolor{stringliteral}{"{}New\ Folder"{}},\ \_item\_2\_pressed,\ bt);}

\end{DoxyCodeInclude}
 It\textquotesingle{}s possible to disable items, so the user can\textquotesingle{}t select then. We will disable the third item\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ tb\_it\ =\ \mbox{\hyperlink{group__Elm__Toolbar_ga0e6a56df529b9d7e8dbc3d17613b9b22}{elm\_toolbar\_item\_append}}(tb,\ \textcolor{stringliteral}{"{}mail-\/send"{}},\ \textcolor{stringliteral}{"{}Create\ and\ send\ email"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_item\_3\_pressed,\ bt);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__General_ga1d4c8d3c83ed9408eaa35d605adbd7d2}{elm\_object\_item\_disabled\_set}}(tb\_it,\ \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}});}

\end{DoxyCodeInclude}
 Our callbacks will just set button\textquotesingle{}s label\+:  
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_item\_2\_pressed(\textcolor{keywordtype}{void}\ *data,\ Evas\_Object\ *obj\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},\ \textcolor{keywordtype}{void}\ *event\_info\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ Evas\_Object\ *bt\ =\ data;}
\DoxyCodeLine{\ \ \ elm\_object\_text\_set(bt,\ \textcolor{stringliteral}{"{}Create\ new\ folder"{}});}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_item\_3\_pressed(\textcolor{keywordtype}{void}\ *data,\ Evas\_Object\ *obj\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},\ \textcolor{keywordtype}{void}\ *event\_info\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ This\ function\ won't\ be\ called\ because\ we\ disabled\ item\ that\ call\ it\ */}}
\DoxyCodeLine{\ \ \ Evas\_Object\ *bt\ =\ data;}
\DoxyCodeLine{\ \ \ elm\_object\_text\_set(bt,\ \textcolor{stringliteral}{"{}Create\ and\ send\ email"{}});}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{EAPI\_MAIN\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{elm\_main(\textcolor{keywordtype}{int}\ argc\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},\ \textcolor{keywordtype}{char}\ **argv\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ Evas\_Object\ *win,\ *bx,\ *tb,\ *bt;}
\DoxyCodeLine{\ \ \ Elm\_Object\_Item\ *tb\_it;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__General_ga7a05f37fd3a019da5e26c5fc91fcd937}{elm\_policy\_set}}(\mbox{\hyperlink{group__Elm__General_ggaa16f3378ecdbf660fa378402e3c5a0a9a02fadb6faada04b19d0fa42c11a8d32a}{ELM\_POLICY\_QUIT}},\ \mbox{\hyperlink{group__Elm__General_gga46af37e6ac2c406321060be827117196abbe0962d88ae12afe1a173da881f56cd}{ELM\_POLICY\_QUIT\_LAST\_WINDOW\_CLOSED}});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ win\ =\ \mbox{\hyperlink{group__Elm__Win__Group_ga23d9d1ffa0a65a1a1dd482d570db1ba0}{elm\_win\_util\_standard\_add}}(\textcolor{stringliteral}{"{}toolbar"{}},\ \textcolor{stringliteral}{"{}Toolbar\ Example"{}});}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Win__Group_ga9a16a2f8c9fd5b6e9203ed9dcb53ea8b}{elm\_win\_autodel\_set}}(win,\ \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ bx\ =\ \mbox{\hyperlink{group__Elm__Box__Group_ga49ec615c90bf8bead2158d5ffab2e445}{elm\_box\_add}}(win);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga9379629ad8ad2860aa786d838a4a106a}{evas\_object\_size\_hint\_weight\_set}}(bx,\ \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}},\ \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}});}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Win__Group_ga505d6bd217e5ee01e82b548ec35986eb}{elm\_win\_resize\_object\_add}}(win,\ bx);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(bx);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ bt\ =\ \mbox{\hyperlink{group__Elm__Button_gaf5caf46d74c4e122a18da323935d25e4}{elm\_button\_add}}(win);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga9379629ad8ad2860aa786d838a4a106a}{evas\_object\_size\_hint\_weight\_set}}(bt,\ \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}},\ \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}});}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gaaf1d3e26e36b316977336066b6f56632}{evas\_object\_size\_hint\_align\_set}}(bt,\ \mbox{\hyperlink{Evas__Common_8h_aecbac710f36d52911fc34dcdaf8e729c}{EVAS\_HINT\_FILL}},\ \mbox{\hyperlink{Evas__Common_8h_aecbac710f36d52911fc34dcdaf8e729c}{EVAS\_HINT\_FILL}});}
\DoxyCodeLine{\ \ \ elm\_object\_text\_set(bt,\ \textcolor{stringliteral}{"{}Button"{}});}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(bt);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ tb\ =\ \mbox{\hyperlink{group__Elm__Toolbar_ga5132198a651cc7a87bde22d5a707f9a5}{elm\_toolbar\_add}}(win);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Toolbar_ga31deb1999afd41648100d3e816c69553}{elm\_toolbar\_shrink\_mode\_set}}(tb,\ ELM\_TOOLBAR\_SHRINK\_SCROLL);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga9379629ad8ad2860aa786d838a4a106a}{evas\_object\_size\_hint\_weight\_set}}(tb,\ 0.0,\ 0.0);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gaaf1d3e26e36b316977336066b6f56632}{evas\_object\_size\_hint\_align\_set}}(tb,\ \mbox{\hyperlink{Evas__Common_8h_aecbac710f36d52911fc34dcdaf8e729c}{EVAS\_HINT\_FILL}},\ 0.0);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(tb);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Toolbar_ga0e6a56df529b9d7e8dbc3d17613b9b22}{elm\_toolbar\_item\_append}}(tb,\ \textcolor{stringliteral}{"{}document-\/print"{}},\ \textcolor{stringliteral}{"{}Print"{}},\ \_item\_1\_pressed,\ bt);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Toolbar_ga0e6a56df529b9d7e8dbc3d17613b9b22}{elm\_toolbar\_item\_append}}(tb,\ \textcolor{stringliteral}{"{}folder-\/new"{}},\ \textcolor{stringliteral}{"{}New\ Folder"{}},\ \_item\_2\_pressed,\ bt);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ tb\_it\ =\ \mbox{\hyperlink{group__Elm__Toolbar_ga0e6a56df529b9d7e8dbc3d17613b9b22}{elm\_toolbar\_item\_append}}(tb,\ \textcolor{stringliteral}{"{}mail-\/send"{}},\ \textcolor{stringliteral}{"{}Create\ and\ send\ email"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_item\_3\_pressed,\ bt);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__General_ga1d4c8d3c83ed9408eaa35d605adbd7d2}{elm\_object\_item\_disabled\_set}}(tb\_it,\ \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Toolbar_ga094182b18f7eec5181dc1448ca292406}{elm\_toolbar\_homogeneous\_set}}(tb,\ \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Box__Group_ga66a10dd861578521af2ab7b8c2ca65c5}{elm\_box\_pack\_end}}(bx,\ tb);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Box__Group_ga66a10dd861578521af2ab7b8c2ca65c5}{elm\_box\_pack\_end}}(bx,\ bt);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_gacad94595f83580c18908cb3b69b08d1a}{evas\_object\_resize}}(win,\ 200,\ 200);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(win);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__General_gadf2553f83e6b0b9c7fbe054019a664a1}{elm\_run}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 By default, toolbars would display items homogeneously, so item with long labels, like the third, will make all of them occupy a lot of space. To avoid that, we can disable it\+:  
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Toolbar_ga094182b18f7eec5181dc1448ca292406}{elm\_toolbar\_homogeneous\_set}}(tb,\ \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}});}

\end{DoxyCodeInclude}
 Another default behavior, is to add an menu item if we have more items that would fit on toolbar size. To simply enable scroll, without menus, it\textquotesingle{}s required to change toolbar\textquotesingle{}s shrink mode\+:  
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Toolbar_ga31deb1999afd41648100d3e816c69553}{elm\_toolbar\_shrink\_mode\_set}}(tb,\ ELM\_TOOLBAR\_SHRINK\_SCROLL);}

\end{DoxyCodeInclude}
 See \doxylink{toolbar_example_01_8c-example}{toolbar\+\_\+example\+\_\+01.c}, whose window should look like this picture\+:

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