TGUI 1.13
Loading...
Searching...
No Matches
Theme.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2026 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#ifndef TGUI_THEME_HPP
26#define TGUI_THEME_HPP
27
28#include <TGUI/Loading/ThemeLoader.hpp>
29#include <TGUI/Renderers/WidgetRenderer.hpp>
30
32
33namespace tgui
34{
39 class TGUI_API Theme
40 {
41 public:
42 using Ptr = std::shared_ptr<Theme>;
43 using ConstPtr = std::shared_ptr<const Theme>;
44
50 Theme(const String& primary = "");
51
55 Theme(const Theme&);
56
60 Theme(Theme&&) noexcept;
61
65 virtual ~Theme();
66
70 Theme& operator=(const Theme&);
71
75 Theme& operator=(Theme&&) noexcept;
76
87 [[nodiscard]] static Theme::Ptr create(const String& primary = "");
88
97 void load(const String& primary);
98
109 void replace(const Theme& otherTheme);
110
120 [[nodiscard]] std::shared_ptr<RendererData> getRenderer(const String& id);
121
131 [[nodiscard]] std::shared_ptr<RendererData> getRendererNoThrow(const String& id);
132
140 [[nodiscard]] ObjectConverter getGlobalProperty(const String& property);
141
151 void addRenderer(const String& id, std::shared_ptr<RendererData> renderer);
152
160 bool removeRenderer(const String& id);
161
166 [[nodiscard]] const String& getPrimary() const;
167
173 static void setThemeLoader(std::shared_ptr<BaseThemeLoader> themeLoader);
174
180 [[nodiscard]] static std::shared_ptr<BaseThemeLoader> getThemeLoader();
181
192 static void setDefault(const String& primary = "");
193
199 static void setDefault(std::shared_ptr<Theme> theme);
200
204 static void setDefault(std::nullptr_t);
205
214 [[nodiscard]] static std::shared_ptr<Theme> getDefault();
215
222 static void addRendererInheritanceParent(const String& widgetType, const String& parentType);
223
230 [[nodiscard]] static String getRendererInheritanceParent(const String& widgetType);
231
239 static void addRendererDefaultSubwidget(const String& widgetType, const String& property, const String& propertyWidgetType);
240
247 [[nodiscard]] static std::map<String, String> getRendererDefaultSubwidgets(const String& widgetType);
248
256 static void addRendererInheritedGlobalProperty(const String& widgetType, const String& property, const String& globalProperty);
257
264 [[nodiscard]] static std::map<String, String> getRendererInheritedGlobalProperties(const String& widgetType);
265
267
268 protected:
269 static std::map<String, String> m_rendererInheritanceParents;
270 static std::map<String, std::map<String, String>> m_rendererDefaultSubwidgets;
271 static std::map<String, std::map<String, String>> m_rendererInheritedGlobalProperties;
272 static std::shared_ptr<Theme> m_defaultTheme;
273 static std::shared_ptr<BaseThemeLoader> m_themeLoader;
274
275 std::map<String, std::shared_ptr<RendererData>> m_renderers;
277 String m_primary;
278 };
279} // namespace tgui
280
281#endif // TGUI_THEME_HPP
Base class for theme loader implementations.
Definition ThemeLoader.hpp:45
Implicit converter for settable properties.
Definition ObjectConverter.hpp:47
Wrapper class to store strings.
Definition String.hpp:94
std::shared_ptr< const Theme > ConstPtr
Shared constant widget pointer.
Definition Theme.hpp:43
static std::shared_ptr< BaseThemeLoader > m_themeLoader
Theme loader which will do the actual loading.
Definition Theme.hpp:273
static std::map< String, String > getRendererDefaultSubwidgets(const String &widgetType)
Returns the defaulted subwidgets that a renderer has.
static std::shared_ptr< Theme > getDefault()
Returns a pointer to the theme class that widgets use by default.
std::map< String, std::shared_ptr< RendererData > > m_renderers
Maps ids to renderer datas.
Definition Theme.hpp:275
ObjectConverter getGlobalProperty(const String &property)
Returns the value of a global property in the theme.
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 p...
void replace(const Theme &otherTheme)
Replaced this theme with another one, while updating all connected widgets to the new renderers.
void load(const String &primary)
Changes the primary theme loader parameter.
std::map< String, ObjectConverter > m_globalProperties
Maps id to value.
Definition Theme.hpp:276
std::shared_ptr< Theme > Ptr
Shared widget pointer.
Definition Theme.hpp:42
std::shared_ptr< RendererData > getRenderer(const String &id)
Gets data for the renderers.
static void setDefault(const String &primary="")
Sets the theme class that widgets use by default.
void addRenderer(const String &id, std::shared_ptr< RendererData > renderer)
Manually adds a renderer data to the theme.
static void setThemeLoader(std::shared_ptr< BaseThemeLoader > themeLoader)
Changes the function that will load the widget theme data.
static std::shared_ptr< BaseThemeLoader > getThemeLoader()
Returns the function that is currently being used to load the widget theme data.
const String & getPrimary() const
Returns the primary theme loader parameter.
Theme(Theme &&) noexcept
Move constructor.
static Theme::Ptr create(const String &primary="")
Constructs a new theme, with an optional theme file to load.
static void addRendererInheritanceParent(const String &widgetType, const String &parentType)
Inform the theme that a custom renderer class inherits its properties from an existing renderer.
std::shared_ptr< RendererData > getRendererNoThrow(const String &id)
Gets data for the renderers.
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.
bool removeRenderer(const String &id)
Manually removes a renderer to the theme.
static std::map< String, String > getRendererInheritedGlobalProperties(const String &widgetType)
Returns the properties which a renderer inherits from the global theme properties.
Theme(const String &primary="")
Constructs the theme class, with an optional theme file to load.
static String getRendererInheritanceParent(const String &widgetType)
Returns the parent type of a widget.
Theme(const Theme &)
Copy constructor.
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
Shared data used in renderer classes.
Definition WidgetRenderer.hpp:47