LayoutSizeRange GUILayoutX::_calculateLayoutSizeRange() const { Vector2I optimalSize; Vector2I minSize; for (auto& child : mChildren) { if (!child->_isActive()) continue; LayoutSizeRange sizeRange = child->_calculateLayoutSizeRange(); if (child->_getType() == GUIElementBase::Type::FixedSpace) sizeRange.optimal.y = sizeRange.min.y = 0; UINT32 paddingX = child->_getPadding().left + child->_getPadding().right; UINT32 paddingY = child->_getPadding().top + child->_getPadding().bottom; optimalSize.x += sizeRange.optimal.x + paddingX; optimalSize.y = std::max((UINT32)optimalSize.y, sizeRange.optimal.y + paddingY); minSize.x += sizeRange.min.x + paddingX; minSize.y = std::max((UINT32)minSize.y, sizeRange.min.y + paddingY); } LayoutSizeRange sizeRange = _getDimensions().calculateSizeRange(optimalSize); sizeRange.min.x = std::max(sizeRange.min.x, minSize.x); sizeRange.min.y = std::max(sizeRange.min.y, minSize.y); return sizeRange; }
void GUIElementBase::setUpdateParent(GUIElementBase* updateParent) { mUpdateParent = updateParent; const GUIDimensions& dimensions = _getDimensions(); bool boundsDependOnChildren = !dimensions.fixedHeight() || !dimensions.fixedWidth(); if (!boundsDependOnChildren) return; for (auto& child : mChildren) child->setUpdateParent(updateParent); }
void GUIPanel::_updateOptimalLayoutSizes() { // Update all children first, otherwise we can't determine our own optimal size GUIElementBase::_updateOptimalLayoutSizes(); if (mChildren.size() != mChildSizeRanges.size()) mChildSizeRanges.resize(mChildren.size()); Vector2I optimalSize; Vector2I minSize; UINT32 childIdx = 0; for (auto& child : mChildren) { LayoutSizeRange& childSizeRange = mChildSizeRanges[childIdx]; if (child->_isActive()) { childSizeRange = _getElementSizeRange(child); UINT32 paddingX = child->_getPadding().left + child->_getPadding().right; UINT32 paddingY = child->_getPadding().top + child->_getPadding().bottom; Vector2I childMax; childMax.x = child->_getDimensions().x + childSizeRange.optimal.x + paddingX; childMax.y = child->_getDimensions().y + childSizeRange.optimal.y + paddingY; optimalSize.x = std::max(optimalSize.x, childMax.x); optimalSize.y = std::max(optimalSize.y, childMax.y); childMax.x = child->_getDimensions().x + childSizeRange.min.x + paddingX; childMax.y = child->_getDimensions().y + childSizeRange.min.y + paddingY; minSize.x = std::max(minSize.x, childMax.x); minSize.y = std::max(minSize.y, childMax.y); } else childSizeRange = LayoutSizeRange(); childIdx++; } mSizeRange = _getDimensions().calculateSizeRange(optimalSize); mSizeRange.min.x = std::max(mSizeRange.min.x, minSize.x); mSizeRange.min.y = std::max(mSizeRange.min.y, minSize.y); }
Vector2I GUIButtonBase::_getOptimalSize() const { UINT32 imageWidth = 0; UINT32 imageHeight = 0; const HSpriteTexture& activeTex = getActiveTexture(); if(SpriteTexture::checkIsLoaded(activeTex)) { imageWidth = activeTex->getWidth(); imageHeight = activeTex->getHeight(); } Vector2I contentSize = GUIHelper::calcOptimalContentsSize(mContent, *_getStyle(), _getDimensions(), mActiveState); UINT32 contentWidth = std::max(imageWidth, (UINT32)contentSize.x); UINT32 contentHeight = std::max(imageHeight, (UINT32)contentSize.y); return Vector2I(contentWidth, contentHeight); }
void GUILayoutX::_updateOptimalLayoutSizes() { // Update all children first, otherwise we can't determine our own optimal size GUIElementBase::_updateOptimalLayoutSizes(); if(mChildren.size() != mChildSizeRanges.size()) mChildSizeRanges.resize(mChildren.size()); Vector2I optimalSize; Vector2I minSize; UINT32 childIdx = 0; for(auto& child : mChildren) { LayoutSizeRange& childSizeRange = mChildSizeRanges[childIdx]; if (child->_isActive()) { childSizeRange = child->_getLayoutSizeRange(); if (child->_getType() == GUIElementBase::Type::FixedSpace) { childSizeRange.optimal.y = 0; childSizeRange.min.y = 0; } UINT32 paddingX = child->_getPadding().left + child->_getPadding().right; UINT32 paddingY = child->_getPadding().top + child->_getPadding().bottom; optimalSize.x += childSizeRange.optimal.x + paddingX; optimalSize.y = std::max((UINT32)optimalSize.y, childSizeRange.optimal.y + paddingY); minSize.x += childSizeRange.min.x + paddingX; minSize.y = std::max((UINT32)minSize.y, childSizeRange.min.y + paddingY); } else childSizeRange = LayoutSizeRange(); childIdx++; } mSizeRange = _getDimensions().calculateSizeRange(optimalSize); mSizeRange.min.x = std::max(mSizeRange.min.x, minSize.x); mSizeRange.min.y = std::max(mSizeRange.min.y, minSize.y); }
LayoutSizeRange GUIPanel::_calculateLayoutSizeRange() const { Vector2I optimalSize; Vector2I minSize; for (auto& child : mChildren) { if (!child->_isActive()) continue; LayoutSizeRange sizeRange = child->_calculateLayoutSizeRange(); if (child->_getType() == GUIElementBase::Type::FixedSpace || child->_getType() == GUIElementBase::Type::FlexibleSpace) { sizeRange.optimal.x = sizeRange.optimal.y = 0; sizeRange.min.x = sizeRange.min.y = 0; } UINT32 paddingX = child->_getPadding().left + child->_getPadding().right; UINT32 paddingY = child->_getPadding().top + child->_getPadding().bottom; Vector2I childMax; childMax.x = child->_getDimensions().x + sizeRange.optimal.x + paddingX; childMax.y = child->_getDimensions().y + sizeRange.optimal.y + paddingY; optimalSize.x = std::max(optimalSize.x, childMax.x); optimalSize.y = std::max(optimalSize.y, childMax.y); childMax.x = child->_getDimensions().x + sizeRange.min.x + paddingX; childMax.y = child->_getDimensions().y + sizeRange.min.y + paddingY; minSize.x = std::max(minSize.x, childMax.x); minSize.y = std::max(minSize.y, childMax.y); } LayoutSizeRange sizeRange = _getDimensions().calculateSizeRange(optimalSize); sizeRange.min.x = std::max(sizeRange.min.x, minSize.x); sizeRange.min.y = std::max(sizeRange.min.y, minSize.y); return sizeRange; }
Vector2I GUIColor::_getOptimalSize() const { return GUIHelper::calcOptimalContentsSize(Vector2I(80, 10), *_getStyle(), _getDimensions()); // Arbitrary size }
LayoutSizeRange GUIElementBase::_calculateLayoutSizeRange() const { const GUIDimensions& dimensions = _getDimensions(); return dimensions.calculateSizeRange(_getOptimalSize()); }