TGUI  1.0-alpha

This class can be used to manage the widget renderers. More...

#include <TGUI/Loading/Theme.hpp>

Public Types

typedef std::shared_ptr< ThemePtr
 Shared widget pointer.
 
typedef std::shared_ptr< const ThemeConstPtr
 Shared constant widget pointer.
 

Public Member Functions

 Theme (const String &primary="")
 Constructs the theme class, with an optional theme file to load. More...
 
 Theme (const Theme &)
 Copy constructor.
 
 Theme (Theme &&) noexcept
 Move constructor.
 
virtual ~Theme ()
 Destructor.
 
Themeoperator= (const Theme &)
 Overload of copy assignment operator.
 
Themeoperator= (Theme &&) noexcept
 Move assignment.
 
void load (const String &primary)
 Changes the primary theme loader parameter. More...
 
std::shared_ptr< RendererDatagetRenderer (const String &id)
 Gets data for the renderers. More...
 
std::shared_ptr< RendererDatagetRendererNoThrow (const String &id)
 Gets data for the renderers. More...
 
ObjectConverter getGlobalProperty (const String &property)
 Returns the value of a global property in the theme. More...
 
void addRenderer (const String &id, std::shared_ptr< RendererData > renderer)
 Manually adds a renderer data to the theme. More...
 
bool removeRenderer (const String &id)
 Manually removes a renderer to the theme. More...
 
const StringgetPrimary () const
 Returns the primary theme loader parameter. More...
 

Static Public Member Functions

static Theme::Ptr create (const String &primary="")
 Constructs a new theme, with an optional theme file to load. More...
 
static void setThemeLoader (std::shared_ptr< BaseThemeLoader > themeLoader)
 Changes the function that will load the widget theme data. More...
 
static std::shared_ptr< BaseThemeLoadergetThemeLoader ()
 Returns the function that is currently being used to load the widget theme data. More...
 
static void setDefault (const String &primary="")
 Sets the theme class that widgets use by default. More...
 
static void setDefault (std::shared_ptr< Theme > theme)
 Sets the theme class that widgets use by default. More...
 
static void setDefault (std::nullptr_t)
 Resets the theme that widgets use by default.
 
static std::shared_ptr< ThemegetDefault ()
 Returns a pointer to the theme class that widgets use by default. More...
 
static void addRendererInheritanceParent (const String &widgetType, const String &parentType)
 Inform the theme that a custom renderer class inherits its properties from an existing renderer. More...
 
static String getRendererInheritanceParent (const String &widgetType)
 Returns the parent type of a widget. More...
 
static void addRendererDefaultSubwidget (const String &widgetType, const String &property, const String &propertyWidgetType)
 Inform the theme that a custom renderer has subwidgets that need a default value. More...
 
static std::map< String, StringgetRendererDefaultSubwidgets (const String &widgetType)
 Returns the defaulted subwidgets that a renderer has. More...
 
static void addRendererInheritedGlobalProperty (const String &widgetType, const String &property, const String &globalProperty)
 Inform the theme that a custom renderer has properties that can use a default value from the global properties. More...
 
static std::map< String, StringgetRendererInheritedGlobalProperties (const String &widgetType)
 Returns the properties which a renderer inherits from the global theme properties. More...
 

Protected Attributes

std::map< String, std::shared_ptr< RendererData > > m_renderers
 Maps ids to renderer datas.
 
std::map< String, ObjectConverterm_globalProperties
 Maps id to value.
 
String m_primary
 

Static Protected Attributes

static std::map< String, Stringm_rendererInheritanceParents
 
static std::map< String, std::map< String, String > > m_rendererDefaultSubwidgets
 
static std::map< String, std::map< String, String > > m_rendererInheritedGlobalProperties
 
static std::shared_ptr< Themem_defaultTheme
 
static std::shared_ptr< BaseThemeLoaderm_themeLoader
 Theme loader which will do the actual loading.
 

Detailed Description

This class can be used to manage the widget renderers.

Constructor & Destructor Documentation

◆ Theme()

tgui::Theme::Theme ( const String primary = "")

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

Parameters
primaryPrimary parameter for the theme loader (filename of the theme file in DefaultThemeLoader)

Member Function Documentation

◆ addRenderer()

void tgui::Theme::addRenderer ( const String id,
std::shared_ptr< RendererData renderer 
)

Manually adds a renderer data to the theme.

Parameters
idIdentifier of the renderer
rendererThe renderer to add

If a renderer with the same id already exists then it will be replaced by this one. Widgets using the old renderer will keep using that old renderer and remain unchanged.

◆ addRendererDefaultSubwidget()

static void tgui::Theme::addRendererDefaultSubwidget ( const String widgetType,
const String property,
const String propertyWidgetType 
)
static

Inform the theme that a custom renderer has subwidgets that need a default value.

Parameters
widgetTypeType name of the custom widget
propertyProperty of the renderer which should refer to another section in the renderer
propertyWidgetTypeType name of subwidget, which specifies the section in the theme file to refer to

◆ addRendererInheritanceParent()

static void tgui::Theme::addRendererInheritanceParent ( const String widgetType,
const String parentType 
)
static

Inform the theme that a custom renderer class inherits its properties from an existing renderer.

Parameters
widgetTypeType name of the custom widget
parentTypeType name of the base widget

◆ addRendererInheritedGlobalProperty()

static void tgui::Theme::addRendererInheritedGlobalProperty ( const String widgetType,
const String property,
const String globalProperty 
)
static

Inform the theme that a custom renderer has properties that can use a default value from the global properties.

Parameters
widgetTypeType name of the custom widget
propertyProperty of the renderer which refers to the global property
globalPropertyGlobal property in the theme that would be copied as default value for the renderer property

◆ create()

static Theme::Ptr tgui::Theme::create ( const String primary = "")
static

Constructs a new theme, with an optional theme file to load.

Parameters
primaryPrimary parameter for the theme loader (filename of the theme file in DefaultThemeLoader)
Returns
The new theme

Unlike with widgets, it is not required to use a smart pointer for the theme. You do not have to use this function to create a theme.

◆ getDefault()

static std::shared_ptr< Theme > tgui::Theme::getDefault ( )
static

Returns a pointer to the theme class that widgets use by default.

Returns
Default theme

When setDefault was not called or was given a nullptr as parameter, getDefault will create and return the default "White" theme.

◆ getGlobalProperty()

ObjectConverter tgui::Theme::getGlobalProperty ( const String property)

Returns the value of a global property in the theme.

Parameters
propertyName of the global property to retrieve
Returns
Value of the global property, or an object with type ObjectConverter::Type::None if no such propery exists

◆ getPrimary()

const String & tgui::Theme::getPrimary ( ) const

Returns the primary theme loader parameter.

Returns
Primary parameter for the theme loader (filename of the theme file in DefaultThemeLoader)

◆ getRenderer()

std::shared_ptr< RendererData > tgui::Theme::getRenderer ( const String id)

Gets data for the renderers.

Parameters
idThe secondary parameter for the theme loader (name of section in theme file in DefaultThemeLoader).
Returns
Shared renderer data
Exceptions
Exceptionif theme loader fails to load the requested renderer

◆ getRendererDefaultSubwidgets()

static std::map< String, String > tgui::Theme::getRendererDefaultSubwidgets ( const String widgetType)
static

Returns the defaulted subwidgets that a renderer has.

Parameters
widgetTypeType name of the widget of which we are looking up the properties
Returns
Map containing property names as keys the corresponding renderer sections as values
See also
addRendererDefaultSubwidget

◆ getRendererInheritanceParent()

static String tgui::Theme::getRendererInheritanceParent ( const String widgetType)
static

Returns the parent type of a widget.

Parameters
widgetTypeType name of the derived widget
Returns
Type name of the base widget, or an empty string if the widget has no known parent.
See also
addRendererInheritanceParent

◆ getRendererInheritedGlobalProperties()

static std::map< String, String > tgui::Theme::getRendererInheritedGlobalProperties ( const String widgetType)
static

Returns the properties which a renderer inherits from the global theme properties.

Parameters
widgetTypeType name of the widget of which we are looking up the properties
Returns
Map containing renderer property names as keys the corresponding global property names as values
See also
addRendererInheritedGlobalProperty

◆ getRendererNoThrow()

std::shared_ptr< RendererData > tgui::Theme::getRendererNoThrow ( const String id)

Gets data for the renderers.

Parameters
idThe secondary parameter for the theme loader (name of section in theme file in DefaultThemeLoader).
Returns
Shared renderer data

Unlike getRenderer which throws an exception, this function will return nullptr when the renderer is not found

◆ getThemeLoader()

static std::shared_ptr< BaseThemeLoader > tgui::Theme::getThemeLoader ( )
static

Returns the function that is currently being used to load the widget theme data.

Returns
Theme loader

◆ load()

void tgui::Theme::load ( const String primary)

Changes the primary theme loader parameter.

Parameters
primaryPrimary parameter for the theme loader (filename of the theme file in DefaultThemeLoader)

When the theme was loaded before and a renderer with the same name is encountered, the widgets that were using the old renderer will be reloaded with the new renderer.

◆ removeRenderer()

bool tgui::Theme::removeRenderer ( const String id)

Manually removes a renderer to the theme.

Parameters
idIdentifier of the renderer
Returns
True when removed, false when the identifier did not match any renderer

◆ setDefault() [1/2]

static void tgui::Theme::setDefault ( const String primary = "")
static

Sets the theme class that widgets use by default.

Parameters
primaryPrimary parameter for the theme loader (filename of the theme file in DefaultThemeLoader)

Calling this function is equivalent to the following:

static void setDefault(const String &primary="")
Sets the theme class that widgets use by default.
static Theme::Ptr create(const String &primary="")
Constructs a new theme, with an optional theme file to load.

◆ setDefault() [2/2]

static void tgui::Theme::setDefault ( std::shared_ptr< Theme theme)
static

Sets the theme class that widgets use by default.

Parameters
themeTheme to use as default

◆ setThemeLoader()

static void tgui::Theme::setThemeLoader ( std::shared_ptr< BaseThemeLoader themeLoader)
static

Changes the function that will load the widget theme data.

Parameters
themeLoaderPointer to the new loader

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