TGUI 1.13
Loading...
Searching...
No Matches
ThemeLoader.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_LOADER_HPP
26#define TGUI_THEME_LOADER_HPP
27
28#include <TGUI/Loading/DataIO.hpp>
29#include <TGUI/String.hpp>
30
31#include <map>
32#include <memory>
33#include <set>
34#include <string>
35#include <vector>
36
38
39namespace tgui
40{
44 class TGUI_API BaseThemeLoader
45 {
46 public:
50 virtual ~BaseThemeLoader() = default;
51
57 virtual void preload(const String& primary);
58
68 [[nodiscard]] virtual std::map<String, String> getGlobalProperties(const String& primary);
69
80 [[nodiscard]] virtual const std::map<String, String>& load(const String& primary, const String& secondary) = 0;
81
92 [[nodiscard]] virtual bool canLoad(const String& primary, const String& secondary) = 0;
93
95
96 protected:
98 // Turns texture and font filenames into paths relative to the theme file
100 void injectThemePath(const std::unique_ptr<DataIO::Node>& node, const String& path) const;
101
103 // Resolves references to sections
105 void resolveReferences(std::map<String, std::reference_wrapper<const std::unique_ptr<DataIO::Node>>>& sections,
106 const std::map<String, String>& globalProperties,
107 const std::unique_ptr<DataIO::Node>& node) const;
108
110 };
111
120 class TGUI_API DefaultThemeLoader : public BaseThemeLoader
121 {
122 public:
130 void preload(const String& filename) override;
131
139 [[nodiscard]] std::map<String, String> getGlobalProperties(const String& filename) override;
140
152 [[nodiscard]] const std::map<String, String>& load(const String& filename, const String& section) override;
153
162 [[nodiscard]] bool canLoad(const String& filename, const String& section) override;
163
173 static void flushCache(const String& filename = "");
174
176
177 protected:
185 [[nodiscard]] virtual std::unique_ptr<DataIO::Node> readFile(const String& filename) const;
186
188
189 protected:
190 static std::map<String, std::map<String, std::map<String, String>>> m_propertiesCache;
191 static std::map<String, std::map<String, String>> m_globalPropertiesCache;
192 };
193} // namespace tgui
194
195#endif // TGUI_THEME_LOADER_HPP
Base class for theme loader implementations.
Definition ThemeLoader.hpp:45
virtual bool canLoad(const String &primary, const String &secondary)=0
Check if the requested property-value pairs are available.
virtual void preload(const String &primary)
Optionally already do some work when only the primary parameter is known yet.
virtual std::map< String, String > getGlobalProperties(const String &primary)
Loads the global property-value pairs from the theme.
virtual const std::map< String, String > & load(const String &primary, const String &secondary)=0
Loads the property-value pairs from the theme.
virtual ~BaseThemeLoader()=default
Virtual destructor.
Default implementation for theme loading.
Definition ThemeLoader.hpp:121
static void flushCache(const String &filename="")
Empties the caches and force files to be reloaded.
bool canLoad(const String &filename, const String &section) override
Check if the requested property-value pairs are available.
std::map< String, String > getGlobalProperties(const String &filename) override
Loads the global property-value pairs from the theme.
const std::map< String, String > & load(const String &filename, const String &section) override
Loads the property-value pairs from the theme file.
virtual std::unique_ptr< DataIO::Node > readFile(const String &filename) const
Reads and return the contents of the entire file.
void preload(const String &filename) override
Loads the theme file in cache.
Wrapper class to store strings.
Definition String.hpp:94
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37