anchoring errors

master
Eduardo Bart 13 years ago
parent 51fe97644d
commit 42c1ae090c

@ -55,19 +55,27 @@ int Anchor::getAnchorLinePoint() const
} }
return -9999; return -9999;
} }
bool UIAnchorLayout::addAnchor(const UIElementPtr& anchoredElement, UI::AnchorPoint anchoredEdge, const AnchorLine& anchorLine) bool UIAnchorLayout::addAnchor(const UIElementPtr& anchoredElement, UI::AnchorPoint anchoredEdge, const AnchorLine& anchorLine)
{ {
Anchor anchor(anchoredElement, anchoredEdge, anchorLine); Anchor anchor(anchoredElement, anchoredEdge, anchorLine);
UIElementPtr anchorLineElement = anchor.getAnchorLineElement(); UIElementPtr anchorLineElement = anchor.getAnchorLineElement();
if(!anchorLineElement) {
logError("ERROR: could not find the element to anchor on, wrong id?");
return false;
}
// we can never anchor with itself // we can never anchor with itself
if(anchoredElement == anchorLineElement) { if(anchoredElement == anchorLineElement) {
logError("ERROR: anchoring with itself is not possible"); logError("ERROR: anchoring with itself is not possible");
return false; return false;
} }
// TODO: check if itself is already anchored on the anchor element // we must never anchor to an anchor child
if(hasElementInAnchorTree(anchorLineElement, anchoredElement)) {
logError("ERROR: anchors is miss configurated, you must never make anchor chains in loops");
return false;
}
// setup the anchor // setup the anchor
m_anchors.push_back(anchor); m_anchors.push_back(anchor);
@ -144,6 +152,17 @@ void UIAnchorLayout::recalculateChildrenLayout(const UIElementPtr& parent)
} }
} }
bool UIAnchorLayout::hasElementInAnchorTree(const UIElementPtr& element, const UIElementPtr& treeAnchor)
{
foreach(const Anchor& anchor, m_anchors) {
if(anchor.getAnchorLineElement() == treeAnchor) {
if(anchor.getAnchoredElement() == element || hasElementInAnchorTree(element, anchor.getAnchoredElement()))
return true;
}
}
return false;
}
UI::AnchorPoint UIAnchorLayout::parseAnchorPoint(const std::string& anchorPointStr) UI::AnchorPoint UIAnchorLayout::parseAnchorPoint(const std::string& anchorPointStr)
{ {
if(anchorPointStr == "left") if(anchorPointStr == "left")

@ -66,6 +66,7 @@ public:
void recalculateElementLayout(const UIElementPtr& element); void recalculateElementLayout(const UIElementPtr& element);
void recalculateChildrenLayout(const UIElementPtr& parent); void recalculateChildrenLayout(const UIElementPtr& parent);
bool hasElementInAnchorTree(const UIElementPtr& element, const UIElementPtr& treeAnchor);
static UI::AnchorPoint parseAnchorPoint(const std::string& anchorPointStr); static UI::AnchorPoint parseAnchorPoint(const std::string& anchorPointStr);
private: private:

Loading…
Cancel
Save