13 using std::make_unique;
14 using std::unique_ptr;
25 GUIScrollAreaController::GUIScrollAreaController(
GUINode* node)
32 float elementHeight = contentNode->getComputedConstraints().height;
33 float contentHeight = contentNode->getContentHeight();
34 auto scrollableHeight = contentHeight - elementHeight;
35 if (scrollableHeight <= 0.0f)
return true;
36 auto childrenRenderOffsetY = contentHeight - contentNode->getComputedConstraints().height;
37 return contentNode->getChildrenRenderOffsetY() == childrenRenderOffsetY;
43 float elementHeight = contentNode->getComputedConstraints().height;
44 float contentHeight = contentNode->getContentHeight();
45 auto scrollableHeight = contentHeight - elementHeight;
46 if (scrollableHeight <= 0.0f)
return;
47 auto childrenRenderOffsetY = contentHeight - contentNode->getComputedConstraints().height;
48 contentNode->setChildrenRenderOffsetY(childrenRenderOffsetY);
74 if (
node == upArrowNode) {
75 float elementHeight = contentNode->getComputedConstraints().height;
76 float contentHeight = contentNode->getContentHeight();
77 auto scrollableHeight = contentHeight - elementHeight;
78 if (scrollableHeight <= 0.0f)
81 auto childrenRenderOffsetY = contentNode->getChildrenRenderOffsetY() - 1.0f;
82 if (childrenRenderOffsetY < 0.0f)
83 childrenRenderOffsetY = 0.0f;
85 contentNode->setChildrenRenderOffsetY(childrenRenderOffsetY);
87 if (
node == downArrowNode) {
88 float elementHeight = contentNode->getComputedConstraints().height;
89 float contentHeight = contentNode->getContentHeight();
90 auto scrollableHeight = contentHeight - elementHeight;
91 if (scrollableHeight <= 0.0f)
94 auto childrenRenderOffsetY = contentNode->getChildrenRenderOffsetY() + 1.0f;
95 if (childrenRenderOffsetY > contentHeight - contentNode->getComputedConstraints().height) {
96 childrenRenderOffsetY = contentHeight - contentNode->getComputedConstraints().height;
98 contentNode->setChildrenRenderOffsetY(childrenRenderOffsetY);
100 if (
node == leftArrowNode) {
101 float elementWidth = contentNode->getComputedConstraints().width;
102 float contentWidth = contentNode->getContentWidth();
103 auto scrollableWidth = contentWidth - elementWidth;
104 if (scrollableWidth <= 0.0f)
107 auto childrenRenderOffsetX = contentNode->getChildrenRenderOffsetX() - 1.0f;
108 if (childrenRenderOffsetX < 0.0f)
109 childrenRenderOffsetX = 0.0f;
111 contentNode->setChildrenRenderOffsetX(childrenRenderOffsetX);
113 if (
node == rightArrowNode) {
114 float elementWidth = contentNode->getComputedConstraints().width;
115 float contentWidth = contentNode->getContentWidth();
116 auto scrollableWidth = contentWidth - elementWidth;
117 if (scrollableWidth <= 0.0f)
120 auto childrenRenderOffsetX = contentNode->getChildrenRenderOffsetX() + 1.0f;
121 if (childrenRenderOffsetX > contentWidth - contentNode->getComputedConstraints().width) {
122 childrenRenderOffsetX = contentWidth - contentNode->getComputedConstraints().width;
124 contentNode->setChildrenRenderOffsetX(childrenRenderOffsetX);
138 : guiScrollAreaController(guiScrollAreaController)
139 , contentNode(contentNode)
140 , upArrowNode(upArrowNode)
141 , downArrowNode(downArrowNode)
142 , leftArrowNode(leftArrowNode)
143 , rightArrowNode(rightArrowNode) {
182 float elementHeight = contentNode->getComputedConstraints().height;
183 float contentHeight = contentNode->getContentHeight();
184 auto scrollableHeight = contentHeight - elementHeight;
186 if (contentHeight > elementHeight + horizontalScrollBarNode->getComputedConstraints().height) {
187 required_dynamic_cast<GUIElementNode*>(
node)->getActiveConditions().add(
"vertical-scrollbar");
188 if (contentNode->getChildrenRenderOffsetY() + elementHeight > contentHeight) {
189 contentNode->setChildrenRenderOffsetY(contentHeight - elementHeight);
192 required_dynamic_cast<GUIElementNode*>(
node)->getActiveConditions().remove(
"vertical-scrollbar");
193 contentNode->setChildrenRenderOffsetY(0.0f);
198 float elementWidth = contentNode->getComputedConstraints().width;
199 float contentWidth = contentNode->getContentWidth();
200 auto scrollableWidth = contentWidth - elementWidth;
202 if (contentWidth > elementWidth + verticalScrollBarNode->getComputedConstraints().width) {
203 required_dynamic_cast<GUIElementNode*>(
node)->getActiveConditions().add(
"horizontal-scrollbar");
204 if (contentNode->getChildrenRenderOffsetX() + elementWidth > contentWidth) {
205 contentNode->setChildrenRenderOffsetX(contentWidth - elementWidth);
208 contentNode->setChildrenRenderOffsetX(0.0f);
209 required_dynamic_cast<GUIElementNode*>(
node)->getActiveConditions().remove(
"horizontal-scrollbar");
GUI node controller base class.
GUIScreenNode * getScreenNode()
GUI parent node base class thats supporting child nodes.
GUI screen node that represents a screen that can be rendered via GUI system.
void removeActionListener(GUIActionListener *listener)
Remove action listener.
void addActionListener(GUIActionListener *listener)
Add action listener.
GUINode * getNodeById(const string &nodeId)
Get GUI node by id.
Mutable utf8 aware string class.
GUI action listener interface.