texus/TGUI — pull request #4 by gupascal (2013-07-30 13:43:18+00:00)
Title: Added a setSize() function to the grid widget

I implemented the Grid::setSize() function following the description written here : http://forum.tgui.eu/index.php/topic,101.msg361.html#msg361

I used the following code to test (a modified version of the login screen), if it can help you:
(As it was just for test it is not really a clean and well-commented code.)
```cpp
#include

void loadWidgets( tgui::Gui& gui )
{
// Create the background image
tgui::Picture::Ptr picture(gui);
picture->load("../xubuntu_bg_aluminium.jpg");
picture->setSize(800, 600);

// Create the grid
tgui::Grid::Ptr grid(gui);
grid->setSize(800, 600);

// Create the username label
tgui::Label::Ptr labelUsername(*grid);
labelUsername->setText("Username:");

// Create the password label
tgui::Label::Ptr labelPassword(*grid);
labelPassword->setText("Password:");

// Create the username edit box
tgui::EditBox::Ptr editBoxUsername(*grid, "Username");
editBoxUsername->load("../../widgets/Black.conf");
editBoxUsername->setSize(250, 40);

// Create the password edit box (we will copy the previously created edit box)
tgui::EditBox::Ptr editBoxPassword = grid->copy(editBoxUsername, "Password");
editBoxPassword->setPasswordCharacter('*');

// Create the login button
tgui::Button::Ptr button(*grid);
button->load("../../widgets/Black.conf");
button->setSize(260, 60);
button->setText("Login");
button->bindCallback(tgui::Button::LeftMouseClicked);
button->setCallbackId(1);

tgui::Button::Ptr b(*grid);
b->load("../../widgets/Black.conf");
b->setText("100x700");
b->bindCallbackEx([](const tgui::Callback& cb){
static_cast(cb.widget->getParent())->setSize(100,700);
},
tgui::Button::LeftMouseClicked);

tgui::Button::Ptr b2(*grid);
b2->load("../../widgets/Black.conf");
b2->setText("650x450");
b2->bindCallbackEx([](const tgui::Callback& cb){
static_cast(cb.widget->getParent())->setSize(650,400);
},
tgui::Button::LeftMouseClicked);

tgui::Button::Ptr b3(*grid);
b3->load("../../widgets/Black.conf");
b3->setText("800x600");
b3->bindCallbackEx([](const tgui::Callback& cb){
static_cast(cb.widget->getParent())->setSize(800,600);
},
tgui::Button::LeftMouseClicked);

tgui::Button::Ptr b4(*grid);
b4->load("../../widgets/Black.conf");
b4->setText("900x1000");
b4->bindCallbackEx([](const tgui::Callback& cb){
static_cast(cb.widget->getParent())->setSize(900,1000);
},
tgui::Button::LeftMouseClicked);

tgui::Button::Ptr b5(*grid);
b5->load("../../widgets/Black.conf");
b5->setText("AlignRight");
b5->setTextSize(10);
b5->setSize(75, 24);

grid->addWidget(labelUsername, 0, 0);
grid->addWidget(editBoxUsername, 0, 1);
grid->addWidget(labelPassword, 1, 0);
grid->addWidget(editBoxPassword, 1, 1);
grid->addWidget(button, 2, 1);

grid->addWidget(b, 0, 2);
grid->addWidget(b2, 1, 2);
grid->addWidget(b3, 2, 2);
grid->addWidget(b4, 3, 2);

grid->addWidget(b5, 2, 0);
grid->changeWidgetLayout(b5, tgui::Grid::Layout::Layouts::Right);
}

int main()
{
// Create the window
sf::RenderWindow window(sf::VideoMode(800, 600), "TGUI window");
tgui::Gui gui(window);

// Load the font (you should check the return value to make sure that it is loaded)
gui.setGlobalFont("../../fonts/DejaVuSans.ttf");

// Load the widgets
loadWidgets(gui);

// Main loop
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();

// Pass the event to all the widgets
gui.handleEvent(event);
}

// The callback loop
tgui::Callback callback;
while (gui.pollCallback(callback))
{
// Make sure tha callback comes from the button
if (callback.id == 1)
{
// Get the username and password
tgui::EditBox::Ptr editBoxUsername = gui.get("Username");
tgui::EditBox::Ptr editBoxPassword = gui.get("Password");

sf::String username = editBoxUsername->getText();
sf::String password = editBoxPassword->getText();

// Continue here by checking if the username and password are correct ...
}
}

window.clear();

// Draw all created widgets
gui.draw();

window.display();
}

return EXIT_SUCCESS;
}
```