Skip to content

Commit

Permalink
Make grids without proportional rows/cols respect min size properly
Browse files Browse the repository at this point in the history
  • Loading branch information
BadMagic100 committed Jul 31, 2022
1 parent 83d1a0d commit 3a39c2b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion MagicUI/Core/Internal/SettingsBoundLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace MagicUI.Core.Internal
{
internal class SettingsBoundLogger
{
private SimpleLogger logger;
private readonly SimpleLogger logger;

public SettingsBoundLogger(string name)
{
Expand Down
19 changes: 19 additions & 0 deletions MagicUI/Elements/GridLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,16 @@ protected override Vector2 MeasureOverride()
colSizes[col] += remainingWidth * colProportions[col];
}
}
remainingWidth = minWidth - colSizes.Sum();
// on the offchance there's no proportional cols, reallocate the remaining space equally among the absolute columns.
if (remainingWidth > 0)
{
float sizePerCol = remainingWidth / colDefs.Count;
for (int col = 0; col < colDefs.Count; col++)
{
colSizes[col] += sizePerCol;
}
}

float remainingHeight = minHeight - requiredHeight;
if (remainingHeight > 0)
Expand All @@ -312,6 +322,15 @@ protected override Vector2 MeasureOverride()
rowSizes[row] += remainingHeight * rowProportions[row];
}
}
remainingHeight = minHeight - rowSizes.Sum();
if (remainingHeight > 0)
{
float sizePerRow = remainingHeight / rowDefs.Count;
for (int row = 0; row < rowDefs.Count; row++)
{
rowSizes[row] += sizePerRow;
}
}

log.Log($"Grid property post fill space");
log.Log($"Row sizes: {string.Join(", ", rowSizes)}");
Expand Down

0 comments on commit 3a39c2b

Please sign in to comment.