From 997751f56a4dacaaeff2cca0da6da9aae3942481 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Thu, 9 Jan 2014 17:13:52 -0600 Subject: [PATCH] Fixed draw order for extra elements. --- src/ThemeData.cpp | 12 ++++++++---- src/ThemeData.h | 20 ++------------------ 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/ThemeData.cpp b/src/ThemeData.cpp index b885877ce..8d68dec20 100644 --- a/src/ThemeData.cpp +++ b/src/ThemeData.cpp @@ -211,6 +211,9 @@ void ThemeData::parseView(const pugi::xml_node& root, ThemeView& view) 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); } } @@ -325,18 +328,19 @@ std::vector ThemeData::makeExtras(const std::shared_ptrmViews.end()) return comps; - for(auto it = viewIt->second.elements.begin(); it != viewIt->second.elements.end(); it++) + for(auto it = viewIt->second.orderedKeys.begin(); it != viewIt->second.orderedKeys.end(); it++) { - if(it->second.extra) + ThemeElement& elem = viewIt->second.elements.at(*it); + if(elem.extra) { GuiComponent* comp = NULL; - const std::string& t = it->second.type; + const std::string& t = elem.type; if(t == "image") comp = new ImageComponent(window); else if(t == "text") comp = new TextComponent(window); - comp->applyTheme(theme, view, it->first, ThemeFlags::ALL); + comp->applyTheme(theme, view, *it, ThemeFlags::ALL); comps.push_back(comp); } } diff --git a/src/ThemeData.h b/src/ThemeData.h index 561dcf910..dc9e81bbe 100644 --- a/src/ThemeData.h +++ b/src/ThemeData.h @@ -73,12 +73,11 @@ class ThemeExtras : public GuiComponent { public: ThemeExtras(Window* window) : GuiComponent(window) {}; + virtual ~ThemeExtras(); // will take ownership of the components within extras (delete them in destructor or when setExtras is called again) void setExtras(const std::vector& extras); - virtual ~ThemeExtras(); - private: std::vector mExtras; }; @@ -106,6 +105,7 @@ private: { public: std::map elements; + std::vector orderedKeys; }; public: @@ -147,19 +147,3 @@ private: std::map mViews; }; - -// okay ideas for applying themes to GuiComponents: -// 1. ThemeData::applyToImage(component, args) -// NO, BECAUSE: -// - for templated types (TextListComponent) have to include the whole template in a header -// - inconsistent definitions if mixing templated types (some in a .cpp, some in a .h/.inl) -// 2. template ThemeData::apply(component, args) with specialized templates -// NO, BECAUSE: -// - doesn't solve the first drawback -// - can't customize arguments for specific types -// 3. GuiComponent::applyTheme(theme, args) - WINNER -// NO, BECAUSE: -// - can't access private members of ThemeData -// - can't this be solved with enough getters? -// - theme->hasElement and theme->getProperty will require 2x as many map lookups (4 vs 2) -// - why not just return a const ThemeElement... \ No newline at end of file