Better support for dynamic tooltip sizes

This commit is contained in:
Paul Chote
2011-07-06 00:01:35 +12:00
parent dd7e270780
commit c965899b8c
9 changed files with 35 additions and 39 deletions

View File

@@ -18,22 +18,26 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
{
[ObjectCreator.UseCtor]
public SimpleTooltipLogic([ObjectCreator.Param] Widget widget,
[ObjectCreator.Param] TooltipContainerWidget tooltipContainer,
[ObjectCreator.Param] Func<string> getText)
{
var label = widget.GetWidget<LabelWidget>("LABEL");
var cachedWidth = 0;
var font = Game.Renderer.Fonts[label.Font];
label.GetText = () =>
var cachedWidth = 0;
var labelText = "";
tooltipContainer.BeforeRender = () =>
{
var text = getText();
var textWidth = font.Measure(text).X;
labelText = getText();
var textWidth = font.Measure(labelText).X;
if (textWidth != cachedWidth)
{
label.Bounds.Width = textWidth;
widget.Bounds.Width = 2*label.Bounds.X + textWidth;
}
return text;
};
label.GetText = () => labelText;
}
}
}

View File

@@ -18,25 +18,28 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
{
[ObjectCreator.UseCtor]
public WorldTooltipLogic([ObjectCreator.Param] Widget widget,
[ObjectCreator.Param] TooltipContainerWidget tooltipContainer,
[ObjectCreator.Param] CncWorldInteractionControllerWidget wic)
{
widget.IsVisible = () => wic.TooltipType != T.WorldTooltipType.None;
var label = widget.GetWidget<LabelWidget>("LABEL");
var font = Game.Renderer.Fonts[label.Font];
var cachedWidth = 0;
label.GetText = () =>
var labelText = "";
tooltipContainer.BeforeRender = () =>
{
var text = wic.TooltipType == T.WorldTooltipType.Unexplored ? "Unexplored Terrain" :
labelText = wic.TooltipType == T.WorldTooltipType.Unexplored ? "Unexplored Terrain" :
wic.ActorTooltip.Name();
var textWidth = font.Measure(text).X;
var textWidth = font.Measure(labelText).X;
if (textWidth != cachedWidth)
{
label.Bounds.Width = textWidth;
widget.Bounds.Width = 2*label.Bounds.X + textWidth;
}
return text;
};
label.GetText = () => labelText;
}
}
}