TGUI  v0.7.5

Default Theme class. More...

#include <Theme.hpp>

Inheritance diagram for tgui::Theme:
tgui::BaseTheme

Public Types

typedef std::shared_ptr< ThemePtr
 Shared theme pointer.
 

Public Member Functions

 Theme (const std::string &filename="")
 Construct the theme class, with an optional theme file to load. More...
 
WidgetConverter load (std::string className)
 Load the widget from the theme. More...
 
void reload (const std::string &filename)
 Reload the theme with a different filename. More...
 
void reload (std::string oldClassName, std::string newClassName)
 Reload all widgets that were loaded with a certain class name. More...
 
void reload (Widget::Ptr widget, std::string className)
 Reload a specific widget. More...
 
void setProperty (std::string className, const std::string &property, const std::string &value)
 Change a property of the renderer of all widgets that were loaded with a certain class name. More...
 
void setProperty (std::string className, const std::string &property, ObjectConverter &&value)
 Change a property of the renderer of all widgets that were loaded with a certain class name. More...
 
std::string getProperty (std::string className, std::string property) const
 Retrieve the serialized value of a certain property of widgets that use a certain class name. More...
 
std::map< std::string, std::string > getPropertyValuePairs (std::string className) const
 Get a map with all properties and their values from widgets loaded with a certain class name. More...
 
std::shared_ptr< Themeclone () const
 Clone the theme without its connected widgets. More...
 
virtual void widgetDetached (Widget *widget) override
 Function that gets called when a widget is disconnected from this theme. More...
 
virtual WidgetConverter internalLoad (const std::string &filename, const std::string &className) override
 This function can be used inside a widget to load other widgets without access to the derived theme class. More...
 
virtual void initWidget (Widget *widget, std::string filename, std::string className) override
 Function called by the widget to finish its initialization. More...
 
- Public Member Functions inherited from tgui::BaseTheme
virtual ~BaseTheme ()=default
 Virtual destructor.
 
virtual void widgetAttached (Widget *widget)
 Virtual function that gets called when a widget is connected to this theme. More...
 

Static Public Member Functions

static Theme::Ptr create (const std::string &filename="")
 Creates a new theme instance. More...
 
- Static Public Member Functions inherited from tgui::BaseTheme
static void setConstructFunction (const std::string &type, const std::function< Widget::Ptr()> &constructor)
 Changes the construct function of a specific widget type. More...
 
static void setThemeLoader (const std::shared_ptr< BaseThemeLoader > &themeLoader)
 Change the function that will load the widget theme data. More...
 

Additional Inherited Members

- Static Protected Attributes inherited from tgui::BaseTheme
static std::map< std::string, std::function< Widget::Ptr()> > m_constructors
 Widget creator functions.
 
static std::shared_ptr< BaseThemeLoaderm_themeLoader
 Theme loading functions, they read the theme file.
 

Detailed Description

Default Theme class.

Constructor & Destructor Documentation

◆ Theme()

tgui::Theme::Theme ( const std::string &  filename = "")

Construct the theme class, with an optional theme file to load.

Parameters
filenameFilename of the theme file
Warning
The theme instance has to be created with std::make_shared

Member Function Documentation

◆ clone()

std::shared_ptr<Theme> tgui::Theme::clone ( ) const

Clone the theme without its connected widgets.

Any changes made on the returned theme will not have any impact on this theme and vice versa.

◆ create()

static Theme::Ptr tgui::Theme::create ( const std::string &  filename = "")
static

Creates a new theme instance.

Returns
The new theme

◆ getProperty()

std::string tgui::Theme::getProperty ( std::string  className,
std::string  property 
) const

Retrieve the serialized value of a certain property of widgets that use a certain class name.

Parameters
classNameThe class name of the widgets
propertyThe property that you would like to retrieve
Returns
The serialized value or an empty string when the property did not exist

◆ getPropertyValuePairs()

std::map<std::string, std::string> tgui::Theme::getPropertyValuePairs ( std::string  className) const

Get a map with all properties and their values from widgets loaded with a certain class name.

Parameters
classNameThe class name of the widgets
Returns
Serialized property-value pairs

◆ initWidget()

virtual void tgui::Theme::initWidget ( Widget widget,
std::string  filename,
std::string  className 
)
overridevirtual

Function called by the widget to finish its initialization.

Parameters
widgetThe widget that needs to be initialized
filenameFilename that was used to load the widget
classNameClass name that was used to load the widget

Implements tgui::BaseTheme.

◆ internalLoad()

virtual WidgetConverter tgui::Theme::internalLoad ( const std::string &  filename,
const std::string &  className 
)
overridevirtual

This function can be used inside a widget to load other widgets without access to the derived theme class.

Parameters
filenameThe filename that has to match the one used to load this theme
classNameThe class name of the theme to load

Implements tgui::BaseTheme.

◆ load()

WidgetConverter tgui::Theme::load ( std::string  className)

Load the widget from the theme.

Parameters
classNameName of the class inside the theme file (equals widget type when no class is given)
Exceptions
Exceptionwhen the requested class name could not be loaded from the file
Exceptionwhen there was no loader for this type of widget

◆ reload() [1/3]

void tgui::Theme::reload ( const std::string &  filename)

Reload the theme with a different filename.

Parameters
filenameFilename of the new theme file

All widgets that are connected to this theme will be reloaded with the new theme file. The class names thus have to match with those from the old theme file!

Exceptions
Exceptionwhen one of the widgets failed to reload

◆ reload() [2/3]

void tgui::Theme::reload ( std::string  oldClassName,
std::string  newClassName 
)

Reload all widgets that were loaded with a certain class name.

Parameters
oldClassNameClass name that was used to load the widget
newClassNameClass name to load the widget with
Exceptions
Exceptionwhen the requested new class name could not be loaded from the file
Exceptionwhen one of the widgets failed to reload

◆ reload() [3/3]

void tgui::Theme::reload ( Widget::Ptr  widget,
std::string  className 
)

Reload a specific widget.

Parameters
widgetThe widget to reload
classNameClass name to load the widget with
Exceptions
Exceptionwhen the requested class name could not be loaded from the file
Exceptionwhen the widget failed to reload

◆ setProperty() [1/2]

void tgui::Theme::setProperty ( std::string  className,
const std::string &  property,
const std::string &  value 
)

Change a property of the renderer of all widgets that were loaded with a certain class name.

Parameters
classNameThe class name of the widgets
propertyThe property that you would like to change
valueThe new serialized value that you like to assign to the property
Exceptions
Exceptionwhen deserialization fails or when the widget does not have this property.

◆ setProperty() [2/2]

void tgui::Theme::setProperty ( std::string  className,
const std::string &  property,
ObjectConverter &&  value 
)

Change a property of the renderer of all widgets that were loaded with a certain class name.

Parameters
classNameThe class name of the widgets
propertyThe property that you would like to change
valueThe new value that you like to assign to the property. The ObjectConverter is implicitly constructed from the possible value types.
Exceptions
Exceptionfor unknown properties or when value was of a wrong type.

◆ widgetDetached()

virtual void tgui::Theme::widgetDetached ( Widget widget)
overridevirtual

Function that gets called when a widget is disconnected from this theme.

Parameters
widgetThe widget that was detached from this theme

Reimplemented from tgui::BaseTheme.


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