add API to remove widget anchors

This commit is contained in:
Eduardo Bart 2012-04-05 19:46:53 -03:00
parent 248ea9e8bc
commit 218f2e4994
4 changed files with 21 additions and 10 deletions

View File

@ -73,6 +73,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("unlockChild", &UIWidget::unlockChild); g_lua.bindClassMemberFunction<UIWidget>("unlockChild", &UIWidget::unlockChild);
g_lua.bindClassMemberFunction<UIWidget>("applyStyle", &UIWidget::applyStyle); g_lua.bindClassMemberFunction<UIWidget>("applyStyle", &UIWidget::applyStyle);
g_lua.bindClassMemberFunction<UIWidget>("addAnchor", &UIWidget::addAnchor); g_lua.bindClassMemberFunction<UIWidget>("addAnchor", &UIWidget::addAnchor);
g_lua.bindClassMemberFunction<UIWidget>("removeAnchor", &UIWidget::removeAnchor);
g_lua.bindClassMemberFunction<UIWidget>("fill", &UIWidget::fill); g_lua.bindClassMemberFunction<UIWidget>("fill", &UIWidget::fill);
g_lua.bindClassMemberFunction<UIWidget>("centerIn", &UIWidget::centerIn); g_lua.bindClassMemberFunction<UIWidget>("centerIn", &UIWidget::centerIn);
g_lua.bindClassMemberFunction<UIWidget>("breakAnchors", &UIWidget::breakAnchors); g_lua.bindClassMemberFunction<UIWidget>("breakAnchors", &UIWidget::breakAnchors);

View File

@ -489,6 +489,11 @@ void UIWidget::addAnchor(Fw::AnchorEdge anchoredEdge, const std::string& hookedW
logError("cannot add anchors to widget ", m_id, ": the parent doesn't use anchors layout"); logError("cannot add anchors to widget ", m_id, ": the parent doesn't use anchors layout");
} }
void UIWidget::removeAnchor(Fw::AnchorEdge anchoredEdge)
{
addAnchor(anchoredEdge, "none", Fw::AnchorNone);
}
void UIWidget::centerIn(const std::string& hookedWidgetId) void UIWidget::centerIn(const std::string& hookedWidgetId)
{ {
if(m_destroyed) if(m_destroyed)

View File

@ -92,6 +92,7 @@ public:
void unlockChild(const UIWidgetPtr& child); void unlockChild(const UIWidgetPtr& child);
void applyStyle(const OTMLNodePtr& styleNode); void applyStyle(const OTMLNodePtr& styleNode);
void addAnchor(Fw::AnchorEdge anchoredEdge, const std::string& hookedWidgetId, Fw::AnchorEdge hookedEdge); void addAnchor(Fw::AnchorEdge anchoredEdge, const std::string& hookedWidgetId, Fw::AnchorEdge hookedEdge);
void removeAnchor(Fw::AnchorEdge anchoredEdge);
void fill(const std::string& hookedWidgetId); void fill(const std::string& hookedWidgetId);
void centerIn(const std::string& hookedWidgetId); void centerIn(const std::string& hookedWidgetId);
void breakAnchors(); void breakAnchors();

View File

@ -278,6 +278,9 @@ void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
} else { } else {
Fw::AnchorEdge anchoredEdge = Fw::translateAnchorEdge(what); Fw::AnchorEdge anchoredEdge = Fw::translateAnchorEdge(what);
if(node->value() == "none") {
removeAnchor(anchoredEdge);
} else {
std::vector<std::string> split = Fw::split(node->value(), "."); std::vector<std::string> split = Fw::split(node->value(), ".");
if(split.size() != 2) if(split.size() != 2)
throw OTMLException(node, "invalid anchor description"); throw OTMLException(node, "invalid anchor description");
@ -293,6 +296,7 @@ void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
addAnchor(anchoredEdge, hookedWidgetId, hookedEdge); addAnchor(anchoredEdge, hookedWidgetId, hookedEdge);
} }
}
// lua functions // lua functions
} else if(boost::starts_with(node->tag(), "@")) { } else if(boost::starts_with(node->tag(), "@")) {
// load once // load once