Removed the overly-complicated "common" view.

Replaced it with the ability to specify multiple views in a theme tag,
just like for elements.
This commit is contained in:
Aloshi 2014-03-06 21:35:13 -06:00
parent 3ba7cd1247
commit 5d6733991a
2 changed files with 24 additions and 29 deletions

View file

@ -81,7 +81,7 @@ It is recommended that if you are writing a theme you launch EmulationStation wi
### The `<include>` tag
You can include theme files within theme files, similar to `#include` in C (though the mechanism is different, the effect is the same). Example:
You can include theme files within theme files, similar to `#include` in C (though the internal mechanism is different, the effect is the same). Example:
`~/.emulationstation/all_themes.xml`:
```xml
@ -126,14 +126,14 @@ Notice that properties that were not specified got merged (`<fontPath>`) and the
### The "common" view
### Theming multiple views simultaneously
Sometimes you want to apply the same values to the same element across many views. The "common" view is one way to do this.
Sometimes you want to apply the same properties to the same elements across multiple views. The `name` attribute actually works as a list (delimited by any characters of `\t\r\n ,` - that is, whitespace and commas). So, for example, to easily apply the same header to the basic, grid, and system views:
```xml
<theme>
<version>3</version>
<view name="common">
<view name="basic, grid, system">
<image name="header">
<path>./snes_art/snes_header.png</path>
</image>
@ -146,7 +146,7 @@ Sometimes you want to apply the same values to the same element across many view
</theme>
```
Is equivalent to:
This is equivalent to:
```xml
<theme>
<version>3</version>
@ -174,15 +174,11 @@ Is equivalent to:
</theme>
```
Notice that you can still override the "common" view in a specific view definition (as shown in the "detailed" view).
You probably should not use the "common" view for element positioning. You also should not use it to create "extra" elements.
### Theming multiple elements simultaneously
### Theming more than one elements at once
You can theme multiple elements *of the same type* simultaneously. The `name` attribute actually works as a list (delimited by any characters of `\t\n ,` - that is, whitespace and commas). This is useful if you want to, say, apply the same color to all the metadata labels:
You can theme multiple elements *of the same type* simultaneously. The `name` attribute actually works as a list (delimited by any characters of `\t\r\n ,` - that is, whitespace and commas), just like it does for views, as long as the elements have the same type. This is useful if you want to, say, apply the same color to all the metadata labels:
```xml
<theme>
@ -197,7 +193,7 @@ You can theme multiple elements *of the same type* simultaneously. The `name` a
</theme>
```
Is equivalent to:
Which is equivalent to:
```xml
<theme>
<version>3</version>

View file

@ -201,24 +201,28 @@ void ThemeData::parseViews(const pugi::xml_node& root)
ThemeException error;
error.setFiles(mPaths);
pugi::xml_node common = root.find_child_by_attribute("view", "name", "common");
// parse views
for(pugi::xml_node node = root.child("view"); node; node = node.next_sibling("view"))
{
if(!node.attribute("name"))
throw error << "View missing \"name\" attribute!";
const char* viewKey = node.attribute("name").as_string();
const char* delim = " \t\r\n,";
const std::string nameAttr = node.attribute("name").as_string();
size_t prevOff = nameAttr.find_first_not_of(delim, 0);
size_t off = nameAttr.find_first_of(delim, prevOff);
std::string viewKey;
while(off != std::string::npos || prevOff != std::string::npos)
{
viewKey = nameAttr.substr(prevOff, off - prevOff);
prevOff = nameAttr.find_first_not_of(delim, off);
off = nameAttr.find_first_of(delim, prevOff);
ThemeView& view = mViews.insert(std::pair<std::string, ThemeView>(viewKey, ThemeView())).first->second;
// load common first
if(common && node != common)
parseView(common, view);
parseView(node, view);
}
}
}
void ThemeData::parseView(const pugi::xml_node& root, ThemeView& view)
{
@ -234,7 +238,7 @@ void ThemeData::parseView(const pugi::xml_node& root, ThemeView& view)
if(elemTypeIt == sElementMap.end())
throw error << "Unknown element of type \"" << node.name() << "\"!";
const char* delim = " \t\n,";
const char* delim = " \t\r\n,";
const std::string nameAttr = node.attribute("name").as_string();
size_t prevOff = nameAttr.find_first_not_of(delim, 0);
size_t off = nameAttr.find_first_of(delim, prevOff);
@ -324,12 +328,7 @@ const ThemeData::ThemeElement* ThemeData::getElement(const std::string& view, co
{
auto viewIt = mViews.find(view);
if(viewIt == mViews.end())
{
// also check common if the view never existed to begin with
viewIt = mViews.find("common");
if(viewIt == mViews.end())
return NULL;
}
return NULL; // not found
auto elemIt = viewIt->second.elements.find(element);
if(elemIt == viewIt->second.elements.end()) return NULL;