TDME2  1.9.200
GUILayerNode.cpp
Go to the documentation of this file.
2 
3 #include <set>
4 #include <string>
5 
6 #include <tdme/tdme.h>
19 #include <tdme/gui/GUI.h>
20 
21 using std::set;
22 using std::to_string;
23 
25 
37 using tdme::gui::GUI;
38 
39 GUILayerNode::GUILayerNode(
40  GUIScreenNode* screenNode,
41  GUIParentNode* parentNode,
42  const string& id,
43  GUINode_Flow* flow,
44  GUIParentNode_Overflow* overflowX,
45  GUIParentNode_Overflow* overflowY,
46  const GUINode_Alignments& alignments,
47  const GUINode_RequestedConstraints& requestedConstraints,
48  const GUIColor& backgroundColor,
49  const string& backgroundImage,
50  const GUINode_Scale9Grid& backgroundImageScaleGrid,
51  const GUIColor& backgroundImageEffectColorMul,
52  const GUIColor& backgroundImageEffectColorAdd,
53  const GUINode_Border& border,
54  const GUINode_Padding& padding,
55  const GUINodeConditions& showOn,
56  const GUINodeConditions& hideOn,
57  const string& tooltip
58  ) :
59  GUIParentNode(screenNode, parentNode, id, flow, overflowX, overflowY, alignments, requestedConstraints, backgroundColor, backgroundImage, backgroundImageScaleGrid, backgroundImageEffectColorMul, backgroundImageEffectColorAdd, border, padding, showOn, hideOn, tooltip)
60 {
61 }
62 
64 {
65  return "element";
66 }
67 
69 {
70  return false;
71 }
72 
74 {
75  auto width = 0;
76  for (auto i = 0; i < subNodes.size(); i++) {
77  auto guiSubNode = subNodes[i];
78  if (guiSubNode->conditionsMet == false) continue;
79  auto contentWidth = guiSubNode->getAutoWidth();
80  if (contentWidth > width) {
81  width = contentWidth;
82  }
83  }
84  width += border.left + border.right;
85  width += padding.left + padding.right;
86  return width;
87 }
88 
90 {
91  auto height = 0;
92  for (auto i = 0; i < subNodes.size(); i++) {
93  auto guiSubNode = subNodes[i];
94  if (guiSubNode->conditionsMet == false) continue;
95  auto contentHeight = guiSubNode->getAutoHeight();
96  if (contentHeight > height) {
97  height = contentHeight;
98  }
99  }
100  height += border.top + border.bottom;
101  height += padding.top + padding.bottom;
102  return height;
103 }
104 
105 void GUILayerNode::setTop(int top)
106 {
110  for (auto i = 0; i < subNodes.size(); i++) {
111  auto guiSubNode = subNodes[i];
112  if (guiSubNode->conditionsMet == false) continue;
113  guiSubNode->setTop(top);
114  }
115 }
116 
117 void GUILayerNode::setLeft(int left)
118 {
122  for (auto i = 0; i < subNodes.size(); i++) {
123  auto guiSubNode = subNodes[i];
124  if (guiSubNode->conditionsMet == false) continue;
125  guiSubNode->setLeft(left);
126  }
127 }
128 
130 {
131  if (conditionsMet == false) return;
135  for (auto i = 0; i < subNodes.size(); i++) {
136  auto guiSubNode = subNodes[i];
137  if (guiSubNode->conditionsMet == false) continue;
138  auto doLayoutSubNodes = false;
139  if (guiSubNode->requestedConstraints.heightType == GUINode_RequestedConstraints_RequestedConstraintsType::STAR) {
140  guiSubNode->computedConstraints.height = height;
141  doLayoutSubNodes = true;
142  } else
143  if (guiSubNode->requestedConstraints.widthType == GUINode_RequestedConstraints_RequestedConstraintsType::STAR) {
144  guiSubNode->computedConstraints.width = width;
145  doLayoutSubNodes = true;
146  }
147  if (dynamic_cast<GUIParentNode*>(guiSubNode) != nullptr && doLayoutSubNodes == true) {
148  (required_dynamic_cast<GUIParentNode*>(guiSubNode))->layoutSubNodes();
149  }
150  }
155 }
156 
158 {
159  if (conditionsMet == false) return;
161  auto subNodesHeight = requestedConstraints.height - border.top - border.bottom - padding.top - padding.bottom;
162  for (auto i = 0; i < subNodes.size(); i++) {
163  auto guiSubNode = subNodes[i];
164  if (guiSubNode->conditionsMet == false) continue;
165  if (overflowY == GUIParentNode_Overflow::DOWNSIZE_CHILDREN && guiSubNode->requestedConstraints.heightType == GUINode_RequestedConstraints_RequestedConstraintsType::PIXEL && guiSubNode->requestedConstraints.height > subNodesHeight) {
166  guiSubNode->requestedConstraints.height = subNodesHeight;
167  }
168  }
169  }
172  for (auto i = 0; i < subNodes.size(); i++) {
173  auto guiSubNode = subNodes[i];
174  if (guiSubNode->conditionsMet == false) continue;
175  if (overflowY == GUIParentNode_Overflow::DOWNSIZE_CHILDREN && guiSubNode->requestedConstraints.widthType == GUINode_RequestedConstraints_RequestedConstraintsType::PIXEL && guiSubNode->requestedConstraints.width > subNodesWidth) {
176  guiSubNode->requestedConstraints.width = subNodesWidth;
177  }
178  }
179  }
181 }
GUI module class.
Definition: GUI.h:64
const string getNodeType() override
void setTop(int top) override
Set computed top.
void layout() override
Layout.
void setLeft(int left) override
Set computed left.
void layoutSubNodes() override
Layout sub nodes.
GUI element node conditions.
static STATIC_DLL_IMPEXT GUINode_RequestedConstraints_RequestedConstraintsType * STAR
static STATIC_DLL_IMPEXT GUINode_RequestedConstraints_RequestedConstraintsType * PIXEL
GUI node base class.
Definition: GUINode.h:64
GUINode_Border border
Definition: GUINode.h:160
virtual void setLeft(int left)
Set computed left.
Definition: GUINode.cpp:179
GUINode_ComputedConstraints computedConstraints
Definition: GUINode.h:152
GUINode_Padding padding
Definition: GUINode.h:159
virtual void setTop(int top)
Set computed top.
Definition: GUINode.cpp:185
GUINode_RequestedConstraints requestedConstraints
Definition: GUINode.h:151
static STATIC_DLL_IMPEXT GUIParentNode_Overflow * DOWNSIZE_CHILDREN
GUI parent node base class thats supporting child nodes.
Definition: GUIParentNode.h:42
virtual void computeHorizontalChildrenAlignment()
Compute horizontal children alignment.
void layout() override
Layout.
GUIParentNode_Overflow * overflowY
Definition: GUIParentNode.h:67
virtual void layoutSubNodes()
Layout sub nodes.
vector< GUINode * > subNodes
Definition: GUIParentNode.h:62
virtual void computeVerticalChildrenAlignment()
Compute vertical children alignment.
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:72
GUI node border entity.
GUI node padding entity.
GUINode_RequestedConstraints_RequestedConstraintsType * topType
GUINode_RequestedConstraints_RequestedConstraintsType * widthType
GUINode_RequestedConstraints_RequestedConstraintsType * leftType
GUINode_RequestedConstraints_RequestedConstraintsType * heightType
GUI node scale 9 grid entity.