(26639256a) - Added a method that automatically sets the text scale of a set of GUITextBlocks so that they all use the same scale and the text fits in all of the blocks. - Fixed TextBlock padding not being taken into account if the text is centered. - AutoScale and change the layout in a bunch of places where translated texts are likely to not fit.

This commit is contained in:
Joonas Rikkonen
2019-04-29 21:12:47 +03:00
parent e21b4e5efc
commit 8737a0e0dd
7 changed files with 147 additions and 56 deletions
@@ -1,6 +1,8 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma
{
@@ -247,7 +249,7 @@ namespace Barotrauma
return;
}
textPos = new Vector2(rect.Width / 2.0f, rect.Height / 2.0f);
textPos = new Vector2(padding.X + (rect.Width - padding.Z - padding.X) / 2.0f, padding.Y + (rect.Height - padding.Y - padding.W) / 2.0f);
origin = TextSize * 0.5f;
if (textAlignment.HasFlag(Alignment.Left) && !overflowClipActive)
@@ -338,5 +340,25 @@ namespace Barotrauma
if (OutlineColor.A * currColor.A > 0.0f) GUI.DrawRectangle(spriteBatch, rect, OutlineColor * (currColor.A / 255.0f), false);
}
/// <summary>
/// Set the text scale of the GUITextBlocks so that they all use the same scale and can fit the text within the block.
/// </summary>
public static void AutoScaleAndNormalize(IEnumerable<GUITextBlock> textBlocks)
{
if (!textBlocks.Any()) { return; }
float minScale = textBlocks.First().TextScale;
foreach (GUITextBlock textBlock in textBlocks)
{
textBlock.AutoScale = true;
minScale = Math.Min(textBlock.TextScale, minScale);
}
foreach (GUITextBlock textBlock in textBlocks)
{
textBlock.AutoScale = false;
textBlock.TextScale = minScale;
}
}
}
}