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
12 changes: 7 additions & 5 deletions Blish HUD/_Utils/DrawUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,19 @@ private static string WrapTextSegment(BitmapFont spriteFont, string text, float
string[] words = text.Split(' ');
var sb = new StringBuilder();
float lineWidth = 0f;
float spaceWidth = spriteFont.MeasureString(" ").Width;
float spaceWidth = spriteFont.MeasureString(" ").Width - spriteFont.MeasureString(" ").Width;
float aWidth = spriteFont.MeasureString("a").Width;

foreach (string word in words) {
Vector2 size = spriteFont.MeasureString(word);
float wordWidth = spriteFont.MeasureString("a" + word).Width - aWidth;
wordWidth = Math.Max(wordWidth, spriteFont.MeasureString(word + "a").Width - aWidth);

if (lineWidth + size.X < maxLineWidth) {
if (lineWidth + wordWidth < maxLineWidth) {
sb.Append(word + " ");
lineWidth += size.X + spaceWidth;
lineWidth += wordWidth + spaceWidth;
} else {
sb.Append("\n" + word + " ");
lineWidth = size.X + spaceWidth;
lineWidth = wordWidth + spaceWidth;
}
}

Expand Down