TDME2 1.9.121
GUITableRowNode.cpp
Go to the documentation of this file.
2
3#include <tdme/tdme.h>
18#include <tdme/gui/GUI.h>
19#include <tdme/math/Math.h>
21
23
38using tdme::gui::GUI;
41
42GUITableRowNode::GUITableRowNode(
43 GUIScreenNode* screenNode,
44 GUIParentNode* parentNode,
45 const string& id,
46 GUINode_Flow* flow,
47 GUIParentNode_Overflow* overflowX,
48 GUIParentNode_Overflow* overflowY,
49 const GUINode_Alignments& alignments,
50 const GUINode_RequestedConstraints& requestedConstraints,
51 const GUIColor& backgroundColor,
52 const string& backgroundImage,
53 const GUINode_Scale9Grid& backgroundImageScale9Grid,
54 const GUIColor& backgroundImageEffectColorMul,
55 const GUIColor& backgroundImageEffectColorAdd,
56 const GUINode_Border& border,
57 const GUINode_Padding& padding,
58 const GUINodeConditions& showOn,
59 const GUINodeConditions& hideOn
60):
61 GUIParentNode(screenNode, parentNode, id, flow, overflowX, overflowY, alignments, requestedConstraints, backgroundColor, backgroundImage, backgroundImageScale9Grid, backgroundImageEffectColorMul, backgroundImageEffectColorAdd, border, padding, showOn, hideOn)
62{
63}
64
66{
67 return "table-row";
68}
69
71{
72 return false;
73}
74
76{
77 auto width = 0;
78 for (auto i = 0; i < subNodes.size(); i++) {
79 auto guiSubNode = subNodes[i];
80 if (guiSubNode->conditionsMet == false) continue;
81 if (guiSubNode->flow == GUINode_Flow::FLOATING) {
82 continue;
83 }
84 width += guiSubNode->getAutoWidth();
85 }
86 width += border.left + border.right;
87 width += padding.left + padding.right;
88 return width;
89}
90
92{
93 auto height = 0;
94 for (auto i = 0; i < subNodes.size(); i++) {
95 auto guiSubNode = subNodes[i];
96 if (guiSubNode->conditionsMet == false) continue;
97 if (guiSubNode->flow == GUINode_Flow::FLOATING) {
98 continue;
99 }
100 auto contentHeight = guiSubNode->getAutoHeight();
101 if (contentHeight > height) {
102 height = contentHeight;
103 }
104 }
105 height += border.top + border.bottom;
106 height += padding.top + padding.bottom;
107 return height;
108}
109
111{
113 if (conditionsMet == false) return;
114 GUITableNode* guiTableNode = required_dynamic_cast<GUITableNode*>(parentNode);
115 if (tableRowNodeIdx == -1) {
116 tableRowNodeIdx = 0;
117 for (auto guiTableNowChild: guiTableNode->subNodes) {
118 if (this == guiTableNowChild) break;
120 }
121 }
122 auto tableCellMaxHeight = guiTableNode->getTableCellMaxHeight(tableRowNodeIdx);
123 {
124 auto starCount = 0;
126 auto nodesWidth = 0;
127 auto finalNodesWidth = 0;
128 for (auto i = 0; i < subNodes.size(); i++) {
129 auto guiSubNode = subNodes[i];
130 if (guiSubNode->conditionsMet == false) continue;
131 if (guiSubNode->flow == GUINode_Flow::FLOATING) {
132 continue;
133 }
134 if (guiSubNode->requestedConstraints.widthType == GUINode_RequestedConstraints_RequestedConstraintsType::STAR) {
135 starCount++;
136 } else {
137 nodesWidth += guiSubNode->computedConstraints.width;
138 finalNodesWidth += guiSubNode->computedConstraints.width;
139 }
140 }
141
142 auto horizontalStarPixelRest = 0.0f;
143 for (auto i = 0; i < subNodes.size(); i++) {
144 auto guiSubNode = subNodes[i];
145 if (guiSubNode->conditionsMet == false) continue;
146
147 if (guiSubNode->requestedConstraints.widthType == GUINode_RequestedConstraints_RequestedConstraintsType::TABLECELL) {
148 auto tableCellMaxWidth = guiTableNode->getTableCellMaxWidth(i);
149 guiSubNode->requestedConstraints.widthType = GUINode_RequestedConstraints_RequestedConstraintsType::TABLECELL;
150 guiSubNode->requestedConstraints.width = tableCellMaxWidth;
151 guiSubNode->computedConstraints.width = tableCellMaxWidth;
152 finalNodesWidth += guiSubNode->computedConstraints.width;
153 }
154
155 if (guiSubNode->requestedConstraints.heightType == GUINode_RequestedConstraints_RequestedConstraintsType::TABLECELL) {
156 guiSubNode->requestedConstraints.height = tableCellMaxHeight;
157 guiSubNode->computedConstraints.height = tableCellMaxHeight;
158 }
159
160 if (dynamic_cast<GUIParentNode*>(guiSubNode) != nullptr) {
161 required_dynamic_cast<GUIParentNode*>(guiSubNode)->layoutSubNodes();
162 }
163 }
164
166 for (auto i = 0; i < subNodes.size(); i++) {
167 auto guiSubNode = subNodes[i];
168 if (guiSubNode->conditionsMet == false) continue;
169 guiSubNode->computedConstraints.alignmentLeft = Math::max(0, border.left + padding.left);
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.alignmentLeft = Math::max(0, border.left + padding.left + ((width - finalNodesWidth) / 2));
177 }
178 } else
180 for (auto i = 0; i < subNodes.size(); i++) {
181 auto guiSubNode = subNodes[i];
182 if (guiSubNode->conditionsMet == false) continue;
183 guiSubNode->computedConstraints.alignmentLeft = Math::max(0, (width - finalNodesWidth));
184 }
185 }
186
188 }
189
190 for (auto i = 0; i < subNodes.size(); i++) {
191 auto guiSubNode = subNodes[i];
192 guiSubNode->computeContentAlignment();
193 }
196}
197
199{
203 for (auto i = 0; i < subNodes.size(); i++) {
204 auto guiSubNode = subNodes[i];
205 if (guiSubNode->conditionsMet == false) continue;
206 guiSubNode->setTop(top);
207 continue;
208 top += guiSubNode->computedConstraints.height;
209 }
210}
211
213{
217 for (auto i = 0; i < subNodes.size(); i++) {
218 auto guiSubNode = subNodes[i];
219 if (guiSubNode->conditionsMet == false) continue;
220 guiSubNode->setLeft(left);
221 if (guiSubNode->flow == GUINode_Flow::FLOATING) {
222 continue;
223 }
224 left += guiSubNode->computedConstraints.width;
225 }
226}
227
228
229GUINode_RequestedConstraints GUITableRowNode::createRequestedConstraints(const string& left, const string& top, const string& width, const string& height, int factor)
230{
233 constraints.left = getRequestedConstraintsValue(StringTools::trim(left), 0);
235 constraints.top = getRequestedConstraintsValue(StringTools::trim(top), 0);
237 constraints.width = getRequestedConstraintsValue(StringTools::trim(width), -1);
239 constraints.height = getRequestedConstraintsValue(StringTools::trim(height), -1);
240 if (constraints.leftType == GUINode_RequestedConstraints_RequestedConstraintsType::PIXEL) constraints.left*= factor;
241 if (constraints.topType == GUINode_RequestedConstraints_RequestedConstraintsType::PIXEL) constraints.top*= factor;
244 return constraints;
245}
GUI module class.
Definition: GUI.h:66
GUI element node conditions.
static STATIC_DLL_IMPEXT GUINode_AlignmentHorizontal * RIGHT
static STATIC_DLL_IMPEXT GUINode_AlignmentHorizontal * CENTER
static STATIC_DLL_IMPEXT GUINode_AlignmentHorizontal * LEFT
static STATIC_DLL_IMPEXT GUINode_Flow * FLOATING
Definition: GUINode_Flow.h:31
static STATIC_DLL_IMPEXT GUINode_RequestedConstraints_RequestedConstraintsType * TABLECELL
static STATIC_DLL_IMPEXT GUINode_RequestedConstraints_RequestedConstraintsType * STAR
static STATIC_DLL_IMPEXT GUINode_RequestedConstraints_RequestedConstraintsType * NONE
static STATIC_DLL_IMPEXT GUINode_RequestedConstraints_RequestedConstraintsType * PIXEL
static STATIC_DLL_IMPEXT GUINode_RequestedConstraints_RequestedConstraintsType * AUTO
GUI node base class.
Definition: GUINode.h:63
static GUINode_RequestedConstraints_RequestedConstraintsType * getRequestedConstraintsType(const string &constraint, GUINode_RequestedConstraints_RequestedConstraintsType *defaultConstraintsType)
Get requested constraints type.
Definition: GUINode.cpp:286
GUINode_Border border
Definition: GUINode.h:159
virtual void setLeft(int left)
Set computed left.
Definition: GUINode.cpp:177
GUIParentNode * parentNode
Definition: GUINode.h:147
GUINode_ComputedConstraints computedConstraints
Definition: GUINode.h:151
GUINode_Padding padding
Definition: GUINode.h:158
virtual void setTop(int top)
Set computed top.
Definition: GUINode.cpp:183
GUINode_RequestedConstraints requestedConstraints
Definition: GUINode.h:150
GUINode_Alignments alignments
Definition: GUINode.h:149
static int getRequestedConstraintsValue(const string &constraint, int defaultConstraintsValue)
Get requested constraints value.
Definition: GUINode.cpp:304
GUI parent node base class thats supporting child nodes.
Definition: GUIParentNode.h:43
virtual void layoutSubNodes()
Layout sub nodes.
vector< GUINode * > subNodes
Definition: GUIParentNode.h:63
virtual void computeVerticalChildrenAlignment()
Compute vertical children alignment.
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:57
const string getNodeType() override
void setTop(int top) override
Set computed top.
void setLeft(int left) override
Set computed left.
static GUINode_RequestedConstraints createRequestedConstraints(const string &left, const string &top, const string &width, const string &height, int factor)
Create requested constraints.
void layoutSubNodes() override
Layout sub nodes.
Standard math functions.
Definition: Math.h:21
String tools class.
Definition: StringTools.h:20
GUINode_AlignmentHorizontal * horizontal
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.