Skip to content

Commit

Permalink
Add 1px width padding to label check
Browse files Browse the repository at this point in the history
Solves an uncommon bug where final character in label is culled due to precision issues.
One check was also using >= condition when it should have been > condition.
  • Loading branch information
Interkarma committed Oct 4, 2023
1 parent 6f91e0c commit a0c9554
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Assets/Scripts/Game/UserInterface/TextLabel.cs
Expand Up @@ -24,6 +24,8 @@ public class TextLabel : BaseScreenComponent
{
#region Fields

const float totalWidthPadding = 1f;

public const int limitMinTextureDim = 8; // the smallest possible value for minTextureDim (used to enforce minimum texture dimensions of 8x8 to avoid "degenerate image" error in Unity 5.2)

int minTextureDim = limitMinTextureDim; // set this with property MinTextureDim to higher values if you experience scaling issues with small texts (e.g. inventory infopanel)
Expand Down Expand Up @@ -431,7 +433,7 @@ void CreateNewLabelLayoutSingleLine()
for (int i = 0; i < codes.Length; i++)
{
float glyphWidth = font.GetGlyphWidth(codes[i], LocalScale);
if (xpos + glyphWidth >= totalWidth)
if (xpos + glyphWidth > totalWidth + totalWidthPadding)
break;

GlyphLayoutData glyphPos = new GlyphLayoutData()
Expand Down Expand Up @@ -612,7 +614,7 @@ void CreateNewLabelLayoutWrapped()
for (int i = 0; i < row.Length; i++)
{
float glyphWidth = font.GetGlyphWidth(row[i], LocalScale);
if (xpos + glyphWidth > totalWidth)
if (xpos + glyphWidth > totalWidth + totalWidthPadding)
break;

if (row[i] == DaggerfallFont.SpaceCode)
Expand Down

0 comments on commit a0c9554

Please sign in to comment.