TGUI  1.3.0
Loading...
Searching...
No Matches

Default implementation for theme loading. More...

#include <TGUI/Loading/ThemeLoader.hpp>

Inheritance diagram for tgui::DefaultThemeLoader:
tgui::BaseThemeLoader

Public Member Functions

void preload (const String &filename) override
 Loads the theme file in cache.
 
TGUI_NODISCARD std::map< String, StringgetGlobalProperties (const String &filename) override
 Loads the global property-value pairs from the theme.
 
TGUI_NODISCARD const std::map< String, String > & load (const String &filename, const String &section) override
 Loads the property-value pairs from the theme file.
 
TGUI_NODISCARD bool canLoad (const String &filename, const String &section) override
 Check if the requested property-value pairs are available.
 
- Public Member Functions inherited from tgui::BaseThemeLoader
virtual ~BaseThemeLoader ()=default
 Virtual destructor.
 

Static Public Member Functions

static void flushCache (const String &filename="")
 Empties the caches and force files to be reloaded.
 

Protected Member Functions

virtual TGUI_NODISCARD std::unique_ptr< DataIO::Node > readFile (const String &filename) const
 Reads and return the contents of the entire file.
 
- Protected Member Functions inherited from tgui::BaseThemeLoader
void injectThemePath (const std::unique_ptr< DataIO::Node > &node, const String &path) const
 
void resolveReferences (std::map< String, std::reference_wrapper< const std::unique_ptr< DataIO::Node > > > &sections, const std::map< String, String > &globalProperties, const std::unique_ptr< DataIO::Node > &node) const
 

Static Protected Attributes

static std::map< String, std::map< String, std::map< String, String > > > m_propertiesCache
 
static std::map< String, std::map< String, String > > m_globalPropertiesCache
 

Detailed Description

Default implementation for theme loading.

Themes are stored on disk in files which contain sections with a syntax similar to CSS. This loader will be able to extract the data from these files.

On first access, the entire file will be cached, the next times the cached map is simply returned.

Member Function Documentation

◆ canLoad()

TGUI_NODISCARD bool tgui::DefaultThemeLoader::canLoad ( const String & filename,
const String & section )
overridevirtual

Check if the requested property-value pairs are available.

Parameters
filenameFilename of the theme file
sectionName of the section inside the theme file
Returns
Whether a map op property-value pairs is available

Implements tgui::BaseThemeLoader.

◆ flushCache()

static void tgui::DefaultThemeLoader::flushCache ( const String & filename = "")
static

Empties the caches and force files to be reloaded.

Parameters
filenameFile to remove from cache. If no filename is given, the entire cache is cleared.

The first time a filename is loaded, its contents is fully cached. If this function isn't called then loading the same file will only read the cache instead of reading the file from disk again.

◆ getGlobalProperties()

TGUI_NODISCARD std::map< String, String > tgui::DefaultThemeLoader::getGlobalProperties ( const String & filename)
overridevirtual

Loads the global property-value pairs from the theme.

Parameters
filenameFilename of the theme file to load
Returns
Map of property-value pairs

Reimplemented from tgui::BaseThemeLoader.

◆ load()

TGUI_NODISCARD const std::map< String, String > & tgui::DefaultThemeLoader::load ( const String & filename,
const String & section )
overridevirtual

Loads the property-value pairs from the theme file.

Parameters
filenameFilename of the theme file
sectionName of the section inside the theme file
Returns
Map of property-value pairs
Exceptions
Exceptionwhen finding syntax errors in the file
Exceptionwhen file did not contain requested class name

Implements tgui::BaseThemeLoader.

◆ preload()

void tgui::DefaultThemeLoader::preload ( const String & filename)
overridevirtual

Loads the theme file in cache.

Parameters
filenameFilename of the theme file to load
Exceptions
Exceptionwhen finding syntax errors in the file

Reimplemented from tgui::BaseThemeLoader.

◆ readFile()

virtual TGUI_NODISCARD std::unique_ptr< DataIO::Node > tgui::DefaultThemeLoader::readFile ( const String & filename) const
protectedvirtual

Reads and return the contents of the entire file.

Parameters
filenameFilename of the file to read
Returns
Root node of the parsed file, obtained by calling DataIO::parse(fileContents)

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