TDME2  1.9.200
GUITableNode.cpp
Go to the documentation of this file.
2 
3 #include <tdme/tdme.h>
19 #include <tdme/gui/GUI.h>
20 #include <tdme/math/Math.h>
22 
24 
40 using tdme::gui::GUI;
41 using tdme::math::Math;
43 
44 GUITableNode::GUITableNode(
45  GUIScreenNode* screenNode,
46  GUIParentNode* parentNode,
47  const string& id,
48  GUINode_Flow* flow,
49  GUIParentNode_Overflow* overflowX,
50  GUIParentNode_Overflow* overflowY,
51  const GUINode_Alignments& alignments,
52  const GUINode_RequestedConstraints& requestedConstraints,
53  const GUIColor& backgroundColor,
54  const string& backgroundImage,
55  const GUINode_Scale9Grid& backgroundImageScale9Grid,
56  const GUIColor& backgroundImageEffectColorMul,
57  const GUIColor& backgroundImageEffectColorAdd,
58  const GUINode_Border& border,
59  const GUINode_Padding& padding,
60  const GUINodeConditions& showOn,
61  const GUINodeConditions& hideOn,
62  const string& tooltip
63 ):
64  GUIParentNode(screenNode, parentNode, id, flow, overflowX, overflowY, alignments, requestedConstraints, backgroundColor, backgroundImage, backgroundImageScale9Grid, backgroundImageEffectColorMul, backgroundImageEffectColorAdd, border, padding, showOn, hideOn, tooltip)
65 {
66 }
67 
69 {
70  return "table";
71 }
72 
74 {
75  return false;
76 }
77 
79 {
80  auto width = 0;
81  for (auto i = 0; i < subNodes.size(); i++) {
82  auto guiSubNode = subNodes[i];
83  if (guiSubNode->conditionsMet == false) continue;
84  if (guiSubNode->flow == GUINode_Flow::FLOATING) {
85  continue;
86  }
87  auto contentWidth = guiSubNode->getAutoWidth();
88  if (contentWidth > width) {
89  width = contentWidth;
90  }
91  }
92  width += border.left + border.right;
93  width += padding.left + padding.right;
94  return width;
95 }
96 
98 {
99  auto height = 0;
100  for (auto i = 0; i < subNodes.size(); i++) {
101  auto guiSubNode = subNodes[i];
102  if (guiSubNode->conditionsMet == false) continue;
103  if (guiSubNode->flow == GUINode_Flow::FLOATING) {
104  continue;
105  }
106  height += guiSubNode->getAutoHeight();
107  }
108  height += border.top + border.bottom;
109  height += padding.top + padding.bottom;
110  return height;
111 }
112 
114 {
116  if (conditionsMet == false) return;
117  {
118  auto starCount = 0;
120  auto nodesHeight = 0;
121  auto finalNodesHeight = 0;
122  for (auto i = 0; i < subNodes.size(); i++) {
123  auto guiSubNode = subNodes[i];
124  if (guiSubNode->conditionsMet == false) continue;
125  if (guiSubNode->flow == GUINode_Flow::FLOATING) {
126  continue;
127  }
128  if (guiSubNode->requestedConstraints.heightType == GUINode_RequestedConstraints_RequestedConstraintsType::STAR) {
129  starCount++;
130  } else {
131  nodesHeight += guiSubNode->computedConstraints.height;
132  finalNodesHeight += guiSubNode->computedConstraints.height;
133  }
134  }
135  auto verticalStarPixelRest = 0.0f;
136  for (auto i = 0; i < subNodes.size(); i++) {
137  auto guiSubNode = subNodes[i];
138  if (guiSubNode->conditionsMet == false) continue;
139  if (guiSubNode->requestedConstraints.heightType == GUINode_RequestedConstraints_RequestedConstraintsType::STAR) {
140  auto nodeStarHeight = (static_cast<float>(height) - static_cast<float>(nodesHeight)) / static_cast<float>(starCount);
141  auto nodeStarHeightInt = static_cast<int>(nodeStarHeight);
142  verticalStarPixelRest += nodeStarHeight - nodeStarHeightInt;
143  if (static_cast<int>(verticalStarPixelRest) > 0) {
144  nodeStarHeightInt += static_cast<int>(verticalStarPixelRest);
145  verticalStarPixelRest -= static_cast<int>(verticalStarPixelRest);
146  }
147  guiSubNode->requestedConstraints.height = nodeStarHeightInt;
148  guiSubNode->computedConstraints.height = nodeStarHeightInt;
149  if (guiSubNode->computedConstraints.height < 0) {
150  guiSubNode->computedConstraints.height = 0;
151  }
152  finalNodesHeight += guiSubNode->computedConstraints.height;
153  if (dynamic_cast<GUIParentNode*>(guiSubNode) != nullptr) {
154  required_dynamic_cast<GUIParentNode*>(guiSubNode)->layoutSubNodes();
155  }
156  }
157  }
159  for (auto i = 0; i < subNodes.size(); i++) {
160  auto guiSubNode = subNodes[i];
161  if (guiSubNode->conditionsMet == false) continue;
162  guiSubNode->computedConstraints.alignmentTop = border.top + padding.top;
163  }
164  } else
166  for (auto i = 0; i < subNodes.size(); i++) {
167  auto guiSubNode = subNodes[i];
168  if (guiSubNode->conditionsMet == false) continue;
169  guiSubNode->computedConstraints.alignmentTop = border.top + padding.top + ((height - finalNodesHeight) / 2);
170  }
171  } else
173  for (auto i = 0; i < subNodes.size(); i++) {
174  auto guiSubNode = subNodes[i];
175  if (guiSubNode->conditionsMet == false) continue;
176  guiSubNode->computedConstraints.alignmentTop = (height - finalNodesHeight); // TODO: take bottom padding into account
177  }
178  }
179 
181  }
182 
183  for (auto i = 0; i < subNodes.size(); i++) {
184  auto guiSubNode = subNodes[i];
185  guiSubNode->computeContentAlignment();
186  }
189 }
190 
191 void GUITableNode::setTop(int top)
192 {
196  for (auto i = 0; i < subNodes.size(); i++) {
197  auto guiSubNode = subNodes[i];
198  if (guiSubNode->conditionsMet == false) continue;
199  guiSubNode->setTop(top);
200  if (guiSubNode->flow == GUINode_Flow::FLOATING) {
201  continue;
202  }
203  top += guiSubNode->computedConstraints.height;
204  }
205 }
206 
207 void GUITableNode::setLeft(int left)
208 {
212  for (auto i = 0; i < subNodes.size(); i++) {
213  auto guiSubNode = subNodes[i];
214  if (guiSubNode->conditionsMet == false) continue;
215  guiSubNode->setLeft(left);
216  continue;
217  left += guiSubNode->computedConstraints.width;
218  }
219 }
220 
222  auto maxWidth = -1;
223  for (auto guiTableRowNode: subNodes) {
224  auto guiTableCellNode = required_dynamic_cast<GUITableCellNode*>((required_dynamic_cast<GUITableRowNode*>(guiTableRowNode))->subNodes.at(x));
225  if (guiTableCellNode->conditionsMet == false) continue;
226  const auto& requestedConstaints = guiTableCellNode->getRequestsConstraints();
227  if (requestedConstaints.widthType == GUINode_RequestedConstraints_RequestedConstraintsType::PIXEL) {
228  maxWidth = Math::max(maxWidth, computedConstraints.width);
229  } else
230  if (requestedConstaints.widthType == GUINode_RequestedConstraints_RequestedConstraintsType::AUTO) {
231  maxWidth = Math::max(maxWidth, guiTableCellNode->getAutoWidth());
232  } else {
233  // TODO: percent, star
234  maxWidth = Math::max(maxWidth, guiTableCellNode->getContentWidth());
235  }
236  }
237  return maxWidth;
238 }
239 
241  auto maxHeight = -1;
242  for (auto guiTableCellNode: required_dynamic_cast<GUITableRowNode*>(subNodes.at(y))->subNodes) {
243  if (guiTableCellNode->conditionsMet == false) continue;
244  const auto& requestedConstaints = guiTableCellNode->getRequestsConstraints();
245  if (requestedConstaints.heightType == GUINode_RequestedConstraints_RequestedConstraintsType::PIXEL) {
246  maxHeight = Math::max(maxHeight, computedConstraints.height);
247  } else
248  if (requestedConstaints.heightType == GUINode_RequestedConstraints_RequestedConstraintsType::AUTO) {
249  maxHeight = Math::max(maxHeight, guiTableCellNode->getAutoHeight());
250  } else {
251  // TODO: percent, star
252  maxHeight = Math::max(maxHeight, guiTableCellNode->getContentHeight());
253  }
254  }
255  return maxHeight;
256 }
GUI module class.
Definition: GUI.h:64
GUI element node conditions.
static STATIC_DLL_IMPEXT GUINode_AlignmentVertical * BOTTOM
static STATIC_DLL_IMPEXT GUINode_AlignmentVertical * CENTER
static STATIC_DLL_IMPEXT GUINode_AlignmentVertical * TOP
static STATIC_DLL_IMPEXT GUINode_Flow * FLOATING
Definition: GUINode_Flow.h:31
static STATIC_DLL_IMPEXT GUINode_RequestedConstraints_RequestedConstraintsType * STAR
static STATIC_DLL_IMPEXT GUINode_RequestedConstraints_RequestedConstraintsType * PIXEL
static STATIC_DLL_IMPEXT GUINode_RequestedConstraints_RequestedConstraintsType * AUTO
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
GUINode_Alignments alignments
Definition: GUINode.h:150
GUI parent node base class thats supporting child nodes.
Definition: GUIParentNode.h:42
virtual void computeHorizontalChildrenAlignment()
Compute horizontal children alignment.
virtual void layoutSubNodes()
Layout sub nodes.
vector< GUINode * > subNodes
Definition: GUIParentNode.h:62
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:72
const string getNodeType() override
void setTop(int top) override
Set computed top.
void setLeft(int left) override
Set computed left.
void layoutSubNodes() override
Layout sub nodes.
Standard math functions.
Definition: Math.h:19
String tools class.
Definition: StringTools.h:22
GUINode_AlignmentVertical * vertical
GUI node border entity.
GUI node padding entity.
GUINode_RequestedConstraints_RequestedConstraintsType * topType
GUINode_RequestedConstraints_RequestedConstraintsType * leftType
GUI node scale 9 grid entity.