1/*
2 * Copyright (c) 2010-2017 OTClient <https://github.com/edubart/otclient>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#ifndef UIANCHORLAYOUT_H
24#define UIANCHORLAYOUT_H
25
26#include "uilayout.h"
27
28class UIAnchor : public stdext::shared_object
29{
30public:
31 UIAnchor(Fw::AnchorEdge anchoredEdge, const std::string& hookedWidgetId, Fw::AnchorEdge hookedEdge) :
32 m_anchoredEdge(anchoredEdge), m_hookedEdge(hookedEdge), m_hookedWidgetId(hookedWidgetId) { }
33
34 Fw::AnchorEdge getAnchoredEdge() const { return m_anchoredEdge; }
35 Fw::AnchorEdge getHookedEdge() const { return m_hookedEdge; }
36
37 virtual UIWidgetPtr getHookedWidget(const UIWidgetPtr& widget, const UIWidgetPtr& parentWidget);
38 virtual int getHookedPoint(const UIWidgetPtr& hookedWidget, const UIWidgetPtr& parentWidget);
39
40protected:
41 Fw::AnchorEdge m_anchoredEdge;
42 Fw::AnchorEdge m_hookedEdge;
43 std::string m_hookedWidgetId;
44};
45
46class UIAnchorGroup : public stdext::shared_object
47{
48public:
49 UIAnchorGroup() : m_updated(true) { }
50
51 void addAnchor(const UIAnchorPtr& anchor);
52 const UIAnchorList& getAnchors() { return m_anchors; }
53 bool isUpdated() { return m_updated; }
54 void setUpdated(bool updated) { m_updated = updated; }
55
56private:
57 UIAnchorList m_anchors;
58 bool m_updated;
59};
60
61// @bindclass
62class UIAnchorLayout : public UILayout
63{
64public:
65 UIAnchorLayout(UIWidgetPtr parentWidget) : UILayout(parentWidget) { }
66
67 void addAnchor(const UIWidgetPtr& anchoredWidget, Fw::AnchorEdge anchoredEdge,
68 const std::string& hookedWidgetId, Fw::AnchorEdge hookedEdge);
69 void removeAnchors(const UIWidgetPtr& anchoredWidget);
70 bool hasAnchors(const UIWidgetPtr& anchoredWidget);
71 void centerIn(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId);
72 void fill(const UIWidgetPtr& anchoredWidget, const std::string& hookedWidgetId);
73
74 void addWidget(const UIWidgetPtr& widget);
75 void removeWidget(const UIWidgetPtr& widget);
76
77 bool isUIAnchorLayout() { return true; }
78
79protected:
80 virtual bool internalUpdate();
81 virtual bool updateWidget(const UIWidgetPtr& widget, const UIAnchorGroupPtr& anchorGroup, UIWidgetPtr first = nullptr);
82 std::unordered_map<UIWidgetPtr, UIAnchorGroupPtr> m_anchorsGroups;
83};
84
85#endif
86