Dawn/archive/ui/container/UIRowContainer.cpp

51 lines
1.1 KiB
C++

// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "UIRowContainer.hpp"
using namespace Dawn;
float_t UIRowContainer::getContentWidth() {
float_t width = 0.0f;
for(auto &child : this->getChildren()) {
width = Math::max(width, child->getWidth());
}
return width;
}
float_t UIRowContainer::getContentHeight() {
float_t height = 0.0f;
for(auto &child : this->getChildren()) {
height += child->getHeight();
}
return height;
}
void UIRowContainer::updateAlignment(
const glm::vec2 parentPosition,
const glm::vec2 parentSize,
const float_t canvasScale
) {
this->updateSelfAlignment(parentPosition, parentSize, canvasScale);
// Now we have our dimensions, divide evenly
auto children = this->getChildren();
float_t y = 0.0f;
float_t yPiece = this->size.y / (float_t)children.size();
// Update all children
for(auto &child : children) {
child->updateAlignment(
this->position + glm::vec2(0, y),
glm::vec2(
this->size.x,
yPiece
),
canvasScale
);
y += yPiece;
}
}