Otclient  14/8/2020
uianchorlayout.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 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 
29 {
30 public:
31  UIAnchor(Fw::AnchorEdge anchoredEdge, const std::string& hookedWidgetId, Fw::AnchorEdge hookedEdge) :
32  m_anchoredEdge(anchoredEdge), m_hookedEdge(hookedEdge), m_hookedWidgetId(hookedWidgetId) { }
33 
36 
37  virtual UIWidgetPtr getHookedWidget(const UIWidgetPtr& widget, const UIWidgetPtr& parentWidget);
38  virtual int getHookedPoint(const UIWidgetPtr& hookedWidget, const UIWidgetPtr& parentWidget);
39 
40 protected:
43  std::string m_hookedWidgetId;
44 };
45 
47 {
48 public:
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 
56 private:
57  UIAnchorList m_anchors;
58  bool m_updated;
59 };
60 
61 // @bindclass
62 class UIAnchorLayout : public UILayout
63 {
64 public:
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 
79 protected:
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
UILayout
Definition: uilayout.h:31
UIAnchor::getAnchoredEdge
Fw::AnchorEdge getAnchoredEdge() const
Definition: uianchorlayout.h:34
UIAnchor::UIAnchor
UIAnchor(Fw::AnchorEdge anchoredEdge, const std::string &hookedWidgetId, Fw::AnchorEdge hookedEdge)
Definition: uianchorlayout.h:31
UIAnchorLayout::hasAnchors
bool hasAnchors(const UIWidgetPtr &anchoredWidget)
Definition: uianchorlayout.cpp:133
Fw::AnchorEdge
AnchorEdge
Definition: const.h:211
UIAnchorGroup
Definition: uianchorlayout.h:46
UIAnchorLayout
Definition: uianchorlayout.h:62
UIAnchorLayout::removeAnchors
void removeAnchors(const UIWidgetPtr &anchoredWidget)
Definition: uianchorlayout.cpp:127
UIAnchorList
std::vector< UIAnchorPtr > UIAnchorList
Definition: declarations.h:54
UIAnchorLayout::centerIn
void centerIn(const UIWidgetPtr &anchoredWidget, const std::string &hookedWidgetId)
Definition: uianchorlayout.cpp:138
UIAnchor
Definition: uianchorlayout.h:28
UIAnchorGroup::setUpdated
void setUpdated(bool updated)
Definition: uianchorlayout.h:54
UIAnchorLayout::addWidget
void addWidget(const UIWidgetPtr &widget)
Definition: uianchorlayout.cpp:152
UIAnchor::m_hookedWidgetId
std::string m_hookedWidgetId
Definition: uianchorlayout.h:43
UIAnchorGroup::getAnchors
const UIAnchorList & getAnchors()
Definition: uianchorlayout.h:52
UIAnchor::getHookedPoint
virtual int getHookedPoint(const UIWidgetPtr &hookedWidget, const UIWidgetPtr &parentWidget)
Definition: uianchorlayout.cpp:43
UIAnchorLayout::isUIAnchorLayout
bool isUIAnchorLayout()
Definition: uianchorlayout.h:77
UIAnchorLayout::fill
void fill(const UIWidgetPtr &anchoredWidget, const std::string &hookedWidgetId)
Definition: uianchorlayout.cpp:144
UIAnchor::getHookedEdge
Fw::AnchorEdge getHookedEdge() const
Definition: uianchorlayout.h:35
UIAnchorGroup::UIAnchorGroup
UIAnchorGroup()
Definition: uianchorlayout.h:49
UIAnchorLayout::UIAnchorLayout
UIAnchorLayout(UIWidgetPtr parentWidget)
Definition: uianchorlayout.h:65
UIAnchor::getHookedWidget
virtual UIWidgetPtr getHookedWidget(const UIWidgetPtr &widget, const UIWidgetPtr &parentWidget)
Definition: uianchorlayout.cpp:26
UIAnchorLayout::addAnchor
void addAnchor(const UIWidgetPtr &anchoredWidget, Fw::AnchorEdge anchoredEdge, const std::string &hookedWidgetId, Fw::AnchorEdge hookedEdge)
Definition: uianchorlayout.cpp:108
UIAnchorLayout::updateWidget
virtual bool updateWidget(const UIWidgetPtr &widget, const UIAnchorGroupPtr &anchorGroup, UIWidgetPtr first=nullptr)
Definition: uianchorlayout.cpp:162
stdext::shared_object_ptr< UIWidget >
UIAnchorLayout::removeWidget
void removeWidget(const UIWidgetPtr &widget)
Definition: uianchorlayout.cpp:157
uilayout.h
UIAnchor::m_anchoredEdge
Fw::AnchorEdge m_anchoredEdge
Definition: uianchorlayout.h:41
UIAnchorLayout::internalUpdate
virtual bool internalUpdate()
Definition: uianchorlayout.cpp:254
UIAnchorLayout::m_anchorsGroups
std::unordered_map< UIWidgetPtr, UIAnchorGroupPtr > m_anchorsGroups
Definition: uianchorlayout.h:82
UIAnchorGroup::isUpdated
bool isUpdated()
Definition: uianchorlayout.h:53
UIAnchor::m_hookedEdge
Fw::AnchorEdge m_hookedEdge
Definition: uianchorlayout.h:42
stdext::shared_object
Definition: shared_object.h:41
UIAnchorGroup::addAnchor
void addAnchor(const UIAnchorPtr &anchor)
Definition: uianchorlayout.cpp:96