1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 02:13:21 +08:00

Add optional strip to OsuTabControl.

This commit is contained in:
DrabWeb 2018-03-29 15:29:45 -03:00
parent 306ff09792
commit f43b009b96

View File

@ -20,16 +20,28 @@ namespace osu.Game.Graphics.UserInterface
{
public class OsuTabControl<T> : TabControl<T>
{
private readonly Box strip;
protected override Dropdown<T> CreateDropdown() => new OsuTabDropdown();
protected override TabItem<T> CreateTabItem(T value) => new OsuTabItem(value);
protected virtual float StripWidth() => TabContainer.Children.Sum(c => c.IsPresent ? c.DrawWidth + TabContainer.Spacing.X : 0) - TabContainer.Spacing.X;
private static bool isEnumType => typeof(T).IsEnum;
public OsuTabControl()
{
TabContainer.Spacing = new Vector2(10f, 0f);
Add(strip = new Box
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Height = 1,
Colour = Color4.White.Opacity(0),
});
if (isEnumType)
foreach (var val in (T[])Enum.GetValues(typeof(T)))
AddItem(val);
@ -57,6 +69,12 @@ namespace osu.Game.Graphics.UserInterface
}
}
public Color4 StripColour
{
get => strip.Colour;
set => strip.Colour = value;
}
protected override TabFillFlowContainer CreateTabFlow() => new OsuTabFillFlowContainer
{
Direction = FillDirection.Full,
@ -65,6 +83,15 @@ namespace osu.Game.Graphics.UserInterface
Masking = true
};
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
// dont bother calculating if the strip is invisible
if (strip.Colour.MaxAlpha > 0)
strip.ResizeWidthTo(StripWidth(), 500, Easing.OutQuint);
}
public class OsuTabItem : TabItem<T>, IHasAccentColour
{
protected readonly SpriteText Text;