

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\+PI 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_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_ga0021b9d86d822367035843ed18bc6ea9}{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}} *)elm\_box\_children\_get(tdata-\/>box);}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (children)}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        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_ga608bd2fbf06293a1b794648990703ab4}{eina\_list\_free}}(children);}
\DoxyCodeLine{     \}}
\DoxyCodeLine{   \textcolor{keywordflow}{else}}
\DoxyCodeLine{     elm\_box\_pack\_end(tdata-\/>box, btn);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{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{   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{   elm\_box\_unpack(tdata-\/>box, obj);}
\DoxyCodeLine{   evas\_object\_move(obj, 0, 50);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{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_ga7e7a625dab7a3890532aa13b43117076}{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_ga9cd35aa22988c800aa981f25ada92ced}{Elm\+\_\+\+Box\+\_\+\+Transition}} to use with \mbox{\hyperlink{group__Elm__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}{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_gad3ef5177a00dcda0c08c86287419d5b5}{Evas\_Object\_Box\_Layout}} next\_layout;}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (!data) \textcolor{keywordflow}{return};}
\DoxyCodeLine{   next\_layout = \mbox{\hyperlink{group__Eina__List__Group_gaec845f0bfb16a14e8d7f0cd508ca7e9c}{eina\_list\_data\_get}}(tdata-\/>transitions);}
\DoxyCodeLine{   layout\_data = \mbox{\hyperlink{group__Elm__Box_ga4a70cd7719f20a6d60e4abdf57eeca4e}{elm\_box\_transition\_new}}(2.0, tdata-\/>last\_layout,}
\DoxyCodeLine{                                        NULL, NULL, next\_layout, NULL, NULL,}
\DoxyCodeLine{                                        \_test\_box\_transition\_change, tdata);}
\DoxyCodeLine{   elm\_box\_layout\_set(tdata-\/>box, \mbox{\hyperlink{group__Elm__Box_ga15194ef319ae722b03f608373f90fe1f}{elm\_box\_layout\_transition}}, layout\_data,}
\DoxyCodeLine{                      \mbox{\hyperlink{group__Elm__Box_gab7b726e4dbfb80da529431d198add95e}{elm\_box\_transition\_free}});}
\DoxyCodeLine{   tdata-\/>last\_layout = next\_layout;}
\DoxyCodeLine{}
\DoxyCodeLine{   tdata-\/>transitions = \mbox{\hyperlink{group__Eina__List__Group_ga082644881a2333bd16208c00931703cd}{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 = evas\_object\_box\_layout\_horizontal;}
\DoxyCodeLine{   tdata.transitions = \mbox{\hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}}(tdata.transitions,}
\DoxyCodeLine{                                        evas\_object\_box\_layout\_vertical);}
\DoxyCodeLine{   tdata.transitions = \mbox{\hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}}(tdata.transitions,}
\DoxyCodeLine{                                        evas\_object\_box\_layout\_horizontal);}
\DoxyCodeLine{   tdata.transitions = \mbox{\hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}}(tdata.transitions,}
\DoxyCodeLine{                                        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_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}}(tdata.transitions,}
\DoxyCodeLine{                                        evas\_object\_box\_layout\_homogeneous\_vertical);}
\DoxyCodeLine{   tdata.transitions = \mbox{\hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}}(tdata.transitions,}
\DoxyCodeLine{                                        evas\_object\_box\_layout\_homogeneous\_horizontal);}
\DoxyCodeLine{   tdata.transitions = \mbox{\hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}}(tdata.transitions,}
\DoxyCodeLine{                                        evas\_object\_box\_layout\_flow\_vertical);}
\DoxyCodeLine{   tdata.transitions = \mbox{\hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}}(tdata.transitions,}
\DoxyCodeLine{                                        evas\_object\_box\_layout\_flow\_horizontal);}
\DoxyCodeLine{   tdata.transitions = \mbox{\hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}}(tdata.transitions,}
\DoxyCodeLine{                                        evas\_object\_box\_layout\_stack);}
\DoxyCodeLine{}
\DoxyCodeLine{   elm\_box\_layout\_set(bx, 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}}. 