This commit is contained in:
Jorijn van der Graaf 2025-12-29 18:56:06 +01:00
commit c84504331b
12 changed files with 867 additions and 17 deletions

View file

@ -26,13 +26,13 @@ import std;
using namespace Crafter;
GridElement::GridElement(std::uint_fast32_t columns, std::uint_fast32_t rows, std::int_fast32_t spacingX, std::int_fast32_t spacingY, Anchor anchor) : Transform(anchor), columns(columns), rows(rows), spacingX(spacingX), spacingY(spacingY) {
GridElement::GridElement(std::uint_fast32_t columns, std::uint_fast32_t rows, std::int_fast32_t spacingX, std::int_fast32_t spacingY, std::int_fast32_t paddingX, std::int_fast32_t paddingY, Anchor anchor) : Transform(anchor), columns(columns), rows(rows), spacingX(spacingX), spacingY(spacingY), paddingX(paddingX), paddingY(paddingY) {
}
void GridElement::UpdatePositionScaled(Window& window) {
std::int_fast32_t cellWidth = SCALE / columns;
std::int_fast32_t cellHeight = SCALE / rows;
std::int_fast32_t cellWidth = (SCALE - (paddingX * 2) - (spacingX * (columns - 1))) / columns;
std::int_fast32_t cellHeight = (SCALE - (paddingY * 2) - (spacingY * (rows - 1))) / rows;
std::size_t childIndex = 0;
for (std::uint_fast32_t row = 0; row < rows && childIndex < children.size(); ++row) {
@ -40,8 +40,8 @@ void GridElement::UpdatePositionScaled(Window& window) {
Transform* child = children[childIndex];
// Calculate position for this child
std::int_fast32_t childX = (cellWidth * col) + (spacingX * col);
std::int_fast32_t childY = (cellHeight * row) + (spacingY * row);
std::int_fast32_t childX = (cellWidth * col) + (spacingX * col) + paddingX;
std::int_fast32_t childY = (cellHeight * row) + (spacingY * row) + paddingY;
// Apply relative positioning
child->anchor.x = childX;