Renderers

Accessing renderer properties

Every widget has a renderer which contains the properties of how the widget should look (e.g. background and text color). When creating a widget, such a renderer is automatically created with it.

The widgets all have a getRenderer() method which will return a pointer to the renderer. The renderer returned by this function will have setters and getters for the properties available for that particular type of widget (i.e. the renderer of a list box has different functions than the one from a button).

auto slider = tgui::Slider::create();
slider->getRenderer()->setTrackColor(sf::Color::Green);
sf::Color thumbColor = slider->getRenderer()->getThumbColor();

Sharing renderer

When not calling the setRenderer function, each widget will have its own renderer. You can however set the same renderer in multiple widgets so that changing the renderer changes all these widgets. Renderers that you get from themes are always shared.

Theme theme{"TGUI/widgets/Black.txt"};
button1->setRenderer(theme.getRenderer("Button"));
button2->setRenderer(theme.getRenderer("Button"));
button3->setRenderer(button2->getRenderer());

button3->getRenderer()->setBackgroundColor(sf::Color::Red); // Changes button1 and button2 as well

If you want to copy a renderer and not have other widgets be affected when you change it then you should clone the renderer:

button3->setRenderer(button2->getRenderer()->clone());

button3->getRenderer()->setBackgroundColor(sf::Color::Red); // Does not affect other buttons