Scissor the text of a ButtonWidget if it overflows and display a tooltip

Also:
* add a variable to a comomn pattern used for truncating text in HotkeyEntryWidget and TextFieldWidget
This commit is contained in:
Ivaylo Draganov
2019-05-10 13:35:31 +03:00
committed by abcdefg30
parent f325a4d190
commit 76a6e7ec92
3 changed files with 24 additions and 4 deletions

View File

@@ -124,7 +124,8 @@ namespace OpenRA.Mods.Common.Widgets
var textPos = pos + new int2(LeftMargin, (Bounds.Height - textSize.Y) / 2 - VisualHeight);
// Scissor when the text overflows
if (textSize.X > Bounds.Width - LeftMargin - RightMargin)
var isTextOverflowing = textSize.X > Bounds.Width - LeftMargin - RightMargin;
if (isTextOverflowing)
{
Game.Renderer.EnableScissor(new Rectangle(pos.X + LeftMargin, pos.Y,
Bounds.Width - LeftMargin - RightMargin, Bounds.Bottom));
@@ -133,7 +134,7 @@ namespace OpenRA.Mods.Common.Widgets
var color = disabled ? TextColorDisabled : TextColor;
font.DrawText(apparentText, textPos, color);
if (textSize.X > Bounds.Width - LeftMargin - RightMargin)
if (isTextOverflowing)
Game.Renderer.DisableScissor();
}