// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osuTK; namespace osu.Framework.Graphics.UserInterface { public abstract class DirectorySelectorItem : CompositeDrawable { private readonly string displayName; /// /// Gets or sets the font size of this 's icon and text. /// protected const float FONT_SIZE = 16; /// /// The display name of this to fallback to when a display name is not provided. /// protected abstract string FallbackName { get; } /// /// The icon of this to use. /// protected abstract IconUsage? Icon { get; } protected FillFlowContainer Flow; protected DirectorySelectorItem(string displayName = null) { this.displayName = displayName; } /// /// Creates the sprite text to be used for the item text. /// protected virtual SpriteText CreateSpriteText() => new SpriteText(); [BackgroundDependencyLoader] private void load() { AutoSizeAxes = Axes.Both; InternalChild = Flow = new FillFlowContainer { AutoSizeAxes = Axes.Both, Margin = new MarginPadding { Vertical = 2, Horizontal = 5 }, Direction = FillDirection.Horizontal, Spacing = new Vector2(5), }; if (Icon.HasValue) { Flow.Add(new SpriteIcon { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, Icon = Icon.Value, Size = new Vector2(FONT_SIZE) }); } Flow.Add(CreateSpriteText().With(text => { text.Anchor = Anchor.CentreLeft; text.Origin = Anchor.CentreLeft; text.Text = displayName ?? FallbackName; })); } } }