38 lines
1.0 KiB
C++
38 lines
1.0 KiB
C++
// Copyright (c) 2023 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#include "UIPaddingContainer.hpp"
|
|
|
|
using namespace Dawn;
|
|
|
|
float_t UIPaddingContainer::getContentWidth() {
|
|
float_t width = 0.0f;
|
|
for(auto &child : getChildren()) {
|
|
width = Math::max(width, child->getWidth());
|
|
}
|
|
return width + padding.x + padding.z;
|
|
}
|
|
|
|
float_t UIPaddingContainer::getContentHeight() {
|
|
float_t height = 0.0f;
|
|
for(auto &child : getChildren()) {
|
|
height = Math::max(height, child->getHeight());
|
|
}
|
|
return height + padding.y + padding.w;
|
|
}
|
|
|
|
void UIPaddingContainer::updateAlignment(
|
|
const glm::vec2 parentPosition,
|
|
const glm::vec2 parentSize,
|
|
const float_t canvasScale
|
|
) {
|
|
glm::vec2 childPosition = parentPosition + glm::vec2(padding.x, padding.y);
|
|
glm::vec2 childSize = parentSize - glm::vec2(padding.x + padding.z, padding.y + padding.w);
|
|
|
|
auto children = getChildren();
|
|
for(auto &child : children) {
|
|
child->updateAlignment(childPosition, childSize, canvasScale);
|
|
}
|
|
} |