// Copyright (c) ppy Pty Ltd . 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 osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Localisation; using osuTK; using osuTK.Graphics; namespace osu.Game.Graphics.Sprites { public class SizePreservingSpriteText : CompositeDrawable { private readonly OsuSpriteText text = new OsuSpriteText(); private Vector2 maximumSize; public SizePreservingSpriteText(Vector2? minimumSize = null) { text.Origin = Anchor.Centre; text.Anchor = Anchor.Centre; AddInternal(text); maximumSize = minimumSize ?? Vector2.Zero; } protected override void Update() { Width = maximumSize.X = MathF.Max(maximumSize.X, text.Width); Height = maximumSize.Y = MathF.Max(maximumSize.Y, text.Height); } public new Axes AutoSizeAxes { get => Axes.None; set => throw new InvalidOperationException("You can't set AutoSizeAxes of this container"); } /// /// Gets or sets the text to be displayed. /// public LocalisableString Text { get => text.Text; set => text.Text = value; } /// /// Contains information on the font used to display the text. /// public FontUsage Font { get => text.Font; set => text.Font = value; } /// /// True if a shadow should be displayed around the text. /// public bool Shadow { get => text.Shadow; set => text.Shadow = value; } /// /// The colour of the shadow displayed around the text. A shadow will only be displayed if the property is set to true. /// public Color4 ShadowColour { get => text.ShadowColour; set => text.ShadowColour = value; } /// /// The offset of the shadow displayed around the text. A shadow will only be displayed if the property is set to true. /// public Vector2 ShadowOffset { get => text.ShadowOffset; set => text.ShadowOffset = value; } /// /// True if the 's vertical size should be equal to (the full height) or precisely the size of used characters. /// Set to false to allow better centering of individual characters/numerals/etc. /// public bool UseFullGlyphHeight { get => text.UseFullGlyphHeight; set => text.UseFullGlyphHeight = value; } public override bool IsPresent => text.IsPresent; public override string ToString() => text.ToString(); public float LineBaseHeight => text.LineBaseHeight; public IEnumerable FilterTerms => text.FilterTerms; } }