TGUI  v0.6.10
Public Member Functions | List of all members
tgui::Container Class Referenceabstract

Parent class for widgets that store multiple widgets. More...

#include <Container.hpp>

Inheritance diagram for tgui::Container:
tgui::Widget tgui::Transformable tgui::CallbackManager tgui::ChildWindow tgui::Grid tgui::GuiContainer tgui::Panel tgui::MessageBox

Public Member Functions

 Container ()
 Default constructor. More...
 
 Container (const Container &copy)
 Copy constructor. More...
 
virtual ~Container ()
 Destructor. More...
 
Containeroperator= (const Container &right)
 Overload of assignment operator. More...
 
bool setGlobalFont (const std::string &filename)
 Changes the global font. More...
 
void setGlobalFont (const sf::Font &font)
 Changes the global font. More...
 
const sf::Font & getGlobalFont () const
 Returns the global font. More...
 
const std::vector< Widget::Ptr > & getWidgets ()
 Returns a list of all the widgets. More...
 
const std::vector< sf::String > & getWidgetNames ()
 Returns a list of the names of all the widgets. More...
 
virtual void add (const Widget::Ptr &widgetPtr, const sf::String &widgetName="")
 Adds a widget to the container. More...
 
Widget::Ptr get (const sf::String &widgetName, bool recursive=false) const
 Returns a pointer to an earlier created widget. More...
 
template<class T >
T::Ptr get (const sf::String &widgetName, bool recursive=false) const
 Returns a pointer to an earlier created widget. More...
 
Widget::Ptr copy (const Widget::Ptr &oldWidget, const sf::String &newWidgetName="")
 Makes a copy of any existing widget and returns the pointer to the new widget. More...
 
virtual void remove (const Widget::Ptr &widget)
 Removes a single widget that was added to the container. More...
 
virtual void remove (Widget *widget)
 Removes a single widget that was added to the container. More...
 
virtual void removeAllWidgets ()
 Removes all widgets that were added to the container. More...
 
bool setWidgetName (const Widget::Ptr &widget, const std::string &name)
 Changes the name of a widget. More...
 
bool getWidgetName (const Widget::Ptr &widget, std::string &name) const
 Returns the name of a widget. More...
 
void focusWidget (const Widget::Ptr &widget)
 Focuses a widget. More...
 
void focusWidget (Widget *const widget)
 Focuses a widget. More...
 
void focusNextWidget ()
 Focuses the next widget. More...
 
void focusPreviousWidget ()
 Focuses the previous widget. More...
 
void unfocusWidgets ()
 Unfocus all the widgets. More...
 
void uncheckRadioButtons ()
 Uncheck all the radio buttons. More...
 
void moveWidgetToFront (Widget *const widget)
 Places a widget before all other widgets. More...
 
void moveWidgetToBack (Widget *const widget)
 Places a widget behind all other widgets. More...
 
virtual void setTransparency (unsigned char transparency)
 Changes the transparency of the widget. More...
 
void bindGlobalCallback (std::function< void(const Callback &)> func)
 Bind a function to the callbacks of all child widgets. More...
 
template<typename T >
void bindGlobalCallback (void(T::*func)(const Callback &), T *const classPtr)
 Bind a function to the callbacks of all child widgets. More...
 
virtual void unbindGlobalCallback ()
 Unbind the global callback function(s). More...
 
bool loadWidgetsFromFile (const std::string &filename)
 Loads a form from a file. More...
 
bool saveWidgetsToFile (const std::string &filename)
 Save the widgets to a file. More...
 
virtual sf::Vector2f getWidgetsOffset () const
 Returns the distance between the position of the container and a widget that would be drawn inside this container on relative position (0,0). More...
 
- Public Member Functions inherited from tgui::Widget
 Widget ()
 Default constructor. More...
 
 Widget (const Widget &copy)
 Copy constructor. More...
 
virtual ~Widget ()
 Destructor. More...
 
Widgetoperator= (const Widget &right)
 Overload of assignment operator. More...
 
virtual sf::Vector2f getAbsolutePosition () const
 Get the absolute position of the widget on the screen. More...
 
virtual void show ()
 Shows the widget. More...
 
virtual void hide ()
 Hides the widget. More...
 
bool isVisible () const
 Returns true when the widget is visible. More...
 
virtual void enable ()
 Enables the widget. More...
 
virtual void disable ()
 Disables the widget. More...
 
bool isEnabled () const
 Returns true when the widget is enabled. More...
 
bool isDisabled () const
 Returns true when the widget is disabled. More...
 
bool isLoaded () const
 Returns true when the widget is loaded successfully. More...
 
virtual void focus ()
 Focus the widget. More...
 
virtual void unfocus ()
 Unfocus the widget. More...
 
bool isFocused () const
 Returns true when the widget is focused and false otherwise. More...
 
WidgetTypes getWidgetType () const
 Returns the type of the widget. More...
 
ContainergetParent () const
 Returns a pointer to the parent widget. More...
 
unsigned char getTransparency () const
 Returns the transparency of the widget. More...
 
virtual void moveToFront ()
 Places the widget before all other widgets. More...
 
virtual void moveToBack ()
 Places the widget behind all other widgets. More...
 
void setCallbackId (unsigned int callbackId)
 Changes the callback id of the widget. More...
 
unsigned int getCallbackId ()
 Returns the callback id of the widget. More...
 
- Public Member Functions inherited from tgui::Transformable
 Transformable ()
 Default constructor. More...
 
virtual ~Transformable ()
 Destructor. More...
 
virtual void setPosition (float x, float y)
 Set the position of the widget. More...
 
void setPosition (const sf::Vector2f &position)
 set the position of the widget More...
 
const sf::Vector2f & getPosition () const
 get the position of the widget More...
 
void move (float offsetX, float offsetY)
 Move the widget by a given offset. More...
 
void move (const sf::Vector2f &offset)
 Move the widget by a given offset. More...
 
virtual void setSize (float width, float height)=0
 Changes the size of the widget. More...
 
virtual sf::Vector2f getSize () const =0
 Returns the size of the widget. More...
 
virtual sf::Vector2f getFullSize () const
 Returns the entire size that the widget is using. More...
 
void scale (float factorX, float factorY)
 Scale the widget. More...
 
void scale (const sf::Vector2f &factors)
 Scale the widget. More...
 
- Public Member Functions inherited from tgui::CallbackManager
void bindCallback (std::function< void()> func, unsigned int trigger)
 Bind a function to one or more specific callback trigger(s). More...
 
template<typename T >
void bindCallback (void(T::*func)(), T *const classPtr, unsigned int trigger)
 Bind a function to one or more specific callback trigger(s). More...
 
void bindCallbackEx (std::function< void(const Callback &)> func, unsigned int trigger)
 Bind a function to one or more specific callback trigger(s). More...
 
template<typename T >
void bindCallbackEx (void(T::*func)(const Callback &), T *const classPtr, unsigned int trigger)
 Bind a function to one or more specific callback trigger(s). More...
 
void bindCallback (unsigned int trigger)
 Bind one or more specific callback trigger(s) to the parent widget. More...
 
void unbindCallback (unsigned int trigger)
 Unbind all callback function bound to the given trigger. More...
 
void unbindAllCallback ()
 Unbind all callback functions bound to any callback. More...
 

Additional Inherited Members

- Public Types inherited from tgui::Widget

Detailed Description

Parent class for widgets that store multiple widgets.

Constructor & Destructor Documentation

tgui::Container::Container ( )

Default constructor.

tgui::Container::Container ( const Container copy)

Copy constructor.

Parameters
copyInstance to copy
virtual tgui::Container::~Container ( )
virtual

Destructor.

Member Function Documentation

virtual void tgui::Container::add ( const Widget::Ptr widgetPtr,
const sf::String &  widgetName = "" 
)
virtual

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

Usage example:

tgui::Picture::Ptr pic(container); // Create a picture and add it to the container
container.remove(pic); // Remove the picture from the container
container.add(pic); // Add the picture to the container again
void tgui::Container::bindGlobalCallback ( std::function< void(const Callback &)>  func)

Bind a function to the callbacks of all child widgets.

When a child widget tells this widget about the callback then the global callback function(s) will be called. If no global callback function has been bound then the callback is passed to the parent of this widget.

Parameters
funcPointer to a free function with a reference to a Callback widget as parameter.
template<typename T >
void tgui::Container::bindGlobalCallback ( void(T::*)(const Callback &)  func,
T *const  classPtr 
)
inline

Bind a function to the callbacks of all child widgets.

When a child widget tells this widget about the callback then the global callback function(s) will be called. If no global callback function has been bound then the callback is passed to the parent of this widget.

Parameters
funcPointer to a member function with a reference to a Callback widget as parameter.
classPtrPointer to the widget of the class.
Widget::Ptr tgui::Container::copy ( const Widget::Ptr oldWidget,
const sf::String &  newWidgetName = "" 
)

Makes a copy of any existing widget and returns the pointer to the new widget.

Parameters
oldWidgetA pointer to the old widget.
newWidgetNameIf you want to access the widget later then you must do this with this name
Returns
Pointer to the new widget

Usage example:

tgui::Picture::Ptr pic(container, "picName");
tgui::Picture::Ptr pic2 = container.copy(pic, "picName_2");
tgui::Picture::Ptr pic3 = container.copy(container.get("picName"), "picName_3");
void tgui::Container::focusNextWidget ( )

Focuses the next widget.

The currently focused widget will be unfocused, even if it was the only widget. When no widget was focused, the first widget in the container will be focused.

void tgui::Container::focusPreviousWidget ( )

Focuses the previous widget.

The currently focused widget will be unfocused, even if it was the only widget. When no widget was focused, the last widget in the container will be focused.

void tgui::Container::focusWidget ( const Widget::Ptr widget)

Focuses a widget.

The previously focused widget will be unfocused.

Parameters
widgetThe widget that has to be focused.
void tgui::Container::focusWidget ( Widget *const  widget)

Focuses a widget.

The previously focused widget will be unfocused.

Parameters
widgetThe widget that has to be focused.
Widget::Ptr tgui::Container::get ( const sf::String &  widgetName,
bool  recursive = false 
) 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.
recursiveShould the function also search for widgets inside containers that are inside this container?
Returns
Pointer to the earlier created widget
Warning
This function will return nullptr when an unknown widget name was passed.

Usage example:

tgui::Picture::Ptr pic(container, "picName");
tgui::Picture::Ptr pic2 = container.get("picName");
template<class T >
T::Ptr tgui::Container::get ( const sf::String &  widgetName,
bool  recursive = false 
) 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.
recursiveShould the function also search for widgets inside containers that are inside this container?
Returns
Pointer to the earlier created widget. The pointer will already be casted to the desired type.
Warning
This function will return nullptr when an unknown widget name was passed.

Usage example:

tgui::Picture::Ptr pic(container, "picName");
tgui::Picture::Ptr pic2 = container.get<tgui::Picture>("picName");
const sf::Font& tgui::Container::getGlobalFont ( ) const

Returns the global font.

This is the font that is used for newly created widget by default.

Returns
global font
bool tgui::Container::getWidgetName ( const Widget::Ptr widget,
std::string &  name 
) const

Returns the name of a widget.

Parameters
widgetWidget of which the name should be retrieved
nameName for the widget
Returns
False is returned when the widget wasn't part of this container. In this case the name parameter is left unchanged.
const std::vector<sf::String>& tgui::Container::getWidgetNames ( )

Returns a list of the names of all the widgets.

Returns
Vector of all widget names
const std::vector<Widget::Ptr>& tgui::Container::getWidgets ( )

Returns a list of all the widgets.

Returns
Vector of all widget pointers
virtual sf::Vector2f tgui::Container::getWidgetsOffset ( ) const
virtual

Returns the distance between the position of the container and a widget that would be drawn inside this container on relative position (0,0).

Returns
Offset of the widgets in the container

Reimplemented in tgui::ChildWindow.

bool tgui::Container::loadWidgetsFromFile ( const std::string &  filename)

Loads a form from a file.

The widgets will be loaded and added to the container. Note that even when this function fails, some widgets might have been loaded already.

Parameters
filenameFilename of the widget file that is to be loaded
Returns
  • true on success
  • false when the file could not be opened
  • false when the file contains a mistake
  • false when one of the widgets couldn't be loaded
void tgui::Container::moveWidgetToBack ( Widget *const  widget)

Places a widget behind all other widgets.

Parameters
widgetThe widget that should be moved to the back
void tgui::Container::moveWidgetToFront ( Widget *const  widget)

Places a widget before all other widgets.

Parameters
widgetThe widget that should be moved to the front
Container& tgui::Container::operator= ( const Container right)

Overload of assignment operator.

Parameters
rightInstance to assign
Returns
Reference to itself
virtual void tgui::Container::remove ( const Widget::Ptr widget)
virtual

Removes a single widget that was added to the container.

Parameters
widgetPointer to the widget to remove

Usage example:

tgui::Picture::Ptr pic(container, "picName");
tgui::Picture::Ptr pic2(container, "picName2");
container.remove(pic);
container.remove(container.get("picName2"));

Reimplemented in tgui::Grid.

virtual void tgui::Container::remove ( Widget widget)
virtual

Removes a single widget that was added to the container.

Parameters
widgetPointer to the widget to remove

Reimplemented in tgui::Grid.

virtual void tgui::Container::removeAllWidgets ( )
virtual

Removes all widgets that were added to the container.

Reimplemented in tgui::Grid.

bool tgui::Container::saveWidgetsToFile ( const std::string &  filename)

Save the widgets to a file.

Parameters
filenameFilename of the widget file that is to be created
Returns
  • true on success
  • false when the file couldn't be created
bool tgui::Container::setGlobalFont ( const std::string &  filename)

Changes the global font.

This font will be used by all widgets that are created after calling this function.

Parameters
filenamePath of the font file to load
Returns
True if loading succeeded, false if it failed
void tgui::Container::setGlobalFont ( const sf::Font &  font)

Changes the global font.

This font will be used by all widgets that are created after calling this function.

Parameters
fontFont to copy
virtual void tgui::Container::setTransparency ( unsigned char  transparency)
virtual

Changes the transparency of the widget.

Parameters
transparencyThe transparency of the widget. 0 is completely transparent, while 255 (default) means fully opaque.

Note that this will only change the transparency of the images. The parts of the widgets that use a color will not be changed. You must change them yourself by setting the alpha channel of the color.

Reimplemented from tgui::Widget.

Reimplemented in tgui::ChildWindow, and tgui::Panel.

bool tgui::Container::setWidgetName ( const Widget::Ptr widget,
const std::string &  name 
)

Changes the name of a widget.

Parameters
widgetWidget of which the name should be changed
nameNew name for the widget
Returns
True when the name was changed, false when the widget wasn't part of this container.
virtual void tgui::Container::unbindGlobalCallback ( )
virtual

Unbind the global callback function(s).

Reimplemented in tgui::GuiContainer.

void tgui::Container::uncheckRadioButtons ( )

Uncheck all the radio buttons.

void tgui::Container::unfocusWidgets ( )

Unfocus all the widgets.


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