Fixed draw order for extra elements.

This commit is contained in:
Aloshi 2014-01-09 17:13:52 -06:00
parent 81a9941645
commit 997751f56a
2 changed files with 10 additions and 22 deletions

View file

@ -211,6 +211,9 @@ void ThemeData::parseView(const pugi::xml_node& root, ThemeView& view)
parseElement(node, elemTypeIt->second,
view.elements.insert(std::make_pair<std::string, ThemeElement>(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<GuiComponent*> ThemeData::makeExtras(const std::shared_ptr<ThemeData
if(viewIt == theme->mViews.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);
}
}

View file

@ -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<GuiComponent*>& extras);
virtual ~ThemeExtras();
private:
std::vector<GuiComponent*> mExtras;
};
@ -106,6 +105,7 @@ private:
{
public:
std::map<std::string, ThemeElement> elements;
std::vector<std::string> orderedKeys;
};
public:
@ -147,19 +147,3 @@ private:
std::map<std::string, ThemeView> 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<typename T> 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...