mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 22:12:53 +08:00
Allow any type to be used to create TabControl
This commit is contained in:
parent
6d8f457161
commit
eb828154ee
@ -24,7 +24,7 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
typeof(ProfileHeader),
|
typeof(ProfileHeader),
|
||||||
typeof(RankGraph),
|
typeof(RankGraph),
|
||||||
typeof(LineGraph),
|
typeof(LineGraph),
|
||||||
typeof(TabControlOverlayHeader.OverlayHeaderTabControl),
|
typeof(TabControlOverlayHeader<>.OverlayHeaderTabControl),
|
||||||
typeof(CentreHeaderContainer),
|
typeof(CentreHeaderContainer),
|
||||||
typeof(BottomHeaderContainer),
|
typeof(BottomHeaderContainer),
|
||||||
typeof(DetailHeaderContainer),
|
typeof(DetailHeaderContainer),
|
||||||
|
@ -22,11 +22,12 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
{
|
{
|
||||||
typeof(OverlayHeader),
|
typeof(OverlayHeader),
|
||||||
typeof(ControllableOverlayHeader),
|
typeof(ControllableOverlayHeader<>),
|
||||||
typeof(TabControlOverlayHeader),
|
typeof(TabControlOverlayHeader<>),
|
||||||
typeof(BreadcrumbControlOverlayHeader),
|
typeof(BreadcrumbControlOverlayHeader),
|
||||||
typeof(TestNoControlHeader),
|
typeof(TestNoControlHeader),
|
||||||
typeof(TestTabControlHeader),
|
typeof(TestStringTabControlHeader),
|
||||||
|
typeof(TestEnumTabControlHeader),
|
||||||
typeof(TestBreadcrumbControlHeader),
|
typeof(TestBreadcrumbControlHeader),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -54,7 +55,8 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
});
|
});
|
||||||
|
|
||||||
addHeader("OverlayHeader", new TestNoControlHeader());
|
addHeader("OverlayHeader", new TestNoControlHeader());
|
||||||
addHeader("TabControlOverlayHeader", new TestTabControlHeader());
|
addHeader("TabControlOverlayHeader (string)", new TestStringTabControlHeader());
|
||||||
|
addHeader("TabControlOverlayHeader (enum)", new TestEnumTabControlHeader());
|
||||||
addHeader("BreadcrumbControlOverlayHeader", new TestBreadcrumbControlHeader());
|
addHeader("BreadcrumbControlOverlayHeader", new TestBreadcrumbControlHeader());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,10 +71,16 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
{
|
{
|
||||||
new OsuSpriteText
|
new OsuSpriteText
|
||||||
{
|
{
|
||||||
|
Anchor = Anchor.TopCentre,
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
Margin = new MarginPadding(20),
|
Margin = new MarginPadding(20),
|
||||||
Text = name,
|
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 Drawable CreateBackground() => new TestBackground();
|
||||||
|
|
||||||
protected override ScreenTitle CreateTitle() => new TestTitle();
|
protected override ScreenTitle CreateTitle() => new TestTitle();
|
||||||
|
|
||||||
public TestTabControlHeader()
|
public TestStringTabControlHeader()
|
||||||
{
|
{
|
||||||
TabControl.AddItem("tab1");
|
TabControl.AddItem("tab1");
|
||||||
TabControl.AddItem("tab2");
|
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
|
private class TestBreadcrumbControlHeader : BreadcrumbControlOverlayHeader
|
||||||
{
|
{
|
||||||
protected override Drawable CreateBackground() => new TestBackground();
|
protected override Drawable CreateBackground() => new TestBackground();
|
||||||
|
@ -7,7 +7,7 @@ using osu.Game.Graphics.UserInterface;
|
|||||||
|
|
||||||
namespace osu.Game.Overlays
|
namespace osu.Game.Overlays
|
||||||
{
|
{
|
||||||
public abstract class BreadcrumbControlOverlayHeader : ControllableOverlayHeader
|
public abstract class BreadcrumbControlOverlayHeader : ControllableOverlayHeader<string>
|
||||||
{
|
{
|
||||||
protected OverlayHeaderBreadcrumbControl BreadcrumbControl;
|
protected OverlayHeaderBreadcrumbControl BreadcrumbControl;
|
||||||
|
|
||||||
|
@ -9,7 +9,8 @@ using osuTK.Graphics;
|
|||||||
|
|
||||||
namespace osu.Game.Overlays
|
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
|
protected Color4 ControlBackgroundColour
|
||||||
{
|
{
|
||||||
@ -36,6 +37,6 @@ namespace osu.Game.Overlays
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract TabControl<string> CreateTabControl();
|
protected abstract TabControl<T> CreateTabControl();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ using osu.Game.Users;
|
|||||||
|
|
||||||
namespace osu.Game.Overlays.Profile
|
namespace osu.Game.Overlays.Profile
|
||||||
{
|
{
|
||||||
public class ProfileHeader : TabControlOverlayHeader
|
public class ProfileHeader : TabControlOverlayHeader<string>
|
||||||
{
|
{
|
||||||
private UserCoverBackground coverContainer;
|
private UserCoverBackground coverContainer;
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
@ -9,13 +10,13 @@ using osuTK;
|
|||||||
|
|
||||||
namespace osu.Game.Overlays
|
namespace osu.Game.Overlays
|
||||||
{
|
{
|
||||||
public abstract class TabControlOverlayHeader : ControllableOverlayHeader
|
public abstract class TabControlOverlayHeader<T> : ControllableOverlayHeader<T>
|
||||||
{
|
{
|
||||||
protected OverlayHeaderTabControl TabControl;
|
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()
|
public OverlayHeaderTabControl()
|
||||||
{
|
{
|
||||||
@ -25,9 +26,15 @@ namespace osu.Game.Overlays
|
|||||||
Anchor = Anchor.BottomLeft;
|
Anchor = Anchor.BottomLeft;
|
||||||
Origin = Anchor.BottomLeft;
|
Origin = Anchor.BottomLeft;
|
||||||
Height = 35;
|
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,
|
AccentColour = AccentColour,
|
||||||
};
|
};
|
||||||
@ -42,10 +49,10 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
private class OverlayHeaderTabItem : OverlayTabItem
|
private class OverlayHeaderTabItem : OverlayTabItem
|
||||||
{
|
{
|
||||||
public OverlayHeaderTabItem(string value)
|
public OverlayHeaderTabItem(T value)
|
||||||
: base(value)
|
: base(value)
|
||||||
{
|
{
|
||||||
Text.Text = value;
|
Text.Text = value.ToString().ToLowerInvariant();
|
||||||
Text.Font = OsuFont.GetFont(size: 14);
|
Text.Font = OsuFont.GetFont(size: 14);
|
||||||
Bar.ExpandedSize = 5;
|
Bar.ExpandedSize = 5;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user