\section{box\-\_\-example\-\_\-02.\-c}

\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{//gcc -g box\_example\_02.c -o box\_example\_02 `pkg-config --cflags --libs elementary`}

\textcolor{preprocessor}{#include <Elementary.h>}

\textcolor{keyword}{typedef} \textcolor{keyword}{struct}
\{
   Eina\_List *transitions;
   Evas\_Object *box;
   Evas\_Object\_Box\_Layout last\_layout;
\} Transitions\_Data;

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_add\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *ev)
\{
   Evas\_Object *btn;
   Eina\_List *children;
   Transitions\_Data *tdata = data;

   btn = elm_button_add(tdata->box);
   elm\_object\_text\_set(btn, \textcolor{stringliteral}{"I do nothing"});
   children = (Eina\_List *)elm_box_children_get(tdata->box);
   \textcolor{keywordflow}{if} (children)
     \{
        elm_box_pack_after(tdata->box, btn, (Evas\_Object *)children->data);
        eina\_list\_free(children);
     \}
   \textcolor{keywordflow}{else}
     elm_box_pack_end(tdata->box, btn);
   evas\_object\_show(btn);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_clear\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *ev)
\{
   Transitions\_Data *tdata = data;
   elm_box_clear(tdata->box);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_unpack\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *ev)
\{
   Transitions\_Data *tdata = data;
   elm_box_unpack(tdata->box, obj);
   evas\_object\_move(obj, 0, 50);
   evas\_object\_color\_set(obj, 128, 64, 0, 128);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_test\_box\_transition\_change(\textcolor{keywordtype}{void} *data)
\{
   Transitions\_Data *tdata = data;
   Elm\_Box\_Transition *layout\_data;
   Evas\_Object\_Box\_Layout next\_layout;

   \textcolor{keywordflow}{if} (!data) \textcolor{keywordflow}{return};
   next\_layout = eina\_list\_data\_get(tdata->transitions);
   layout\_data = elm_box_transition_new(2.0, tdata->last\_layout,
                                        NULL, NULL, next\_layout, NULL, NULL,
                                        \_test\_box\_transition\_change, tdata);
   elm_box_layout_set(tdata->box, elm_box_layout_transition, layout\_data,
                      elm_box_transition_free);
   tdata->last\_layout = next\_layout;

   tdata->transitions = eina\_list\_demote\_list(tdata->transitions,
                                              tdata->transitions);
\}

EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} *argv[])
\{
   Evas\_Object *win, *bigbox, *bx, *bt;
   \textcolor{keyword}{static} Transitions\_Data tdata = \{
        .transitions = NULL,
        .box = NULL,
        .last\_layout = NULL
   \};

   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"box-transition"}, \textcolor{stringliteral}{"Box Transition"});
   elm_win_autodel_set(win, EINA\_TRUE);
   evas\_object\_resize(win, 300, 320);
   evas\_object\_show(win);

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

   bx = elm_box_add(win);
   elm_box_horizontal_set(bx, EINA\_TRUE);
   elm_box_pack_end(bigbox, bx);
   evas\_object\_show(bx);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Add"});
   elm_box_pack_end(bx, bt);
   evas\_object\_show(bt);
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_add\_cb, &tdata);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Clear"});
   elm_box_pack_end(bx, bt);
   evas\_object\_show(bt);
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_clear\_cb, &tdata);

   bx = elm_box_add(win);
   evas\_object\_size\_hint\_weight\_set(bx, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(bx, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_box_pack_end(bigbox, bx);
   evas\_object\_show(bx);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Button 1"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_unpack\_cb, &tdata);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_box_pack_end(bx, bt);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Button 2"});
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, 0.0);
   evas\_object\_size\_hint\_align\_set(bt, 1.0, 0.5);
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_unpack\_cb, &tdata);
   elm_box_pack_end(bx, bt);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Button 3"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_unpack\_cb, &tdata);
   elm_box_pack_end(bx, bt);
   evas\_object\_show(bt);

   tdata.box = bx;
   tdata.last\_layout = evas\_object\_box\_layout\_horizontal;
   tdata.transitions = eina\_list\_append(tdata.transitions,
                                        evas\_object\_box\_layout\_vertical);
   tdata.transitions = eina\_list\_append(tdata.transitions,
                                        evas\_object\_box\_layout\_horizontal);
   tdata.transitions = eina\_list\_append(tdata.transitions,
                                        evas\_object\_box\_layout\_stack);
   tdata.transitions = eina\_list\_append(tdata.transitions,
                                        evas\_object\_box\_layout\_homogeneous\_vertical);
   tdata.transitions = eina\_list\_append(tdata.transitions,
                                        evas\_object\_box\_layout\_homogeneous\_horizontal);
   tdata.transitions = eina\_list\_append(tdata.transitions,
                                        evas\_object\_box\_layout\_flow\_vertical);
   tdata.transitions = eina\_list\_append(tdata.transitions,
                                        evas\_object\_box\_layout\_flow\_horizontal);
   tdata.transitions = eina\_list\_append(tdata.transitions,
                                        evas\_object\_box\_layout\_stack);

   elm_box_layout_set(bx, evas\_object\_box\_layout\_horizontal, NULL, NULL);
   \_test\_box\_transition\_change(&tdata);

   elm_run();
   elm_shutdown();

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