

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 API that was left untouched in our \mbox{\hyperlink{box_example_01}{previous example}}.

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



\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\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}{0}
\DoxyCodeLine{\textcolor{keyword}{typedef}\ \textcolor{keyword}{struct}}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Eina__List}{Eina\_List}}\ *transitions;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}}\ *box;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Box__Group_gad3ef5177a00dcda0c08c86287419d5b5}{Evas\_Object\_Box\_Layout}}\ last\_layout;}
\DoxyCodeLine{\}\ 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}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_add\_cb(\textcolor{keywordtype}{void}\ *data,\ \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}}\ *obj\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},\ \textcolor{keywordtype}{void}\ *ev\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}}\ *btn;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Eina__List}{Eina\_List}}\ *children;}
\DoxyCodeLine{\ \ \ Transitions\_Data\ *tdata\ =\ data;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ btn\ =\ \mbox{\hyperlink{group__Elm__Button_gaf5caf46d74c4e122a18da323935d25e4}{elm\_button\_add}}(tdata-\/>box);}
\DoxyCodeLine{\ \ \ elm\_object\_text\_set(btn,\ \textcolor{stringliteral}{"{}I\ do\ nothing"{}});}
\DoxyCodeLine{\ \ \ children\ =\ (\mbox{\hyperlink{struct__Eina__List}{Eina\_List}}\ *)\mbox{\hyperlink{group__Elm__Box__Group_ga0b17b6350e5310dc3c94635ddf399961}{elm\_box\_children\_get}}(tdata-\/>box);}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (children)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Elm__Box__Group_ga45b459590ae168019243ca5742931e16}{elm\_box\_pack\_after}}(tdata-\/>box,\ btn,\ (\mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}}\ *)children-\/>\mbox{\hyperlink{struct__Eina__List_a043e22d601d3a0504f30255a43a25e7a}{data}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Eina__List__Group_ga82a1bfa543e21853f9ea3ff88dd1250b}{eina\_list\_free}}(children);}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{else}}
\DoxyCodeLine{\ \ \ \ \ \mbox{\hyperlink{group__Elm__Box__Group_ga66a10dd861578521af2ab7b8c2ca65c5}{elm\_box\_pack\_end}}(tdata-\/>box,\ btn);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga07208fcafd4739de606bc35fff684bf5}{evas\_object\_show}}(btn);}
\DoxyCodeLine{\}}

\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}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_clear\_cb(\textcolor{keywordtype}{void}\ *data,\ \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}}\ *obj\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},\ \textcolor{keywordtype}{void}\ *ev\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ Transitions\_Data\ *tdata\ =\ data;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Box__Group_ga4616b670f386ab6ddfddce9433c62c08}{elm\_box\_clear}}(tdata-\/>box);}
\DoxyCodeLine{\}}

\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}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_unpack\_cb(\textcolor{keywordtype}{void}\ *data,\ \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}}\ *obj,\ \textcolor{keywordtype}{void}\ *ev\ \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ Transitions\_Data\ *tdata\ =\ data;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Box__Group_ga2c4fb2f04cb3d55e07ca04c21fd958fd}{elm\_box\_unpack}}(tdata-\/>box,\ obj);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group_ga335c8ee6eaeaac9710656af4f8b0db91}{evas\_object\_move}}(obj,\ 0,\ 50);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Group__Basic_gab751e9d24c16e74af6f7c08ea5b930c2}{evas\_object\_color\_set}}(obj,\ 128,\ 64,\ 0,\ 128);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 If we wanted, we could just call {\ttfamily \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9217cf1d90690dbd1960db155d1c7476}{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 \mbox{\hyperlink{group__Elm__Box__Group_ga9cd35aa22988c800aa981f25ada92ced}{Elm\+\_\+\+Box\+\_\+\+Transition}} to use with \mbox{\hyperlink{group__Elm__Box__Group_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}{0}
\DoxyCodeLine{\textcolor{keyword}{static}\ \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_test\_box\_transition\_change(\textcolor{keywordtype}{void}\ *data)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ Transitions\_Data\ *tdata\ =\ data;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{struct__Elm__Box__Transition}{Elm\_Box\_Transition}}\ *layout\_data;}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Evas__Object__Box__Group_gad3ef5177a00dcda0c08c86287419d5b5}{Evas\_Object\_Box\_Layout}}\ next\_layout;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!data)\ \textcolor{keywordflow}{return};}
\DoxyCodeLine{\ \ \ next\_layout\ =\ eina\_list\_data\_get(tdata-\/>transitions);}
\DoxyCodeLine{\ \ \ layout\_data\ =\ \mbox{\hyperlink{group__Elm__Box__Group_ga50fabb86b0ddcc8af447b03b9c3562d1}{elm\_box\_transition\_new}}(2.0,\ tdata-\/>last\_layout,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ NULL,\ NULL,\ next\_layout,\ NULL,\ NULL,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_test\_box\_transition\_change,\ tdata);}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Box__Group_ga964ff6e51c328ed9e9a64c73f9e2a21f}{elm\_box\_layout\_set}}(tdata-\/>box,\ \mbox{\hyperlink{group__Elm__Box__Group_ga15194ef319ae722b03f608373f90fe1f}{elm\_box\_layout\_transition}},\ layout\_data,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Elm__Box__Group_gab7b726e4dbfb80da529431d198add95e}{elm\_box\_transition\_free}});}
\DoxyCodeLine{\ \ \ tdata-\/>last\_layout\ =\ next\_layout;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ tdata-\/>transitions\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga33dc7f75dae277326c99ad5939861613}{eina\_list\_demote\_list}}(tdata-\/>transitions,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ tdata-\/>transitions);}
\DoxyCodeLine{\}}

\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}{0}
\DoxyCodeLine{\ \ \ tdata.box\ =\ bx;}
\DoxyCodeLine{\ \ \ tdata.last\_layout\ =\ \mbox{\hyperlink{group__Evas__Object__Box__Group_gaaaaf1c9ba2bd49e51108c1202aea9c3c}{evas\_object\_box\_layout\_horizontal}};}
\DoxyCodeLine{\ \ \ tdata.transitions\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga625698a383dda8fc0db245a1c7608c49}{eina\_list\_append}}(tdata.transitions,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Evas__Object__Box__Group_ga8836b5287edf32f687e2ad05a140e836}{evas\_object\_box\_layout\_vertical}});}
\DoxyCodeLine{\ \ \ tdata.transitions\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga625698a383dda8fc0db245a1c7608c49}{eina\_list\_append}}(tdata.transitions,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Evas__Object__Box__Group_gaaaaf1c9ba2bd49e51108c1202aea9c3c}{evas\_object\_box\_layout\_horizontal}});}
\DoxyCodeLine{\ \ \ tdata.transitions\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga625698a383dda8fc0db245a1c7608c49}{eina\_list\_append}}(tdata.transitions,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Evas__Object__Box__Group_gabbf12730358c40b99a4152dbe104b35e}{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}{0}
\DoxyCodeLine{\ \ \ tdata.transitions\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga625698a383dda8fc0db245a1c7608c49}{eina\_list\_append}}(tdata.transitions,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Evas__Object__Box__Group_ga02e09abf4c39068f6922f9077149c131}{evas\_object\_box\_layout\_homogeneous\_vertical}});}
\DoxyCodeLine{\ \ \ tdata.transitions\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga625698a383dda8fc0db245a1c7608c49}{eina\_list\_append}}(tdata.transitions,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Evas__Object__Box__Group_ga5fe32364de114ac27926faf36a92565f}{evas\_object\_box\_layout\_homogeneous\_horizontal}});}
\DoxyCodeLine{\ \ \ tdata.transitions\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga625698a383dda8fc0db245a1c7608c49}{eina\_list\_append}}(tdata.transitions,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Evas__Object__Box__Group_ga5e4ae5bcafc724706824418969faeb7f}{evas\_object\_box\_layout\_flow\_vertical}});}
\DoxyCodeLine{\ \ \ tdata.transitions\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga625698a383dda8fc0db245a1c7608c49}{eina\_list\_append}}(tdata.transitions,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Evas__Object__Box__Group_ga92c45845c149cc21fab4fcfd4e7839eb}{evas\_object\_box\_layout\_flow\_horizontal}});}
\DoxyCodeLine{\ \ \ tdata.transitions\ =\ \mbox{\hyperlink{group__Eina__List__Group_ga625698a383dda8fc0db245a1c7608c49}{eina\_list\_append}}(tdata.transitions,}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Evas__Object__Box__Group_gabbf12730358c40b99a4152dbe104b35e}{evas\_object\_box\_layout\_stack}});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Elm__Box__Group_ga964ff6e51c328ed9e9a64c73f9e2a21f}{elm\_box\_layout\_set}}(bx,\ \mbox{\hyperlink{group__Evas__Object__Box__Group_gaaaaf1c9ba2bd49e51108c1202aea9c3c}{evas\_object\_box\_layout\_horizontal}},\ NULL,\ NULL);}
\DoxyCodeLine{\ \ \ \_test\_box\_transition\_change(\&tdata);}

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