1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-20 10:25:30 +08:00

Allow any type to be used to create TabControl

This commit is contained in:
Andrei Zavatski 2020-01-08 00:41:52 +03:00
parent 6d8f457161
commit eb828154ee
6 changed files with 56 additions and 18 deletions

View File

@ -24,7 +24,7 @@ namespace osu.Game.Tests.Visual.Online
typeof(ProfileHeader),
typeof(RankGraph),
typeof(LineGraph),
typeof(TabControlOverlayHeader.OverlayHeaderTabControl),
typeof(TabControlOverlayHeader<>.OverlayHeaderTabControl),
typeof(CentreHeaderContainer),
typeof(BottomHeaderContainer),
typeof(DetailHeaderContainer),

View File

@ -22,11 +22,12 @@ namespace osu.Game.Tests.Visual.UserInterface
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(OverlayHeader),
typeof(ControllableOverlayHeader),
typeof(TabControlOverlayHeader),
typeof(ControllableOverlayHeader<>),
typeof(TabControlOverlayHeader<>),
typeof(BreadcrumbControlOverlayHeader),
typeof(TestNoControlHeader),
typeof(TestTabControlHeader),
typeof(TestStringTabControlHeader),
typeof(TestEnumTabControlHeader),
typeof(TestBreadcrumbControlHeader),
};
@ -54,7 +55,8 @@ namespace osu.Game.Tests.Visual.UserInterface
});
addHeader("OverlayHeader", new TestNoControlHeader());
addHeader("TabControlOverlayHeader", new TestTabControlHeader());
addHeader("TabControlOverlayHeader (string)", new TestStringTabControlHeader());
addHeader("TabControlOverlayHeader (enum)", new TestEnumTabControlHeader());
addHeader("BreadcrumbControlOverlayHeader", new TestBreadcrumbControlHeader());
}
@ -69,10 +71,16 @@ namespace osu.Game.Tests.Visual.UserInterface
{
new OsuSpriteText
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Margin = new MarginPadding(20),
Text = name,
},
header
header.With(header =>
{
header.Anchor = Anchor.TopCentre;
header.Origin = Anchor.TopCentre;
})
}
});
}
@ -90,13 +98,13 @@ namespace osu.Game.Tests.Visual.UserInterface
}
}
private class TestTabControlHeader : TabControlOverlayHeader
private class TestStringTabControlHeader : TabControlOverlayHeader<string>
{
protected override Drawable CreateBackground() => new TestBackground();
protected override ScreenTitle CreateTitle() => new TestTitle();
public TestTabControlHeader()
public TestStringTabControlHeader()
{
TabControl.AddItem("tab1");
TabControl.AddItem("tab2");
@ -111,6 +119,28 @@ namespace osu.Game.Tests.Visual.UserInterface
}
}
private class TestEnumTabControlHeader : TabControlOverlayHeader<TestEnum>
{
protected override Drawable CreateBackground() => new TestBackground();
protected override ScreenTitle CreateTitle() => new TestTitle();
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
TitleBackgroundColour = colours.GreyVioletDarker;
ControlBackgroundColour = colours.GreyVioletDark;
TabControl.AccentColour = colours.Violet;
}
}
private enum TestEnum
{
Some,
Cool,
Tabs
}
private class TestBreadcrumbControlHeader : BreadcrumbControlOverlayHeader
{
protected override Drawable CreateBackground() => new TestBackground();

View File

@ -7,7 +7,7 @@ using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays
{
public abstract class BreadcrumbControlOverlayHeader : ControllableOverlayHeader
public abstract class BreadcrumbControlOverlayHeader : ControllableOverlayHeader<string>
{
protected OverlayHeaderBreadcrumbControl BreadcrumbControl;

View File

@ -9,7 +9,8 @@ using osuTK.Graphics;
namespace osu.Game.Overlays
{
public abstract class ControllableOverlayHeader : OverlayHeader
/// <typeparam name="T">The type of item to be represented by tabs in <see cref="TabControl{T}"/>.</typeparam>
public abstract class ControllableOverlayHeader<T> : OverlayHeader
{
protected Color4 ControlBackgroundColour
{
@ -36,6 +37,6 @@ namespace osu.Game.Overlays
});
}
protected abstract TabControl<string> CreateTabControl();
protected abstract TabControl<T> CreateTabControl();
}
}

View File

@ -15,7 +15,7 @@ using osu.Game.Users;
namespace osu.Game.Overlays.Profile
{
public class ProfileHeader : TabControlOverlayHeader
public class ProfileHeader : TabControlOverlayHeader<string>
{
private UserCoverBackground coverContainer;

View File

@ -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.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
@ -9,13 +10,13 @@ using osuTK;
namespace osu.Game.Overlays
{
public abstract class TabControlOverlayHeader : ControllableOverlayHeader
public abstract class TabControlOverlayHeader<T> : ControllableOverlayHeader<T>
{
protected OverlayHeaderTabControl TabControl;
protected override TabControl<string> CreateTabControl() => TabControl = new OverlayHeaderTabControl();
protected override TabControl<T> CreateTabControl() => TabControl = new OverlayHeaderTabControl();
public class OverlayHeaderTabControl : OverlayTabControl<string>
public class OverlayHeaderTabControl : OverlayTabControl<T>
{
public OverlayHeaderTabControl()
{
@ -25,9 +26,15 @@ namespace osu.Game.Overlays
Anchor = Anchor.BottomLeft;
Origin = Anchor.BottomLeft;
Height = 35;
if (typeof(T).IsEnum)
{
foreach (var val in (T[])Enum.GetValues(typeof(T)))
AddItem(val);
}
}
protected override TabItem<string> CreateTabItem(string value) => new OverlayHeaderTabItem(value)
protected override TabItem<T> CreateTabItem(T value) => new OverlayHeaderTabItem(value)
{
AccentColour = AccentColour,
};
@ -42,10 +49,10 @@ namespace osu.Game.Overlays
private class OverlayHeaderTabItem : OverlayTabItem
{
public OverlayHeaderTabItem(string value)
public OverlayHeaderTabItem(T value)
: base(value)
{
Text.Text = value;
Text.Text = value.ToString().ToLowerInvariant();
Text.Font = OsuFont.GetFont(size: 14);
Bar.ExpandedSize = 5;
}