| 131 | |
| 132 | |
| 133 | void GameToolbox::alignItemsInColumnsWithPadding(ax::Menu* menu, |
| 134 | const int rows, |
| 135 | const int x_padding, |
| 136 | const int y_padding) { |
| 137 | // Get the menu items and calculate the total number of items |
| 138 | const auto items = menu->getChildren(); |
| 139 | const int totalItems = static_cast<int>(items.size()); |
| 140 | |
| 141 | // Calculate the number of rows and the maximum number of items per row |
| 142 | const int columns = (totalItems + rows - 1) / rows; |
| 143 | const int itemsPerRow = (totalItems + rows - 1) / rows; |
| 144 | |
| 145 | // Calculate the starting position for the menu items |
| 146 | const float startX = -(columns - 1) * (x_padding / 2.0f); |
| 147 | const float startY = (rows - 1) * (y_padding / 2.0f); |
| 148 | |
| 149 | // Loop through each row and position the items in it |
| 150 | for (int row = 0; row < rows; row++) { |
| 151 | // Calculate the y position for the items in this row |
| 152 | const float yPos = startY - (row * y_padding); |
| 153 | |
| 154 | // Loop through each item in this row and position it |
| 155 | for (int column = 0; column < columns; column++) { |
| 156 | // Calculate the index of the item in the menu items array |
| 157 | const int index = (row * columns) + column; |
| 158 | GameToolbox::log("index: {}", index); |
| 159 | |
| 160 | // Check if this index is valid for the menu items array |
| 161 | if (index < totalItems) { |
| 162 | // Get the item and set its position |
| 163 | auto item = dynamic_cast<ax::MenuItem*>(items.at(index)); |
| 164 | const float xPos = startX + (column * x_padding); |
| 165 | item->setPosition(ax::Vec2(xPos, yPos)); |
| 166 | } else { |
| 167 | // We've reached the end of the items, so we break out of the loop |
| 168 | break; |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | void GameToolbox::alignItemsHorizontally(ax::Vector<Node*> children, float padding, Point location) |
| 175 | { |
nothing calls this directly
no test coverage detected