TDME2 1.9.121
GUITabsController.cpp
Go to the documentation of this file.
2
3#include <tdme/tdme.h>
12#include <tdme/gui/GUI.h>
15
17
26using tdme::gui::GUI;
29
30GUITabsController::GUITabsController(GUINode* node)
31 : GUINodeController(node)
32{
33}
34
37 vector<GUINode*> childControllerNodes;
38 required_dynamic_cast<GUIParentNode*>(node)->getChildControllerNodes(childControllerNodes);
39 for (auto i = 0; i < childControllerNodes.size(); i++) {
40 auto childControllerNode = childControllerNodes[i];
41 auto childController = childControllerNode->getController();
42 if (dynamic_cast<GUITabContentController*>(childController) != nullptr) {
43 auto tabContentController = required_dynamic_cast<GUITabContentController*>(childController);
44 if (static_cast<GUINode*>(tabContentController->getNode()->getParentControllerNode()->getParentControllerNode()) != node)
45 continue;
46 tabContentControllers.push_back(tabContentController);
47 }
48 }
49}
50
52{
53 return false;
54}
55
57{
58}
59
61{
63 vector<GUINode*> childControllerNodes;
64 required_dynamic_cast<GUIParentNode*>(node)->getChildControllerNodes(childControllerNodes);
65 for (auto i = 0; i < childControllerNodes.size(); i++) {
66 auto childControllerNode = childControllerNodes[i];
67 auto childController = childControllerNode->getController();
68 if (dynamic_cast<GUITabsHeaderController*>(childController) != nullptr) {
69 auto _tabsHeaderController = required_dynamic_cast<GUITabsHeaderController*>(childController);
70 if (static_cast<GUINode*>(_tabsHeaderController->getNode()->getParentControllerNode()) != node)
71 continue;
72 tabsHeaderController = _tabsHeaderController;
73 }
74 }
75 auto preselectedTabIdx = 0;
76 auto i = 0;
77 for (auto tabContentController: tabContentControllers) {
78 if (tabContentController->isSelected() == true) preselectedTabIdx = i;
79 i++;
80 }
81 tabsHeaderController->select(preselectedTabIdx);
82}
83
85{
86}
87
89{
90}
91
93{
95}
96
98 tabsHeaderController->select(tabElementNode);
99}
100
102 // TODO: a.drewke: improve me!
103 if (value.equals(id) == true && tabSelected == true) return;
104 tabSelected = false;
105 auto tabContentNodeId = id + "-content";
106 for (auto tabContentController: tabContentControllers) {
107 auto select = tabContentNodeId == tabContentController->getNode()->getId();
108 tabContentController->setSelected(select);
109 if (select == true) tabSelected = true;
110 }
111 value.set(tabSelected == true?id:string());
112}
113
115{
117 // TODO: a.drewke, no element node, so it cant delegate value changes
118 // node->getScreenNode()->delegateValueChanged(required_dynamic_cast<GUIElementNode*>(node));
119}
120
122{
123}
124
126{
127}
128
130{
131}
132
134{
135}
136
138{
139}
140
142{
143 return true;
144}
145
147{
148 return value;
149}
150
152{
153 auto tabElementNode = dynamic_cast<GUIElementNode*>(node->getScreenNode()->getNodeById(value.getString()));
154 if (tabElementNode != nullptr) {
155 tabsHeaderController->select(tabElementNode);
156 setTabContentSelected(tabElementNode->getId());
157 } else {
158 Console::println("GUITabsController::setValue(): tab with id '" + value.getString() + "' not found");
159 }
160}
161
163{
164 tabSelected = false;
167}
GUI module class.
Definition: GUI.h:66
void setTabContentSelected(const string &id)
Set tab content selected.
void determineTabContentControllers()
Determine tab controllers.
void onFocusGained() override
On focus gained.
void dispose() override
Dispose controller.
void postLayout() override
Post layout event.
void initialize() override
Initialize controller after element has been created.
void handleKeyboardEvent(GUIKeyboardEvent *event) override
Handle keyboard event.
void setTabContentSelectedInternal(const string &id)
Set tab content selected internal.
void onFocusLost() override
On focus lost.
void setValue(const MutableString &value) override
Set value.
void handleMouseEvent(GUINode *node, GUIMouseEvent *event) override
Handle mouse event.
void tick() override
Tick method will be executed once per frame.
GUITabsHeaderController * tabsHeaderController
vector< GUITabContentController * > tabContentControllers
void setDisabled(bool disabled) override
Set disabled.
const MutableString & getValue() override
void onSubTreeChange() override
On sub tree change.
void select(GUIElementNode *tabElementNode)
Select.
GUI node controller base class.
GUI node base class.
Definition: GUINode.h:63
GUIScreenNode * getScreenNode()
Definition: GUINode.h:315
GUI parent node base class thats supporting child nodes.
Definition: GUIParentNode.h:43
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:57
GUINode * getNodeById(const string &nodeId)
Get GUI node by id.
Console class.
Definition: Console.h:26
Mutable string class.
Definition: MutableString.h:16
bool equals(const string &s2) const
Equals.
MutableString & set(char c)
Set character.
const string & getString() const