TDME2  1.9.200
GUINodeConditions.cpp
Go to the documentation of this file.
2 
3 #include <vector>
4 
5 #include <tdme/tdme.h>
9 
10 using std::vector;
11 
16 
17 GUINodeConditions::GUINodeConditions(GUIElementNode* elementNode): elementNode(elementNode)
18 {
19 }
20 
21 void GUINodeConditions::updateNode(GUINode* node, const vector<string>& conditions) const {
22  node->conditionsMet = node->checkConditions();
24  auto parentNode = dynamic_cast<GUIParentNode*>(node);
25  if (parentNode != nullptr) {
26  for (auto i = 0; i < parentNode->subNodes.size(); i++) {
27  auto guiSubNode = parentNode->subNodes[i];
28  updateNode(guiSubNode, conditions);
29  }
30  }
31 }
32 
33 void GUINodeConditions::updateElementNode(const vector<string>& conditions) const {
34  if (elementNode == nullptr) return;
35 
36  // update related element node
38  for (auto i = 0; i < elementNode->subNodes.size(); i++) {
39  auto guiSubNode = elementNode->subNodes[i];
40  updateNode(guiSubNode, conditions);
41  }
42  auto screenNode = elementNode->getScreenNode();
43  screenNode->invalidateLayout(elementNode);
44 
45  // also update nodes that belong to this conditions but are not with in sub tree of related element node
46  auto elementNodeToNodeMappingIt = screenNode->elementNodeToNodeMapping.find(elementNode->getId());
47  if (elementNodeToNodeMappingIt != screenNode->elementNodeToNodeMapping.end()) {
48  for (const auto& nodeId: elementNodeToNodeMappingIt->second) {
49  auto node = screenNode->getNodeById(nodeId);
50  if (node == nullptr) continue;
51  updateNode(node, conditions);
52  screenNode->invalidateLayout(node);
53  }
54  }
55 }
GUI element node conditions.
void updateNode(GUINode *node, const vector< string > &conditions) const
Update node.
void updateElementNode(const vector< string > &conditions) const
Update element node.
GUI node base class.
Definition: GUINode.h:64
void onSetConditions(const vector< string > &conditions)
On set condition.
Definition: GUINode.cpp:1341
GUIScreenNode * getScreenNode()
Definition: GUINode.h:325
const string & getId()
Definition: GUINode.h:339
bool checkConditions()
Check if conditions are met.
Definition: GUINode.cpp:426
GUI parent node base class thats supporting child nodes.
Definition: GUIParentNode.h:42
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
void invalidateLayout(GUINode *node)
Mark a node to be invalidated regarding layout.