rendering element rewrite
This commit is contained in:
parent
4c286e1fd8
commit
3d40256bde
22 changed files with 799 additions and 795 deletions
|
|
@ -26,94 +26,42 @@ 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,
|
||||
std::int_fast32_t anchorX, std::int_fast32_t anchorY,
|
||||
std::uint_fast32_t relativeWidth, std::uint_fast32_t relativeHeight,
|
||||
std::int_fast32_t anchorOffsetX, std::int_fast32_t anchorOffsetY,
|
||||
std::int_fast32_t z)
|
||||
: Transform(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z),
|
||||
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, Anchor anchor) : Transform(anchor), columns(columns), rows(rows), spacingX(spacingX), spacingY(spacingY) {
|
||||
|
||||
}
|
||||
|
||||
void GridElement::SetGridSize(std::uint_fast32_t columns, std::uint_fast32_t rows) {
|
||||
this->columns = columns;
|
||||
this->rows = rows;
|
||||
}
|
||||
|
||||
void GridElement::SetSpacing(std::int_fast32_t spacingX, std::int_fast32_t spacingY) {
|
||||
this->spacingX = spacingX;
|
||||
this->spacingY = spacingY;
|
||||
void GridElement::UpdatePositionScaled(Window& window) {
|
||||
std::int_fast32_t cellWidth = SCALE / columns;
|
||||
std::int_fast32_t cellHeight = SCALE / rows;
|
||||
|
||||
std::size_t childIndex = 0;
|
||||
for (std::uint_fast32_t row = 0; row < rows && childIndex < children.size(); ++row) {
|
||||
for (std::uint_fast32_t col = 0; col < columns && childIndex < children.size(); ++col) {
|
||||
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);
|
||||
|
||||
// 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);
|
||||
|
||||
// Calculate grid dimensions
|
||||
std::int_fast32_t totalWidth = 0;
|
||||
std::int_fast32_t totalHeight = 0;
|
||||
|
||||
if (columns > 0 && rows > 0) {
|
||||
// Calculate the space available for children based on grid size
|
||||
std::int_fast32_t cellWidth = (relativeWidth - (columns - 1) * spacingX) / columns;
|
||||
std::int_fast32_t cellHeight = (relativeHeight - (rows - 1) * spacingY) / rows;
|
||||
|
||||
// Position each child in the grid
|
||||
std::size_t childIndex = 0;
|
||||
for (std::uint_fast32_t row = 0; row < rows && childIndex < children.size(); ++row) {
|
||||
for (std::uint_fast32_t col = 0; col < columns && childIndex < children.size(); ++col) {
|
||||
Transform* child = children[childIndex];
|
||||
|
||||
// Calculate position for this child
|
||||
std::int_fast32_t childX = anchorOffsetX + (cellWidth * col) + (spacingX * col);
|
||||
std::int_fast32_t childY = anchorOffsetY + (cellHeight * row) + (spacingY * row);
|
||||
|
||||
// Apply relative positioning
|
||||
child->anchorX = childX;
|
||||
child->anchorY = childY;
|
||||
child->relativeWidth = cellWidth;
|
||||
child->relativeHeight = cellHeight;
|
||||
|
||||
// Update child position
|
||||
child->UpdatePosition(window, *this);
|
||||
childIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
UpdatePositionScaled(window);
|
||||
}
|
||||
|
||||
void GridElement::UpdatePosition(Window& window, Transform& parent) {
|
||||
window.ScaleElement(*this, parent);
|
||||
// Calculate grid dimensions
|
||||
std::int_fast32_t totalWidth = 0;
|
||||
std::int_fast32_t totalHeight = 0;
|
||||
|
||||
if (columns > 0 && rows > 0) {
|
||||
// Calculate the space available for children based on grid size
|
||||
std::int_fast32_t cellWidth = (relativeWidth - (columns - 1) * spacingX) / columns;
|
||||
std::int_fast32_t cellHeight = (relativeHeight - (rows - 1) * spacingY) / rows;
|
||||
|
||||
// Position each child in the grid
|
||||
std::size_t childIndex = 0;
|
||||
for (std::uint_fast32_t row = 0; row < rows && childIndex < children.size(); ++row) {
|
||||
for (std::uint_fast32_t col = 0; col < columns && childIndex < children.size(); ++col) {
|
||||
Transform* child = children[childIndex];
|
||||
|
||||
// Calculate position for this child
|
||||
std::int_fast32_t childX = anchorOffsetX + (cellWidth * col) + (spacingX * col);
|
||||
std::int_fast32_t childY = anchorOffsetY + (cellHeight * row) + (spacingY * row);
|
||||
|
||||
// Apply relative positioning
|
||||
child->anchorX = childX;
|
||||
child->anchorY = childY;
|
||||
child->relativeWidth = cellWidth;
|
||||
child->relativeHeight = cellHeight;
|
||||
|
||||
// Update child position
|
||||
child->UpdatePosition(window, *this);
|
||||
childIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
UpdatePositionScaled(window);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue