Multiline support for SimpleTooltipLogic

This commit is contained in:
atlimit8
2015-11-07 14:34:47 -06:00
parent 39fa74a013
commit cbc8d1c5ec
4 changed files with 15 additions and 6 deletions

View File

@@ -22,17 +22,26 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var font = Game.Renderer.Fonts[label.Font]; var font = Game.Renderer.Fonts[label.Font];
var cachedWidth = 0; var cachedWidth = 0;
var cachedHeight = 0;
var horizontalPadding = label.Bounds.Width - widget.Bounds.Width;
if (horizontalPadding <= 0)
horizontalPadding = 2 * label.Bounds.X;
var vertcalPadding = widget.Bounds.Height - label.Bounds.Height;
if (vertcalPadding <= 0)
vertcalPadding = 2 * label.Bounds.Y;
var labelText = ""; var labelText = "";
tooltipContainer.BeforeRender = () => tooltipContainer.BeforeRender = () =>
{ {
labelText = getText(); labelText = getText();
var textDim = font.Measure(labelText); var textDim = font.Measure(labelText);
if (textDim.X != cachedWidth) if (textDim.X != cachedWidth || textDim.Y != cachedHeight)
{ {
label.Bounds.Width = textDim.X; label.Bounds.Width = textDim.X;
widget.Bounds.Width = 2 * label.Bounds.X + textDim.X; widget.Bounds.Width = horizontalPadding + textDim.X;
label.Bounds.Height = textDim.Y; label.Bounds.Height = textDim.Y;
widget.Bounds.Height = 4 * label.Bounds.Y + textDim.Y; widget.Bounds.Height = vertcalPadding + textDim.Y;
cachedWidth = textDim.X;
cachedHeight = textDim.Y;
} }
}; };

View File

@@ -1,7 +1,7 @@
Background@SIMPLE_TOOLTIP: Background@SIMPLE_TOOLTIP:
Logic: SimpleTooltipLogic Logic: SimpleTooltipLogic
Background: panel-black Background: panel-black
Height: 25 Height: 27
Children: Children:
Label@LABEL: Label@LABEL:
X: 5 X: 5

View File

@@ -1,7 +1,7 @@
Background@SIMPLE_TOOLTIP: Background@SIMPLE_TOOLTIP:
Logic: SimpleTooltipLogic Logic: SimpleTooltipLogic
Background: dialog3 Background: dialog3
Height: 31 Height: 34
Children: Children:
Label@LABEL: Label@LABEL:
X: 5 X: 5

View File

@@ -1,7 +1,7 @@
Background@SIMPLE_TOOLTIP: Background@SIMPLE_TOOLTIP:
Logic: SimpleTooltipLogic Logic: SimpleTooltipLogic
Background: dialog4 Background: dialog4
Height: 29 Height: 32
Children: Children:
Label@LABEL: Label@LABEL:
X: 7 X: 7