mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 20:13:21 +08:00
Enum constraint for enum dropdown.
This commit is contained in:
parent
40a5c1fd96
commit
c3518a2b94
@ -6,12 +6,10 @@ using System;
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public class OsuEnumDropdown<T> : OsuDropdown<T>
|
||||
where T : struct, Enum
|
||||
{
|
||||
public OsuEnumDropdown()
|
||||
{
|
||||
if (!typeof(T).IsEnum)
|
||||
throw new InvalidOperationException("OsuEnumDropdown only supports enums as the generic type argument");
|
||||
|
||||
Items = (T[])Enum.GetValues(typeof(T));
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using osu.Framework.Bindables;
|
||||
using osuTK;
|
||||
using osu.Framework.Graphics;
|
||||
@ -11,6 +12,7 @@ using osu.Game.Graphics.Containers;
|
||||
namespace osu.Game.Overlays.SearchableList
|
||||
{
|
||||
public class DisplayStyleControl<T> : Container
|
||||
where T : struct, Enum
|
||||
{
|
||||
public readonly SlimEnumDropdown<T> Dropdown;
|
||||
public readonly Bindable<PanelDisplayStyle> DisplayStyle = new Bindable<PanelDisplayStyle>();
|
||||
|
@ -13,7 +13,9 @@ using osu.Framework.Graphics.Shapes;
|
||||
|
||||
namespace osu.Game.Overlays.SearchableList
|
||||
{
|
||||
public abstract class SearchableListFilterControl<T, U> : Container
|
||||
public abstract class SearchableListFilterControl<TTab, TCategory> : Container
|
||||
where TTab : struct, Enum
|
||||
where TCategory : struct, Enum
|
||||
{
|
||||
private const float padding = 10;
|
||||
|
||||
@ -21,12 +23,12 @@ namespace osu.Game.Overlays.SearchableList
|
||||
private readonly Box tabStrip;
|
||||
|
||||
public readonly SearchTextBox Search;
|
||||
public readonly PageTabControl<T> Tabs;
|
||||
public readonly DisplayStyleControl<U> DisplayStyleControl;
|
||||
public readonly PageTabControl<TTab> Tabs;
|
||||
public readonly DisplayStyleControl<TCategory> DisplayStyleControl;
|
||||
|
||||
protected abstract Color4 BackgroundColour { get; }
|
||||
protected abstract T DefaultTab { get; }
|
||||
protected abstract U DefaultCategory { get; }
|
||||
protected abstract TTab DefaultTab { get; }
|
||||
protected abstract TCategory DefaultCategory { get; }
|
||||
protected virtual Drawable CreateSupplementaryControls() => null;
|
||||
|
||||
/// <summary>
|
||||
@ -36,9 +38,6 @@ namespace osu.Game.Overlays.SearchableList
|
||||
|
||||
protected SearchableListFilterControl()
|
||||
{
|
||||
if (!typeof(T).IsEnum)
|
||||
throw new InvalidOperationException("SearchableListFilterControl's sort tabs only support enums as the generic type argument");
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
|
||||
var controls = CreateSupplementaryControls();
|
||||
@ -90,7 +89,7 @@ namespace osu.Game.Overlays.SearchableList
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Padding = new MarginPadding { Right = 225 },
|
||||
Child = Tabs = new PageTabControl<T>
|
||||
Child = Tabs = new PageTabControl<TTab>
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
},
|
||||
@ -105,7 +104,7 @@ namespace osu.Game.Overlays.SearchableList
|
||||
},
|
||||
},
|
||||
},
|
||||
DisplayStyleControl = new DisplayStyleControl<U>
|
||||
DisplayStyleControl = new DisplayStyleControl<TCategory>
|
||||
{
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
|
@ -14,6 +14,7 @@ using osu.Framework.Graphics.Sprites;
|
||||
namespace osu.Game.Overlays.SearchableList
|
||||
{
|
||||
public abstract class SearchableListHeader<T> : Container
|
||||
where T : struct, Enum
|
||||
{
|
||||
public readonly HeaderTabControl<T> Tabs;
|
||||
|
||||
@ -24,9 +25,6 @@ namespace osu.Game.Overlays.SearchableList
|
||||
|
||||
protected SearchableListHeader()
|
||||
{
|
||||
if (!typeof(T).IsEnum)
|
||||
throw new InvalidOperationException("BrowseHeader only supports enums as the generic type argument");
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Height = 90;
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using osuTK.Graphics;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -16,19 +17,22 @@ namespace osu.Game.Overlays.SearchableList
|
||||
public const float WIDTH_PADDING = 80;
|
||||
}
|
||||
|
||||
public abstract class SearchableListOverlay<T, U, S> : SearchableListOverlay
|
||||
public abstract class SearchableListOverlay<THeader, TTab, TCategory> : SearchableListOverlay
|
||||
where THeader : struct, Enum
|
||||
where TTab : struct, Enum
|
||||
where TCategory : struct, Enum
|
||||
{
|
||||
private readonly Container scrollContainer;
|
||||
|
||||
protected readonly SearchableListHeader<T> Header;
|
||||
protected readonly SearchableListFilterControl<U, S> Filter;
|
||||
protected readonly SearchableListHeader<THeader> Header;
|
||||
protected readonly SearchableListFilterControl<TTab, TCategory> Filter;
|
||||
protected readonly FillFlowContainer ScrollFlow;
|
||||
|
||||
protected abstract Color4 BackgroundColour { get; }
|
||||
protected abstract Color4 TrianglesColourLight { get; }
|
||||
protected abstract Color4 TrianglesColourDark { get; }
|
||||
protected abstract SearchableListHeader<T> CreateHeader();
|
||||
protected abstract SearchableListFilterControl<U, S> CreateFilterControl();
|
||||
protected abstract SearchableListHeader<THeader> CreateHeader();
|
||||
protected abstract SearchableListFilterControl<TTab, TCategory> CreateFilterControl();
|
||||
|
||||
protected SearchableListOverlay()
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using osuTK.Graphics;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
@ -11,6 +12,7 @@ using osuTK;
|
||||
namespace osu.Game.Overlays.SearchableList
|
||||
{
|
||||
public class SlimEnumDropdown<T> : OsuEnumDropdown<T>
|
||||
where T : struct, Enum
|
||||
{
|
||||
protected override DropdownHeader CreateHeader() => new SlimDropdownHeader();
|
||||
|
||||
|
@ -1,12 +1,14 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
|
||||
namespace osu.Game.Overlays.Settings
|
||||
{
|
||||
public class SettingsEnumDropdown<T> : SettingsDropdown<T>
|
||||
where T : struct, Enum
|
||||
{
|
||||
protected override OsuDropdown<T> CreateDropdown() => new DropdownControl();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user