A game framework written with osu! in mind.
at master 74 lines 2.4 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using osu.Framework.Allocation; 5using osu.Framework.Graphics.Containers; 6using osu.Framework.Graphics.Sprites; 7using osuTK; 8 9namespace osu.Framework.Graphics.UserInterface 10{ 11 public abstract class DirectorySelectorItem : CompositeDrawable 12 { 13 private readonly string displayName; 14 15 /// <summary> 16 /// Gets or sets the font size of this <see cref="DirectorySelectorItem"/>'s icon and text. 17 /// </summary> 18 protected const float FONT_SIZE = 16; 19 20 /// <summary> 21 /// The display name of this <see cref="DirectorySelectorItem"/> to fallback to when a display name is not provided. 22 /// </summary> 23 protected abstract string FallbackName { get; } 24 25 /// <summary> 26 /// The icon of this <see cref="DirectorySelectorItem"/> to use. 27 /// </summary> 28 protected abstract IconUsage? Icon { get; } 29 30 protected FillFlowContainer Flow; 31 32 protected DirectorySelectorItem(string displayName = null) 33 { 34 this.displayName = displayName; 35 } 36 37 /// <summary> 38 /// Creates the sprite text to be used for the item text. 39 /// </summary> 40 protected virtual SpriteText CreateSpriteText() => new SpriteText(); 41 42 [BackgroundDependencyLoader] 43 private void load() 44 { 45 AutoSizeAxes = Axes.Both; 46 47 InternalChild = Flow = new FillFlowContainer 48 { 49 AutoSizeAxes = Axes.Both, 50 Margin = new MarginPadding { Vertical = 2, Horizontal = 5 }, 51 Direction = FillDirection.Horizontal, 52 Spacing = new Vector2(5), 53 }; 54 55 if (Icon.HasValue) 56 { 57 Flow.Add(new SpriteIcon 58 { 59 Anchor = Anchor.CentreLeft, 60 Origin = Anchor.CentreLeft, 61 Icon = Icon.Value, 62 Size = new Vector2(FONT_SIZE) 63 }); 64 } 65 66 Flow.Add(CreateSpriteText().With(text => 67 { 68 text.Anchor = Anchor.CentreLeft; 69 text.Origin = Anchor.CentreLeft; 70 text.Text = displayName ?? FallbackName; 71 })); 72 } 73 } 74}