68 lines
No EOL
2.5 KiB
C++
68 lines
No EOL
2.5 KiB
C++
/*
|
|
Crafter®.Graphics
|
|
Copyright (C) 2025 Catcrafts®
|
|
Catcrafts.net
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 3.0 of the License, or (at your option) any later version.
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with this library; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
module Crafter.Graphics:GridElement_impl;
|
|
import :GridElement;
|
|
import :Window;
|
|
import :Types;
|
|
import std;
|
|
|
|
using namespace Crafter;
|
|
|
|
GridElement::GridElement(std::uint32_t columns, std::uint32_t rows, std::int32_t spacingX, std::int32_t spacingY, std::int32_t paddingX, std::int32_t paddingY, Anchor anchor) : Transform(anchor), columns(columns), rows(rows), spacingX(spacingX), spacingY(spacingY), paddingX(paddingX), paddingY(paddingY) {
|
|
|
|
}
|
|
|
|
void GridElement::UpdatePositionScaled(Window& window) {
|
|
std::int32_t cellWidth = (SCALE32 - (paddingX * 2) - (spacingX * (columns - 1))) / columns;
|
|
std::int32_t cellHeight = (SCALE32 - (paddingY * 2) - (spacingY * (rows - 1))) / rows;
|
|
|
|
std::size_t childIndex = 0;
|
|
for (std::uint32_t row = 0; row < rows && childIndex < children.size(); ++row) {
|
|
for (std::uint32_t col = 0; col < columns && childIndex < children.size(); ++col) {
|
|
Transform* child = children[childIndex];
|
|
|
|
// Calculate position for this child
|
|
std::int32_t childX = (cellWidth * col) + (spacingX * col) + paddingX;
|
|
|
|
std::int32_t childY = (cellHeight * row) + (spacingY * row) + paddingY;
|
|
|
|
// Apply relative positioning
|
|
child->anchor.x = childX;
|
|
child->anchor.y = childY;
|
|
child->anchor.width = cellWidth;
|
|
child->anchor.height = cellHeight;
|
|
|
|
// Update child position
|
|
child->UpdatePosition(window, *this);
|
|
childIndex++;
|
|
}
|
|
}
|
|
}
|
|
|
|
void GridElement::UpdatePosition(Window& window) {
|
|
window.ScaleElement(*this);
|
|
UpdatePositionScaled(window);
|
|
}
|
|
|
|
void GridElement::UpdatePosition(Window& window, Transform& parent) {
|
|
window.ScaleElement(*this, parent);
|
|
UpdatePositionScaled(window);
|
|
} |