Tabs

There is no real tutorial yet about the Tab widget, but below you can find some code to understand how to use it.

#include <TGUI/TGUI.hpp>

void onTabSelected(const tgui::Callback& callback)
{
// Get the tab that sent the callback
tgui::Tab::Ptr tab = callback.widget;

// Access the gui.
tgui::Container* gui = tab->getParent();

// Show the correct panel
if (tab->getSelected() == "First")
{
gui->get("FirstPanel")->show();
gui->get("SecondPanel")->hide();
}
else if (tab->getSelected() == "Second")
{
gui->get("FirstPanel")->hide();
gui->get("SecondPanel")->show();
}
}

int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "TGUI.Net Tabs Example");

sf::Texture background1, background2;
background1.loadFromFile("xubuntu_bg_aluminium.jpg");
background2.loadFromFile("Linux.jpg");

tgui::Gui gui = tgui::Gui(window);
gui.setGlobalFont("TGUI/fonts/DejaVuSans.ttf");

// Create the tabs
tgui::Tab::Ptr tabs(gui);
tabs->load("TGUI/widgets/Black.conf");
tabs->add("First");
tabs->add("Second");
tabs->setPosition(20, 20);

// Create the first panel
tgui::Panel::Ptr panel1(gui, "FirstPanel");
panel1->setSize(400, 300);
panel1->setPosition(tabs->getPosition().x, tabs->getPosition().y + tabs->getTabHeight());
panel1->setBackgroundTexture(&background1);

// Create the second panel (copy of first one, but with different image)
tgui::Panel::Ptr panel2 = gui.copy(panel1, "SecondPanel");
panel2->setBackgroundTexture(&background2);

// Enable callback when another tab is selected
tabs->bindCallbackEx(onTabSelected, tgui::Tab::TabChanged);

// Select the first tab and only show the first panel
tabs->select("First");
panel1->show();
panel2->hide();

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

gui.handleEvent(event);
}

window.clear();
gui.draw();
window.display();
}

return 0;
}