TGUI  1.0-alpha

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. More...
 
std::map< String, StringgetGlobalProperties (const String &filename) override
 Loads the global property-value pairs from the theme. More...
 
const std::map< String, String > & load (const String &filename, const String &section) override
 Loads the property-value pairs from the theme file. More...
 
bool canLoad (const String &filename, const String &section) override
 Check if the requested property-value pairs are available. More...
 
- Public Member Functions inherited from tgui::BaseThemeLoader
virtual ~BaseThemeLoader ()=default
 Virtual destructor.
 
virtual void preload (const String &primary)
 Optionally already do some work when only the primary parameter is known yet. More...
 
virtual std::map< String, StringgetGlobalProperties (const String &primary)
 Loads the global property-value pairs from the theme. More...
 
virtual const std::map< String, String > & load (const String &primary, const String &secondary)=0
 Loads the property-value pairs from the theme. More...
 
virtual bool canLoad (const String &primary, const String &secondary)=0
 Check if the requested property-value pairs are available. More...
 

Static Public Member Functions

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

Protected Member Functions

virtual std::unique_ptr< DataIO::Node > readFile (const String &filename) const
 Reads and return the contents of the entire file. More...
 
- 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()

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()

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()

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 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: