Make LabelledComponent generic

This commit is contained in:
smoogipoo 2019-09-24 18:22:02 +09:00
parent 79b64bdaa1
commit df692b091c
3 changed files with 11 additions and 10 deletions

View File

@ -25,7 +25,7 @@ private void createPaddedComponent(bool hasDescription = false, bool padded = tr
{ {
AddStep("create component", () => AddStep("create component", () =>
{ {
LabelledComponent component; LabelledComponent<Drawable> component;
Child = new Container Child = new Container
{ {
@ -33,7 +33,7 @@ private void createPaddedComponent(bool hasDescription = false, bool padded = tr
Origin = Anchor.Centre, Origin = Anchor.Centre,
Width = 500, Width = 500,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Child = component = padded ? (LabelledComponent)new PaddedLabelledComponent() : new NonPaddedLabelledComponent(), Child = component = padded ? (LabelledComponent<Drawable>)new PaddedLabelledComponent() : new NonPaddedLabelledComponent(),
}; };
component.Label = "a sample component"; component.Label = "a sample component";
@ -41,7 +41,7 @@ private void createPaddedComponent(bool hasDescription = false, bool padded = tr
}); });
} }
private class PaddedLabelledComponent : LabelledComponent private class PaddedLabelledComponent : LabelledComponent<Drawable>
{ {
public PaddedLabelledComponent() public PaddedLabelledComponent()
: base(true) : base(true)
@ -57,7 +57,7 @@ public PaddedLabelledComponent()
}; };
} }
private class NonPaddedLabelledComponent : LabelledComponent private class NonPaddedLabelledComponent : LabelledComponent<Drawable>
{ {
public NonPaddedLabelledComponent() public NonPaddedLabelledComponent()
: base(false) : base(false)

View File

@ -89,7 +89,7 @@ private void reload()
}; };
} }
private class ActionableInfo : LabelledComponent private class ActionableInfo : LabelledComponent<Drawable>
{ {
private OsuButton button; private OsuButton button;

View File

@ -11,7 +11,8 @@
namespace osu.Game.Screens.Edit.Setup.Components.LabelledComponents namespace osu.Game.Screens.Edit.Setup.Components.LabelledComponents
{ {
public abstract class LabelledComponent : CompositeDrawable public abstract class LabelledComponent<T> : CompositeDrawable
where T : Drawable
{ {
protected const float CONTENT_PADDING_VERTICAL = 10; protected const float CONTENT_PADDING_VERTICAL = 10;
protected const float CONTENT_PADDING_HORIZONTAL = 15; protected const float CONTENT_PADDING_HORIZONTAL = 15;
@ -20,15 +21,15 @@ public abstract class LabelledComponent : CompositeDrawable
/// <summary> /// <summary>
/// The component that is being displayed. /// The component that is being displayed.
/// </summary> /// </summary>
protected readonly Drawable Component; protected readonly T Component;
private readonly OsuTextFlowContainer labelText; private readonly OsuTextFlowContainer labelText;
private readonly OsuTextFlowContainer descriptionText; private readonly OsuTextFlowContainer descriptionText;
/// <summary> /// <summary>
/// Creates a new <see cref="LabelledComponent"/>. /// Creates a new <see cref="LabelledComponent{T}"/>.
/// </summary> /// </summary>
/// <param name="padded">Whether the component should be padded or should be expanded to the bounds of this <see cref="LabelledComponent"/>.</param> /// <param name="padded">Whether the component should be padded or should be expanded to the bounds of this <see cref="LabelledComponent{T}"/>.</param>
protected LabelledComponent(bool padded) protected LabelledComponent(bool padded)
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
@ -127,6 +128,6 @@ public string Description
/// Creates the component that should be displayed. /// Creates the component that should be displayed.
/// </summary> /// </summary>
/// <returns>The component.</returns> /// <returns>The component.</returns>
protected abstract Drawable CreateComponent(); protected abstract T CreateComponent();
} }
} }