| 2261 | } |
| 2262 | |
| 2263 | void RichText::formatRenderers() |
| 2264 | { |
| 2265 | float verticalSpace = _defaults[KEY_VERTICAL_SPACE].asFloat(); |
| 2266 | float fontSize = _defaults[KEY_FONT_SIZE].asFloat(); |
| 2267 | |
| 2268 | if (_ignoreSize) |
| 2269 | { |
| 2270 | const auto verticalAlignment = static_cast<VerticalAlignment>(_defaults.at(KEY_VERTICAL_ALIGNMENT).asInt()); |
| 2271 | |
| 2272 | float newContentSizeWidth = 0.0f; |
| 2273 | float nextPosY = 0.0f; |
| 2274 | std::vector<std::pair<Vector<Node*>*, float>> rowWidthPairs; |
| 2275 | rowWidthPairs.reserve(_elementRenders.size()); |
| 2276 | for (auto&& element : _elementRenders) |
| 2277 | { |
| 2278 | float nextPosX = 0.0f; |
| 2279 | float maxY = 0.0f; |
| 2280 | for (auto&& iter : element) |
| 2281 | { |
| 2282 | auto& iSize = iter->getContentSize(); |
| 2283 | |
| 2284 | if (verticalAlignment == VerticalAlignment::CENTER) |
| 2285 | { |
| 2286 | iter->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT); |
| 2287 | iter->setPosition(nextPosX, nextPosY + iSize.height / 2); |
| 2288 | } |
| 2289 | else if (verticalAlignment == VerticalAlignment::TOP) |
| 2290 | { |
| 2291 | iter->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT); |
| 2292 | iter->setPosition(nextPosX, nextPosY + iSize.height); |
| 2293 | } |
| 2294 | else // if (verticalAlignment == VerticalAlignment::BOTTOM) |
| 2295 | { |
| 2296 | iter->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); |
| 2297 | iter->setPosition(nextPosX, nextPosY); |
| 2298 | } |
| 2299 | |
| 2300 | this->addProtectedChild(iter, 1); |
| 2301 | newContentSizeWidth += iSize.width; |
| 2302 | nextPosX += iSize.width; |
| 2303 | maxY = std::max(maxY, iSize.height); |
| 2304 | } |
| 2305 | nextPosY -= maxY; |
| 2306 | rowWidthPairs.emplace_back(&element, nextPosX); |
| 2307 | } |
| 2308 | this->setContentSize(Vec2(newContentSizeWidth, -nextPosY)); |
| 2309 | for (auto&& row : rowWidthPairs) |
| 2310 | doHorizontalAlignment(*row.first, row.second); |
| 2311 | } |
| 2312 | else |
| 2313 | { |
| 2314 | // calculate real height |
| 2315 | float newContentSizeHeight = 0.0f; |
| 2316 | std::vector<float> maxHeights(_elementRenders.size()); |
| 2317 | |
| 2318 | for (size_t i = 0, size = _elementRenders.size(); i < size; i++) |
| 2319 | { |
| 2320 | Vector<Node*>& row = _elementRenders[i]; |
nothing calls this directly
no test coverage detected