\section{codegen\-\_\-example.\-c}

\begin{DoxyCodeInclude}

\textcolor{preprocessor}{#include "codegen\_example\_generated.h"}

\textcolor{keyword}{static} Eina\_Bool \_btn\_large = EINA\_FALSE;

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_swallow\_btn\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *btn, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *layout = data;

   \textcolor{keywordflow}{if} (\_btn\_large == EINA\_FALSE)
     \{
        \_btn\_large = EINA\_TRUE;
        codegen\_example\_swallow\_grow\_emit(layout);
        elm\_object\_text\_set(btn, \textcolor{stringliteral}{"Reduce me!"});
        \textcolor{keywordflow}{if} (!codegen\_example\_table\_clear(layout, EINA\_TRUE))
          fprintf(stderr, \textcolor{stringliteral}{"Could not remove the items from the table!\(\backslash\)n"});
     \}
   \textcolor{keywordflow}{else}
     \{
        \_btn\_large = EINA\_FALSE;
        codegen\_example\_swallow\_shrink\_emit(layout);
        elm\_object\_text\_set(btn, \textcolor{stringliteral}{"Enlarge me!"});
     \}
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_size\_changed\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *layout, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *emission, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *source)
\{
   Evas\_Object *edje;
   Evas\_Coord w, h;

   elm_layout_sizing_eval(layout);
   edje = elm_layout_edje_get(layout);
   edje\_object\_size\_min\_calc(edje, &w, &h);
   printf(\textcolor{stringliteral}{"Minimum size for this theme: %dx%d\(\backslash\)n"}, w, h);
\}

\textcolor{keyword}{static} Evas\_Object *
\_button\_create(Evas\_Object *parent, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *label)
\{
   Evas\_Object *btn;
   btn = elm_button_add(parent);
   \textcolor{keywordflow}{if} (!btn) \textcolor{keywordflow}{return} NULL;

   elm\_object\_text\_set(btn, label);
   evas\_object\_size\_hint\_weight\_set(btn, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(btn, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);

   \textcolor{keywordflow}{return} btn;
\}

EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   Evas\_Object *win, *btn, *layout, *tbl\_items[6];
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *labels[] = \{\textcolor{stringliteral}{"One"}, \textcolor{stringliteral}{"Two"}, \textcolor{stringliteral}{"Three"}, \textcolor{stringliteral}{"Four"}, \textcolor{stringliteral}{"Five"}, \textcolor{stringliteral}{"Six"}\};
   \textcolor{keywordtype}{int} i;

   elm_app_info_set(elm\_main, \textcolor{stringliteral}{"elementary"}, \textcolor{stringliteral}{"examples/codegen\_example.edj"});

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"codegen"}, \textcolor{stringliteral}{"Elementary CodeGen"});
   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
   elm_win_autodel_set(win, EINA\_TRUE);

   \textcolor{comment}{// Adding layout}
   layout = codegen\_example\_layout\_add(win, NULL, NULL);
   \textcolor{keywordflow}{if} (!layout)
     \{
        printf(\textcolor{stringliteral}{"Could not create the layout\(\backslash\)n"});
        \textcolor{keywordflow}{return} -1;
     \}

   evas\_object\_size\_hint\_weight\_set(layout, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_win_resize_object_add(win, layout);
   evas\_object\_show(layout);

   codegen\_example\_size\_changed\_callback\_add(layout, \_size\_changed\_cb, layout);

   \textcolor{comment}{// Setting title}
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *title = codegen\_example\_title\_get(layout);
   \textcolor{keywordflow}{if} (title)
     \{
        elm_win_title_set(win, title);
        codegen\_example\_title\_set(layout, title);
     \}

   btn = \_button\_create(win, \textcolor{stringliteral}{"Enlarge me!"});
   codegen\_example\_custom\_set(layout, btn);
   evas\_object\_smart\_callback\_add(btn, \textcolor{stringliteral}{"clicked"}, \_swallow\_btn\_cb, layout);

   \textcolor{keywordflow}{for} (i = 0; i < 6; i++)
     \{
        tbl\_items[i] = \_button\_create(win, labels[i]);
        \textcolor{keywordflow}{if} (i < 3)
          \{
             \textcolor{keywordflow}{if} (!codegen\_example\_table\_pack(layout, tbl\_items[i], i, i, 1,1))
               fprintf(stderr, \textcolor{stringliteral}{"Could not add the button to the table!\(\backslash\)n"});
          \}
        \textcolor{keywordflow}{else}
          \{
             \textcolor{keywordflow}{if} (!codegen\_example\_box\_append(layout, tbl\_items[i]))
               fprintf(stderr, \textcolor{stringliteral}{"Could not add the button to the box!\(\backslash\)n"});
          \}

        evas\_object\_show(tbl\_items[i]);
     \}

   evas\_object\_resize(win, 500, 600);
   evas\_object\_show(win);

   elm_run();
   elm_shutdown();

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