Loading data from file for Grid
« on: 28 March 2014, 11:33:33 »

I'm using TGUI in my project, which is set to load the widgets from a file.
I noticed that when loading widgets from a file, there is no way to pass information about the rows, columns, borders and Layout, in which you put the widgets in the control Grid.

It blocks my project, would you consider adding this feature to TGUI?



  • *****
  • 1151
    • View Profile
    • Texus's Blog
Re: Loading data from file for Grid
« Reply #1 on: 28 March 2014, 11:54:27 »
I've looked into it, but there doesn't seem to be an easy way to add this.
Loading widgets from a file is still something that is far from being perfect, but I can't immediately do much about it.

I'm afraid you will have to solve it in your c++ code. (GridName, ButtonName1 and ButtonName2 are the names of the widgets in the file)
Code: [Select]
tgui::Grid::Ptr grid = gui.get("GridName");
grid->addWidget(grid.get("ButtonName1"), 1, 2);
grid->addWidget(grid.get("ButtonName2"), 2, 0);

But of course doing that for all widgets might be a bit long and requires a bit too much hardcoding. So maybe you can do it in another way, using the knowledge that the widgets in the grid are in the same order as they are defined in the file. When you e.g. have a 3x4 grid you can do this:
Code: [Select]
tgui::Grid::Ptr grid = gui.get("GridName");
auto& widgets = grid.getWidgets();
for (unsigned int row = 0; row < 3; ++row) {
    for (unsigned int col = 0; col < 4; ++col) {
        grid->addWidget(widgets[row*4 + col], row, col);

(Codes were written without testing)
« Last Edit: 28 March 2014, 11:56:12 by texus »