implement style priority with # syntax

master
Eduardo Bart 12 years ago
parent 0a6470eac4
commit cae4d46a7d

@ -576,6 +576,7 @@ void Application::registerLuaFunctions()
// UI
g_lua.registerStaticClass("g_ui");
g_lua.bindClassStaticFunction("g_ui", "clearStyles", std::bind(&UIManager::clearStyles, &g_ui));
g_lua.bindClassStaticFunction("g_ui", "importStyle", std::bind(&UIManager::importStyle, &g_ui, std::placeholders::_1));
g_lua.bindClassStaticFunction("g_ui", "getStyle", std::bind(&UIManager::getStyle, &g_ui, std::placeholders::_1));
g_lua.bindClassStaticFunction("g_ui", "getStyleClass", std::bind(&UIManager::getStyleClass, &g_ui, std::placeholders::_1));

@ -293,6 +293,11 @@ void UIManager::onWidgetDestroy(const UIWidgetPtr& widget)
#endif
}
void UIManager::clearStyles()
{
m_styles.clear();
}
bool UIManager::importStyle(const std::string& file)
{
try {
@ -317,10 +322,19 @@ void UIManager::importStyleFromOTML(const OTMLNodePtr& styleNode)
std::string name = split[0];
std::string base = split[1];
bool unique = false;
boost::trim(name);
boost::trim(base);
if(name[0] == '#') {
name = name.substr(1);
unique = true;
styleNode->setTag(name);
styleNode->writeAt("__unique", true);
}
// TODO: styles must be searched by widget scopes, in that way this warning could be fixed
// this warning is disabled because many ppl was complening about it
/*
@ -329,13 +343,16 @@ void UIManager::importStyleFromOTML(const OTMLNodePtr& styleNode)
g_logger.warning("style '%s' is being redefined", name);
*/
OTMLNodePtr originalStyle = getStyle(base);
if(!originalStyle)
stdext::throw_exception(stdext::format("base style '%s', is not defined", base));
OTMLNodePtr style = originalStyle->clone();
style->merge(styleNode);
style->setTag(name);
m_styles[name] = style;
OTMLNodePtr oldStyle = m_styles[name];
if(!oldStyle || oldStyle->valueAt("__unique", false) || unique) {
OTMLNodePtr originalStyle = getStyle(base);
if(!originalStyle)
stdext::throw_exception(stdext::format("base style '%s', is not defined", base));
OTMLNodePtr style = originalStyle->clone();
style->merge(styleNode);
style->setTag(name);
m_styles[name] = style;
}
}
OTMLNodePtr UIManager::getStyle(const std::string& styleName)

@ -41,6 +41,7 @@ public:
bool updateDraggingWidget(const UIWidgetPtr& draggingWidget, const Point& clickedPos = Point());
void updateHoveredWidget();
void clearStyles();
bool importStyle(const std::string& file);
void importStyleFromOTML(const OTMLNodePtr& styleNode);
OTMLNodePtr getStyle(const std::string& styleName);

Loading…
Cancel
Save