mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-15 03:20:30 +00:00
45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
#nullable disable
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using JetBrains.Annotations;
|
|
|
|
namespace osu.Framework.Graphics.Containers
|
|
{
|
|
/// <summary>
|
|
/// A basic implementation of <see cref="ITextPart"/>,
|
|
/// which automatically handles returning correct <see cref="Drawables"/>
|
|
/// and raising <see cref="DrawablePartsRecreated"/>.
|
|
/// </summary>
|
|
public abstract class TextPart : ITextPart
|
|
{
|
|
public IEnumerable<Drawable> Drawables { get; }
|
|
|
|
[CanBeNull]
|
|
public event Action<IEnumerable<Drawable>> DrawablePartsRecreated;
|
|
|
|
private readonly List<Drawable> drawables = new List<Drawable>();
|
|
|
|
protected TextPart()
|
|
{
|
|
Drawables = drawables.AsReadOnly();
|
|
}
|
|
|
|
public void RecreateDrawablesFor(TextFlowContainer textFlowContainer)
|
|
{
|
|
drawables.Clear();
|
|
drawables.AddRange(CreateDrawablesFor(textFlowContainer));
|
|
DrawablePartsRecreated?.Invoke(drawables);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates drawables representing the contents of this <see cref="TextPart"/>,
|
|
/// to be appended to the <paramref name="textFlowContainer"/>.
|
|
/// </summary>
|
|
protected abstract IEnumerable<Drawable> CreateDrawablesFor(TextFlowContainer textFlowContainer);
|
|
}
|
|
}
|