Moved LinkFlowContainer out of ProfileHeader to make it available for other uses too (e.g. chat) and renamed it to LinkTextFlowContainer bc it can contain both links and text, not only one

This commit is contained in:
FreezyLemon
2017-12-01 20:26:51 +01:00
parent f5f287bed5
commit 1f1c7dd70f
2 changed files with 54 additions and 51 deletions

View File

@ -0,0 +1,44 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input;
using osu.Game.Graphics.Sprites;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.Graphics.Containers
{
public class OsuLinkTextFlowContainer : OsuLinkTextFlowContainer<OsuLinkSpriteText>
{
public OsuLinkTextFlowContainer(Action<SpriteText> defaultCreationParameters = null)
: base(defaultCreationParameters)
{
}
}
public class OsuLinkTextFlowContainer<T> : OsuTextFlowContainer
where T : OsuLinkSpriteText, new()
{
public override bool HandleInput => true;
public OsuLinkTextFlowContainer(Action<SpriteText> defaultCreationParameters = null) : base(defaultCreationParameters)
{
}
protected override SpriteText CreateSpriteText() => new T();
public void AddLink(string text, string url, Action<SpriteText> creationParameters = null)
{
AddText(text, link =>
{
((T)link).Url = url;
creationParameters?.Invoke(link);
});
}
}
}