

This example will show 2 checkboxes, one with just a label and the second one with both a label and an icon. This example also illustrates how to have the checkbox change the value of a variable and how to react to those changes.

We will start with the usual setup code\+: 
\begin{DoxyCodeInclude}
EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   Evas\_Object *win, *cb, *cb2, *icon;
   Eina\_Bool value;

   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"check"}, \textcolor{stringliteral}{"Check"});
   elm_win_autodel_set(win, EINA\_TRUE);

\end{DoxyCodeInclude}


And now we create our first checkbox, set its label, tell it to change the value of {\ttfamily value} when the checkbox stats is changed and ask to be notified of state changes\+: 
\begin{DoxyCodeInclude}

   cb = elm_check_add(win);
   elm\_object\_text\_set(cb, \textcolor{stringliteral}{"checkbox"});
   elm_check_state_pointer_set(cb, &value);
   evas\_object\_smart\_callback\_add(cb, \textcolor{stringliteral}{"changed"}, \_print, &value);
   evas\_object\_move(cb, 10, 10);
   evas\_object\_resize(cb, 200, 30);
   evas\_object\_show(cb);

\end{DoxyCodeInclude}


For our second checkbox we are going to set an icon so we need to create and icon\+: 
\begin{DoxyCodeInclude}

   icon = evas\_object\_rectangle\_add(evas\_object\_evas\_get(win));
   evas\_object\_color\_set(icon, 0, 255, 0, 255);
   evas\_object\_resize(icon, 20, 20);
   evas\_object\_show(icon);

\end{DoxyCodeInclude}
 \begin{DoxyNote}{Note}
For simplicity we are using a rectangle as icon, but any evas object can be used.
\end{DoxyNote}
And for our second checkbox we set the label, icon and state to true\+: 
\begin{DoxyCodeInclude}

   cb2 = elm_check_add(win);
   elm\_object\_text\_set(cb2, \textcolor{stringliteral}{"another checkbox"});
   elm_check_state_set(cb2, EINA\_TRUE);
   elm_object_part_content_set(cb2, \textcolor{stringliteral}{"icon"}, icon);
   evas\_object\_move(cb2, 10, 50);
   evas\_object\_resize(cb2, 200, 30);
   evas\_object\_show(cb2);

\end{DoxyCodeInclude}


We now do some more setup\+: 
\begin{DoxyCodeInclude}

   evas\_object\_resize(win, 200, 100);
   evas\_object\_show(win);

   elm_run();

   \textcolor{keywordflow}{return} 0;
\}
ELM_MAIN()

\end{DoxyCodeInclude}


And finally implement the callback that will be called when the first checkbox\textquotesingle{}s state changes. This callback will use {\ttfamily data} to print a message\+:  
\begin{DoxyCodeInclude}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_print(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   printf(\textcolor{stringliteral}{"check %smarked\(\backslash\)n"}, *((Eina\_Bool*)data) ? \textcolor{stringliteral}{""} : \textcolor{stringliteral}{"un"});
\}

\end{DoxyCodeInclude}
 \begin{DoxyNote}{Note}
This work because {\ttfamily data} is {\ttfamily value(from the main function)} and {\ttfamily value} is changed when the checkbox is changed.
\end{DoxyNote}
Our example will look like this\+:

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