Support SpriteText for LinkFlowContainer

This commit is contained in:
PercyDan54
2021-04-18 20:58:08 +08:00
parent 38a7c590c4
commit 488001d570
3 changed files with 29 additions and 1 deletions

View File

@ -67,6 +67,13 @@ namespace osu.Game.Graphics.Containers
createLink(text, new LinkDetails(action, linkArgument), tooltipText);
}
public void AddLink(SpriteText text, LinkAction action = LinkAction.External, string linkArgument = null, string tooltipText = null)
{
AddArbitraryDrawable(text);
createLink(text, new LinkDetails(action, linkArgument), tooltipText);
}
public void AddUserLink(User user, Action<SpriteText> creationParameters = null)
=> createLink(AddText(user.Username, creationParameters), new LinkDetails(LinkAction.OpenUserProfile, user.Id.ToString()), "view profile");
@ -86,6 +93,22 @@ namespace osu.Game.Graphics.Containers
});
}
private void createLink(Drawable drawable, LinkDetails link, string tooltipText, Action action = null)
{
AddInternal(new DrawableLinkCompiler(drawable)
{
RelativeSizeAxes = Axes.Both,
TooltipText = tooltipText,
Action = () =>
{
if (action != null)
action();
else
game?.HandleLink(link);
},
});
}
// We want the compilers to always be visible no matter where they are, so RelativeSizeAxes is used.
// However due to https://github.com/ppy/osu-framework/issues/2073, it's possible for the compilers to be relative size in the flow's auto-size axes - an unsupported operation.
// Since the compilers don't display any content and don't affect the layout, it's simplest to exclude them from the flow.