Skip to content

Commit

Permalink
Update UiPanel.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
burdoto committed Feb 17, 2024
1 parent c153a7f commit 94348bb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions textUI/UiPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ public override IEnumerable<string> Print(int width, int height)
goto end;
}

var emptyLine = string.Empty;
for (var col = 0; col < width; col++)
emptyLine += ' ';
if (Lines.Count == 0 || Lines.All(string.IsNullOrWhiteSpace))
{
for (var row = 0; row < height; row++)
yield return emptyLine;
goto end;
}

var nNewl = Lines.Count;
var spacingH = height - (1 + nNewl);
var halfSpacingH = spacingH / 2;
Expand All @@ -69,7 +79,7 @@ public override IEnumerable<string> Print(int width, int height)

// top padding
for (var h = 0; h < limSpacingH; h++)
yield return "";
yield return emptyLine;

// text content
foreach (var str in Lines)
Expand All @@ -87,7 +97,7 @@ public override IEnumerable<string> Print(int width, int height)
// bottom padding
limSpacingH -= evenSpacingH ? 1 : 0;
for (var h = 0; h < limSpacingH; h++)
yield return "";
yield return emptyLine;

end: ;
}
Expand Down

0 comments on commit 94348bb

Please sign in to comment.