| 118 | bool Element::_allClickableFalse = false; |
| 119 | |
| 120 | ElementPtr Element::createFromXml(const std::string &xmlContent) { |
| 121 | tinyxml2::XMLDocument doc; |
| 122 | std::vector<std::string> strings; |
| 123 | int startIndex = 0, endIndex = 0; |
| 124 | for (int i = 0; i <= xmlContent.size(); i++) { |
| 125 | // If we reached the end of the word or the end of the input. |
| 126 | if (xmlContent[i] == '\n' || i == xmlContent.size()) { |
| 127 | endIndex = i; |
| 128 | std::string temp; |
| 129 | temp.append(xmlContent, startIndex, endIndex - startIndex); |
| 130 | strings.push_back(temp); |
| 131 | startIndex = endIndex + 1; |
| 132 | } |
| 133 | } |
| 134 | for (auto it: strings) { |
| 135 | BLOG("The content of XML is: %s", it.c_str()); |
| 136 | } |
| 137 | tinyxml2::XMLError errXml = doc.Parse(xmlContent.c_str()); |
| 138 | |
| 139 | if (errXml != tinyxml2::XML_SUCCESS) { |
| 140 | BLOGE("parse xml error %d", (int) errXml); |
| 141 | return nullptr; |
| 142 | } |
| 143 | |
| 144 | ElementPtr elementPtr = std::make_shared<Element>(); |
| 145 | |
| 146 | _allClickableFalse = true; |
| 147 | elementPtr->fromXml(doc, elementPtr); |
| 148 | if (_allClickableFalse) { |
| 149 | elementPtr->recursiveDoElements([](const ElementPtr &elm) { |
| 150 | elm->_clickable = true; |
| 151 | }); |
| 152 | } |
| 153 | // force set root element scrollable = true |
| 154 | elementPtr->_scrollable = true; |
| 155 | doc.Clear(); |
| 156 | return elementPtr; |
| 157 | } |
| 158 | |
| 159 | ElementPtr Element::createFromXml(const tinyxml2::XMLDocument &doc) { |
| 160 | ElementPtr elementPtr = std::make_shared<Element>(); // Use the empty element as the FAKE root element |