Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect calc width in WrapTextSegment #997

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
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