Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Runtime/GridLayoutGroup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using UnityEngine;
using UnityEngine.UI;

namespace Beardy
{
Expand Down Expand Up @@ -121,7 +120,10 @@ private void SetCellsAlongAxis(int axis)
{
int positionX;
int positionY;
Vector2 cellStartOffset = (i+1 > rectChildrenCount - actualLastCellsCount) ? lastCellsStartOffset : startOffset;
bool isLastLine = i + 1 > rectChildrenCount - actualLastCellsCount;
Vector2 cellStartOffset = isLastLine ? lastCellsStartOffset : startOffset;
int thisCellCountX = isLastLine && startAxis == Axis.Horizontal ? actualLastCellsCount : actualCellCountX;
int thisCellCountY = isLastLine && startAxis == Axis.Vertical ? actualLastCellsCount : actualCellCountY;

if (startAxis == Axis.Horizontal)
{
Expand All @@ -135,9 +137,9 @@ private void SetCellsAlongAxis(int axis)
}

if (cornerX == 1)
positionX = actualCellCountX - 1 - positionX;
positionX = thisCellCountX - 1 - positionX;
if (cornerY == 1)
positionY = actualCellCountY - 1 - positionY;
positionY = thisCellCountY - 1 - positionY;

SetChildAlongAxis(rectChildren[i], 0, cellStartOffset.x + (cellSize[0] + spacing[0]) * positionX, cellSize[0]);
SetChildAlongAxis(rectChildren[i], 1, cellStartOffset.y + (cellSize[1] + spacing[1]) * positionY, cellSize[1]);
Expand Down