Fix LabelWidget positioning of text when WordWrap is true.
If WordWrap is enabled, the wrapping must be applied before any TextAlign is applied, or the final position will be incorrect. Introduce a IncreaseHeightToFitCurrentText to make such WordWrap labels easier to use, and apply to CreditsLogic.
This commit is contained in:
@@ -68,6 +68,17 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
GetContrastColorLight = other.GetContrastColorLight;
|
||||
}
|
||||
|
||||
public void IncreaseHeightToFitCurrentText()
|
||||
{
|
||||
if (!Game.Renderer.Fonts.TryGetValue(Font, out var font))
|
||||
throw new ArgumentException($"Requested font '{Font}' was not found.");
|
||||
|
||||
var line = GetText();
|
||||
if (WordWrap)
|
||||
line = WidgetUtils.WrapText(line, Bounds.Width, font);
|
||||
Bounds.Height = Math.Max(Bounds.Height, font.Measure(line).Y);
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
if (!Game.Renderer.Fonts.TryGetValue(Font, out var font))
|
||||
@@ -77,6 +88,9 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (text == null)
|
||||
return;
|
||||
|
||||
if (WordWrap)
|
||||
text = WidgetUtils.WrapText(text, Bounds.Width, font);
|
||||
|
||||
var textSize = font.Measure(text);
|
||||
var position = RenderOrigin;
|
||||
var offset = font.TopOffset;
|
||||
@@ -96,9 +110,6 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (Align == TextAlign.Right)
|
||||
position += new int2(Bounds.Width - textSize.X, 0);
|
||||
|
||||
if (WordWrap)
|
||||
text = WidgetUtils.WrapText(text, Bounds.Width, font);
|
||||
|
||||
DrawInner(text, font, GetColor(), position);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user