tibia-client/src/framework/ui/uianchorlayout.h

67 lines
1.9 KiB
C
Raw Normal View History

#ifndef UIANCHORLAYOUT_H
#define UIANCHORLAYOUT_H
2011-07-13 23:12:36 +02:00
#include <global.h>
#include <ui/uilayout.h>
2011-07-17 08:56:57 +02:00
class UIElement;
typedef std::shared_ptr<UIElement> UIElementPtr;
typedef std::weak_ptr<UIElement> UIElementWeakPtr;
2011-07-17 08:56:57 +02:00
enum AnchorPoint {
AnchorNone = 0,
AnchorTop,
AnchorBottom,
AnchorLeft,
AnchorRight,
AnchorVerticalCenter,
AnchorHorizontalCenter,
};
class AnchorLine
{
public:
2011-07-17 08:56:57 +02:00
AnchorLine(const std::string& elementId, AnchorPoint edge) : m_elementId(elementId), m_edge(edge) { }
AnchorLine(const AnchorLine& other) : m_elementId(other.m_elementId), m_edge(other.m_edge) { }
2011-07-17 08:56:57 +02:00
AnchorPoint getEdge() const { return m_edge; }
const std::string& getElementId() const { return m_elementId; }
private:
std::string m_elementId;
2011-07-17 08:56:57 +02:00
AnchorPoint m_edge;
};
class Anchor
{
public:
2011-07-17 08:56:57 +02:00
Anchor(const UIElementPtr& anchoredElement, AnchorPoint anchoredEdge, const AnchorLine& anchorLine)
: m_anchoredElement(anchoredElement), m_anchoredEdge(anchoredEdge), m_anchorLine(anchorLine) { }
UIElementPtr getAnchorLineElement() const ;
UIElementPtr getAnchoredElement() const { return m_anchoredElement.lock(); }
2011-07-17 08:56:57 +02:00
AnchorPoint getAnchoredEdge() const { return m_anchoredEdge; }
int getAnchorLinePoint() const;
private:
UIElementWeakPtr m_anchoredElement;
2011-07-17 08:56:57 +02:00
AnchorPoint m_anchoredEdge;
AnchorLine m_anchorLine;
};
class UIAnchorLayout : public UILayout
{
public:
2011-07-17 08:56:57 +02:00
bool addAnchor(const UIElementPtr& anchoredElement, AnchorPoint anchoredEdge, const AnchorLine& anchorLine);
void recalculateElementLayout(const UIElementPtr& element);
void recalculateChildrenLayout(const UIElementPtr& parent);
2011-05-09 23:08:17 +02:00
bool hasElementInAnchorTree(const UIElementPtr& element, const UIElementPtr& treeAnchor);
2011-07-17 08:56:57 +02:00
static AnchorPoint parseAnchorPoint(const std::string& anchorPointStr);
private:
std::vector<Anchor> m_anchors;
};
typedef std::shared_ptr<UIAnchorLayout> UIAnchorLayoutPtr;
#endif // UIANCHORLAYOUT_H