From 612b196b111aab89612a4941b5b18c44fc7fdcbc Mon Sep 17 00:00:00 2001 From: Aloshi Date: Fri, 24 Jan 2014 19:25:15 -0600 Subject: [PATCH] Added the ability to theme multiple elements of the same type simultaneously. --- THEMES.md | 54 +++++++++++++++++++++++++++++++++++++++++++++++ src/ThemeData.cpp | 25 +++++++++++++++------- 2 files changed, 71 insertions(+), 8 deletions(-) diff --git a/THEMES.md b/THEMES.md index f708c9a62..f062f07a2 100644 --- a/THEMES.md +++ b/THEMES.md @@ -179,6 +179,60 @@ Notice that you can still override the "common" view in a specific view definiti You probably should not use the "common" view for element positioning. You also should not use it to create "extra" elements. + +### 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: + +```xml + + 3 + + + + 48474D + + + +``` + +Is equivalent to: +```xml + + 3 + + + 48474D + + + 48474D + + + 48474D + + + 48474D + + + 48474D + + + 48474D + + + 48474D + + + 48474D + + + +``` + +Just remember, *this only works if the elements have the same type!* + + Reference ========= diff --git a/src/ThemeData.cpp b/src/ThemeData.cpp index 08f3b9244..6182499c0 100644 --- a/src/ThemeData.cpp +++ b/src/ThemeData.cpp @@ -222,13 +222,22 @@ void ThemeData::parseView(const pugi::xml_node& root, ThemeView& view) if(elemTypeIt == sElementMap.end()) throw error << "Unknown element of type \"" << node.name() << "\"!"; - const char* elemKey = node.attribute("name").as_string(); + const char* delim = " \t\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); + while(off != std::string::npos || prevOff != std::string::npos) + { + std::string elemKey = nameAttr.substr(prevOff, off - prevOff); + prevOff = nameAttr.find_first_not_of(delim, off); + off = nameAttr.find_first_of(delim, prevOff); + + parseElement(node, elemTypeIt->second, + view.elements.insert(std::make_pair(elemKey, ThemeElement())).first->second); - parseElement(node, elemTypeIt->second, - view.elements.insert(std::make_pair(elemKey, ThemeElement())).first->second); - - if(std::find(view.orderedKeys.begin(), view.orderedKeys.end(), elemKey) == view.orderedKeys.end()) - view.orderedKeys.push_back(elemKey); + if(std::find(view.orderedKeys.begin(), view.orderedKeys.end(), elemKey) == view.orderedKeys.end()) + view.orderedKeys.push_back(elemKey); + } } } @@ -255,7 +264,7 @@ void ThemeData::parseElement(const pugi::xml_node& root, const std::map