implement style priority with # syntax
This commit is contained in:
parent
0a6470eac4
commit
cae4d46a7d
|
@ -576,6 +576,7 @@ void Application::registerLuaFunctions()
|
||||||
|
|
||||||
// UI
|
// UI
|
||||||
g_lua.registerStaticClass("g_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", "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", "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));
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UIManager::clearStyles()
|
||||||
|
{
|
||||||
|
m_styles.clear();
|
||||||
|
}
|
||||||
|
|
||||||
bool UIManager::importStyle(const std::string& file)
|
bool UIManager::importStyle(const std::string& file)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
@ -317,10 +322,19 @@ void UIManager::importStyleFromOTML(const OTMLNodePtr& styleNode)
|
||||||
|
|
||||||
std::string name = split[0];
|
std::string name = split[0];
|
||||||
std::string base = split[1];
|
std::string base = split[1];
|
||||||
|
bool unique = false;
|
||||||
|
|
||||||
boost::trim(name);
|
boost::trim(name);
|
||||||
boost::trim(base);
|
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
|
// 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
|
// this warning is disabled because many ppl was complening about it
|
||||||
/*
|
/*
|
||||||
|
@ -329,6 +343,8 @@ void UIManager::importStyleFromOTML(const OTMLNodePtr& styleNode)
|
||||||
g_logger.warning("style '%s' is being redefined", name);
|
g_logger.warning("style '%s' is being redefined", name);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
OTMLNodePtr oldStyle = m_styles[name];
|
||||||
|
if(!oldStyle || oldStyle->valueAt("__unique", false) || unique) {
|
||||||
OTMLNodePtr originalStyle = getStyle(base);
|
OTMLNodePtr originalStyle = getStyle(base);
|
||||||
if(!originalStyle)
|
if(!originalStyle)
|
||||||
stdext::throw_exception(stdext::format("base style '%s', is not defined", base));
|
stdext::throw_exception(stdext::format("base style '%s', is not defined", base));
|
||||||
|
@ -336,6 +352,7 @@ void UIManager::importStyleFromOTML(const OTMLNodePtr& styleNode)
|
||||||
style->merge(styleNode);
|
style->merge(styleNode);
|
||||||
style->setTag(name);
|
style->setTag(name);
|
||||||
m_styles[name] = style;
|
m_styles[name] = style;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OTMLNodePtr UIManager::getStyle(const std::string& styleName)
|
OTMLNodePtr UIManager::getStyle(const std::string& styleName)
|
||||||
|
|
|
@ -41,6 +41,7 @@ public:
|
||||||
bool updateDraggingWidget(const UIWidgetPtr& draggingWidget, const Point& clickedPos = Point());
|
bool updateDraggingWidget(const UIWidgetPtr& draggingWidget, const Point& clickedPos = Point());
|
||||||
void updateHoveredWidget();
|
void updateHoveredWidget();
|
||||||
|
|
||||||
|
void clearStyles();
|
||||||
bool importStyle(const std::string& file);
|
bool importStyle(const std::string& file);
|
||||||
void importStyleFromOTML(const OTMLNodePtr& styleNode);
|
void importStyleFromOTML(const OTMLNodePtr& styleNode);
|
||||||
OTMLNodePtr getStyle(const std::string& styleName);
|
OTMLNodePtr getStyle(const std::string& styleName);
|
||||||
|
|
Loading…
Reference in New Issue