TGUI  0.9-dev
tgui::Gui Class Reference

Gui class. More...

#include <TGUI/Gui.hpp>

Public Member Functions

 Gui ()
 Default constructor. More...
 
 Gui (sf::RenderTarget &target)
 Constructs the gui and set the target on which the gui should be drawn. More...
 
void setTarget (sf::RenderTarget &target)
 Sets the target on which the gui should be drawn. More...
 
sf::RenderTarget * getTarget () const
 Returns the render target on which the gui is being drawn. More...
 
void setView (const sf::View &view)
 Changes the view that is used by the gui. More...
 
const sf::View & getView () const
 Returns the view that is currently used by the gui. More...
 
bool handleEvent (sf::Event event)
 Passes the event to the widgets. More...
 
void setTabKeyUsageEnabled (bool enabled)
 When the tab key usage is enabled, pressing tab will focus another widget.
 
bool isTabKeyUsageEnabled () const
 Returns whether the tab key usage is enabled (if so, pressing tab will focus another widget)
 
void draw ()
 Draws all the widgets that were added to the gui. More...
 
GuiContainer::Ptr getContainer () const
 Returns the internal container of the Gui. More...
 
void setFont (const Font &font)
 Changes the global font. More...
 
std::shared_ptr< sf::Font > getFont () const
 Returns the global font. More...
 
const std::vector< Widget::Ptr > & getWidgets () const
 Returns a list of all the widgets. More...
 
void add (const Widget::Ptr &widgetPtr, const String &widgetName="")
 Adds a widget to the container. More...
 
Widget::Ptr get (const String &widgetName) const
 Returns a pointer to an earlier created widget. More...
 
template<class T >
T::Ptr get (const String &widgetName) const
 Returns a pointer to an earlier created widget. More...
 
bool remove (const Widget::Ptr &widget)
 Removes a single widget that was added to the container. More...
 
void removeAllWidgets ()
 Removes all widgets that were added to the container. More...
 
bool focusNextWidget ()
 Focuses the next widget in the gui. More...
 
bool focusPreviousWidget ()
 Focuses the previous widget in the gui. More...
 
void unfocusAllWidgets ()
 Unfocus all the widgets.
 
void moveWidgetToFront (const Widget::Ptr &widget)
 Places a widget before all other widgets. More...
 
void moveWidgetToBack (const Widget::Ptr &widget)
 Places a widget behind all other widgets. More...
 
void uncheckRadioButtons ()
 Unchecks all the radio buttons. More...
 
void setOpacity (float opacity)
 Changes the opacity of all widgets. More...
 
float getOpacity () const
 Returns the opacity of all the widgets. More...
 
void setTextSize (unsigned int size)
 Changes the character size of all existing and future child widgets. More...
 
unsigned int getTextSize () const
 Returns the character size for future child widgets (and for existing widgets where the size wasn't changed) More...
 
void loadWidgetsFromFile (const String &filename, bool replaceExisting=true)
 Loads the child widgets from a text file. More...
 
void saveWidgetsToFile (const String &filename)
 Saves the child widgets to a text file. More...
 
void loadWidgetsFromStream (std::stringstream &stream, bool replaceExisting=true)
 Loads the child widgets from a string stream. More...
 
void loadWidgetsFromStream (std::stringstream &&stream, bool replaceExisting=true)
 Loads the child widgets from a string stream. More...
 
void saveWidgetsToStream (std::stringstream &stream) const
 Saves this the child widgets to a text file. More...
 

Detailed Description

Gui class.

Constructor & Destructor Documentation

◆ Gui() [1/2]

tgui::Gui::Gui ( )

Default constructor.

If you use this constructor then you will still have to call the setTarget yourself.

◆ Gui() [2/2]

tgui::Gui::Gui ( sf::RenderTarget &  target)

Constructs the gui and set the target on which the gui should be drawn.

Parameters
targetThe render target (typically sf::RenderWindow) that will be used by the gui

If you use this constructor then you will no longer have to call setTarget yourself.

Member Function Documentation

◆ add()

void tgui::Gui::add ( const Widget::Ptr widgetPtr,
const String widgetName = "" 
)

Adds a widget to the container.

Parameters
widgetPtrPointer to the widget you would like to add
widgetNameIf you want to access the widget later then you must do this with this name
Warning
The widget name should not contain whitespace

◆ draw()

void tgui::Gui::draw ( )

Draws all the widgets that were added to the gui.

◆ focusNextWidget()

bool tgui::Gui::focusNextWidget ( )

Focuses the next widget in the gui.

Returns
Whether a new widget was focused

◆ focusPreviousWidget()

bool tgui::Gui::focusPreviousWidget ( )

Focuses the previous widget in the gui.

Returns
Whether a new widget was focused

◆ get() [1/2]

Widget::Ptr tgui::Gui::get ( const String widgetName) const

Returns a pointer to an earlier created widget.

Parameters
widgetNameThe name that was given to the widget when it was added to the container
Returns
Pointer to the earlier created widget

The gui will first search for widgets that are direct children of it, but when none of the child widgets match the given name, a recursive search will be performed.

Warning
This function will return nullptr when an unknown widget name was passed

◆ get() [2/2]

template<class T >
T::Ptr tgui::Gui::get ( const String widgetName) const
inline

Returns a pointer to an earlier created widget.

Parameters
widgetNameThe name that was given to the widget when it was added to the container
Returns
Pointer to the earlier created widget. The pointer will already be casted to the desired type

The gui will first search for widgets that are direct children of it, but when none of the child widgets match the given name, a recursive search will be performed.

Warning
This function will return nullptr when an unknown widget name was passed

◆ getContainer()

GuiContainer::Ptr tgui::Gui::getContainer ( ) const

Returns the internal container of the Gui.

This could be useful when having a function that should accept both the gui and e.g. a child window as parameter.

Warning
Not all functions in the Container class make sense for the Gui (which is the reason that the Gui does not inherit from Container). So calling some functions (e.g. setSize) will have no effect.
Returns
Reference to the internal Container class

◆ getFont()

std::shared_ptr<sf::Font> tgui::Gui::getFont ( ) const

Returns the global font.

Returns
global font

◆ getOpacity()

float tgui::Gui::getOpacity ( ) const

Returns the opacity of all the widgets.

Returns
The opacity of the widgets. 0 means completely transparent, while 1 (default) means fully opaque

◆ getTarget()

sf::RenderTarget* tgui::Gui::getTarget ( ) const

Returns the render target on which the gui is being drawn.

Returns
The sfml render target that is used by the gui

◆ getTextSize()

unsigned int tgui::Gui::getTextSize ( ) const

Returns the character size for future child widgets (and for existing widgets where the size wasn't changed)

Returns
The current text size or 0 when no size was explicitly set in this gui

◆ getView()

const sf::View& tgui::Gui::getView ( ) const

Returns the view that is currently used by the gui.

Returns
Currently set view

◆ getWidgets()

const std::vector<Widget::Ptr>& tgui::Gui::getWidgets ( ) const

Returns a list of all the widgets.

Returns
Vector of all widget pointers

◆ handleEvent()

bool tgui::Gui::handleEvent ( sf::Event  event)

Passes the event to the widgets.

Parameters
eventThe event that was polled from the gui
Returns
Has the event been consumed? When this function returns false, then the event was ignored by all widgets.

You should call this function in your event loop.

◆ loadWidgetsFromFile()

void tgui::Gui::loadWidgetsFromFile ( const String filename,
bool  replaceExisting = true 
)

Loads the child widgets from a text file.

Parameters
filenameFilename of the widget file
replaceExistingRemove existing widgets first if there are any

◆ loadWidgetsFromStream() [1/2]

void tgui::Gui::loadWidgetsFromStream ( std::stringstream &&  stream,
bool  replaceExisting = true 
)

Loads the child widgets from a string stream.

Parameters
streamstringstream that contains the widget file
replaceExistingRemove existing widgets first if there are any

◆ loadWidgetsFromStream() [2/2]

void tgui::Gui::loadWidgetsFromStream ( std::stringstream &  stream,
bool  replaceExisting = true 
)

Loads the child widgets from a string stream.

Parameters
streamstringstream that contains the widget file
replaceExistingRemove existing widgets first if there are any

◆ moveWidgetToBack()

void tgui::Gui::moveWidgetToBack ( const Widget::Ptr widget)

Places a widget behind all other widgets.

Parameters
widgetThe widget that should be moved to the back

◆ moveWidgetToFront()

void tgui::Gui::moveWidgetToFront ( const Widget::Ptr widget)

Places a widget before all other widgets.

Parameters
widgetThe widget that should be moved to the front

◆ remove()

bool tgui::Gui::remove ( const Widget::Ptr widget)

Removes a single widget that was added to the container.

Parameters
widgetPointer to the widget to remove

◆ removeAllWidgets()

void tgui::Gui::removeAllWidgets ( )

Removes all widgets that were added to the container.

◆ saveWidgetsToFile()

void tgui::Gui::saveWidgetsToFile ( const String filename)

Saves the child widgets to a text file.

Parameters
filenameFilename of the widget file

◆ saveWidgetsToStream()

void tgui::Gui::saveWidgetsToStream ( std::stringstream &  stream) const

Saves this the child widgets to a text file.

Parameters
streamstringstream to which the widget file will be added

◆ setFont()

void tgui::Gui::setFont ( const Font font)

Changes the global font.

Parameters
fontFont to use

◆ setOpacity()

void tgui::Gui::setOpacity ( float  opacity)

Changes the opacity of all widgets.

Parameters
opacityThe opacity of the widgets. 0 means completely transparent, while 1 (default) means fully opaque

◆ setTarget()

void tgui::Gui::setTarget ( sf::RenderTarget &  target)

Sets the target on which the gui should be drawn.

Parameters
targetThe render target (typically sf::RenderWindow) that will be used by the gui

◆ setTextSize()

void tgui::Gui::setTextSize ( unsigned int  size)

Changes the character size of all existing and future child widgets.

Parameters
sizeThe new text size

The text size specified in this function overrides the global text size property. By default, the gui does not pass any text size to the widgets and the widgets will use the global text size as default value.

◆ setView()

void tgui::Gui::setView ( const sf::View &  view)

Changes the view that is used by the gui.

Parameters
viewThe new view

◆ uncheckRadioButtons()

void tgui::Gui::uncheckRadioButtons ( )

Unchecks all the radio buttons.


The documentation for this class was generated from the following file: