Setting a customized layout for a box is simple once you have the layout function, which is just like the layout function for
Evas_Box. The new and fancier thing we can do with Elementary is animate the transition from one layout to the next. We'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 previous example.
Our application data consists of a list of layout functions, given by
transitions. We'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.
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'll be using creates a new button, asks the box for the list of its children and if it'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.
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.
And a little function to remove buttons from the box without deleting them. This one is set for the
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.
If we wanted, we could just call
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
last_layout, it creates an Elm_Box_Transition to use with 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.
The main function doesn'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.
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.
For the full code, follow here.