0.7 setting layout in containers

Started by Heinrich, 10 October 2014, 14:17:50

Heinrich

It think it would really come in handy to have a method that specifies how child widgets should be positioned (e.g. center horizontally, center vertically, default=none). In my use case, I have a Panel and a Grid inside this Panel, now I want to have the Grid centered inside the panel.
Also: Grid has a method for changing the alignment of a widget inside one cell, for convenience, a method to change every cell would be nice.  However, I may be overseeing some possibilities tgui provides.

texus

QuoteIt think it would really come in handy to have a method that specifies how child widgets should be positioned
It can be done already with 0.7, but not in a very short and easy way.

TGUI 0.7 is the first version where there is some decent layouting, so its not really as great as it should be.
Its important to understand that the Grid widget was added in v0.5 to provide a simple way to put some buttons below or next to each other. It was never intended to be advanced and it has not yet been rewritten to provide more functionality.

With the layout system, this is how you currently would center a picture in the gui:
Code (cpp) Select
picture->setPosition((tgui::bindWidth(gui) - tgui::bindWidth(picture)) / 2.0f, (tgui::bindHeight(gui) - tgui::bindHeight(picture)) / 2.0f);

Centering the grid in a panel will become:
Code (cpp) Select
grid->setPosition((tgui::bindWidth(*panel) - tgui::bindWidth(grid)) / 2.0f, (tgui::bindHeight(*panel) - tgui::bindHeight(grid)) / 2.0f);

Of course it would be nice if it was simpler, most lines with these bind functions can get quite long, but this is the only way so far to do it.

PS: The layout system was not tested yet with complex widgets like Grid, I hope the code above will actually work.