

Setting a customized layout for a box is simple once you have the layout function, which is just like the layout function for {\ttfamily Evas\+\_\+\+Box}. The new and fancier thing we can do with Elementary is animate the transition from one layout to the next. We\textquotesingle{}ll see now how to do that through a simple example, while also taking a look at some of the A\+P\+I that was left untouched in our \hyperlink{box_example_01}{previous example}.

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



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

\end{DoxyCodeInclude}


Our application data consists of a list of layout functions, given by {\ttfamily transitions}. We\textquotesingle{}ll be animating through them throughout the entire run. The box with the stuff to move around and the last layout that was set to make things easier in the code. 
\begin{DoxyCodeInclude}
\textcolor{keyword}{typedef} \textcolor{keyword}{struct}
\{
   Eina\_List *transitions;
   Evas\_Object *box;
   Evas\_Object\_Box\_Layout last\_layout;
\} Transitions\_Data;

\end{DoxyCodeInclude}


The box starts with three buttons, clicking on any of them will take it out of the box without deleting the object. There are also two more buttons outside, one to add an object to the box and the other to clear it. This is all to show how you can interact with the items in the box, add things and even remove them, while the transitions occur.

One of the callback we\textquotesingle{}ll be using creates a new button, asks the box for the list of its children and if it\textquotesingle{}s not empty, we add the new object after the first one, otherwise just place at the end as it will not make any difference. 
\begin{DoxyCodeInclude}
\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);
\}

\end{DoxyCodeInclude}


The clear button is even simpler. Everything in the box will be deleted, leaving it empty and ready to fill it up with more stuff. 
\begin{DoxyCodeInclude}
\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);
\}

\end{DoxyCodeInclude}


And a little function to remove buttons from the box without deleting them. This one is set for the {\ttfamily clicked} callback of the original buttons, unpacking them when clicked and placing it somewhere in the screen where they will not disturb. Once we do this, the box no longer has any control of it, so it will be left untouched until the program ends. 
\begin{DoxyCodeInclude}
\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);
\}

\end{DoxyCodeInclude}


If we wanted, we could just call {\ttfamily evas\+\_\+object\+\_\+del()} on the object to destroy it. In this case, no unpack is really necessary, as the box would be notified of a child being deleted and adjust its calculations accordingly.

The core of the program is the following function. It takes whatever function is first on our list of layouts and together with the {\ttfamily last\+\_\+layout}, it creates an \hyperlink{group__Box_ga9cd35aa22988c800aa981f25ada92ced}{Elm\+\_\+\+Box\+\_\+\+Transition} to use with \hyperlink{group__Box_ga15194ef319ae722b03f608373f90fe1f}{elm\+\_\+box\+\_\+layout\+\_\+transition()}. In here, we tell it to start from whatever layout we last set, end with the one that was at the top of the list and when everything is finished, call us back so we can create another transition. Finally, move the new layout to the end of the list so we can continue running through them until the program ends. 
\begin{DoxyCodeInclude}
\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);
\}

\end{DoxyCodeInclude}


The main function doesn\textquotesingle{}t have anything special. Creation of box, initial buttons and some callback setting. The only part worth mentioning is the initialization of our application data. 
\begin{DoxyCodeInclude}
   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);

\end{DoxyCodeInclude}


We have a simple static variable, set the box, the first layout we are using as last and create the list with the different functions to go through.

And in the end, we set the first layout and call the same function we went through before to start the run of transitions. 
\begin{DoxyCodeInclude}
   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);

\end{DoxyCodeInclude}


For the full code, follow \hyperlink{box_example_02_8c-example}{here}. 