1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 01:45:35 +08:00
osu-lazer/osu.Game/Overlays/TabControlOverlayHeader.cs

101 lines
3.3 KiB
C#
Raw Normal View History

// 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.
2020-01-21 11:03:48 +08:00
using JetBrains.Annotations;
2020-01-16 03:41:22 +08:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2020-01-03 14:01:42 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2020-01-21 11:00:12 +08:00
using osu.Framework.Graphics.Shapes;
2019-12-31 23:12:03 +08:00
using osu.Framework.Graphics.UserInterface;
2020-01-03 14:01:42 +08:00
using osu.Game.Graphics;
2020-01-21 11:00:12 +08:00
using osu.Game.Graphics.UserInterface;
2020-01-03 14:01:42 +08:00
using osuTK;
2019-12-31 23:12:03 +08:00
namespace osu.Game.Overlays
{
2020-01-21 11:00:12 +08:00
/// <summary>
2020-01-24 15:24:44 +08:00
/// An overlay header which contains a <see cref="OsuTabControl{T}"/>.
2020-01-21 11:00:12 +08:00
/// </summary>
2020-01-24 15:24:44 +08:00
/// <typeparam name="T">The type of item to be represented by tabs.</typeparam>
public abstract class TabControlOverlayHeader<T> : OverlayHeader, IHasCurrentValue<T>
{
2020-01-21 11:00:12 +08:00
protected OsuTabControl<T> TabControl;
2019-12-31 23:12:03 +08:00
private readonly BindableWithCurrent<T> current = new BindableWithCurrent<T>();
public Bindable<T> Current
{
get => current.Current;
set => current.Current = value;
}
2020-01-21 11:00:12 +08:00
private readonly Box controlBackground;
2020-01-03 14:01:42 +08:00
2020-01-26 21:35:07 +08:00
protected TabControlOverlayHeader()
2020-01-16 03:41:22 +08:00
{
2020-01-21 11:00:12 +08:00
HeaderInfo.Add(new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
controlBackground = new Box
{
RelativeSizeAxes = Axes.Both,
},
TabControl = CreateTabControl().With(control =>
{
control.Margin = new MarginPadding { Left = UserProfileOverlay.CONTENT_X_MARGIN };
control.Current = Current;
})
2020-01-21 11:00:12 +08:00
}
});
2020-01-16 03:41:22 +08:00
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
2020-01-16 03:41:22 +08:00
{
TabControl.AccentColour = colourProvider.Highlight1;
2020-01-26 21:35:07 +08:00
controlBackground.Colour = colourProvider.Dark4;
2020-01-16 03:41:22 +08:00
}
2020-01-21 11:03:48 +08:00
[NotNull]
2020-01-21 11:00:12 +08:00
protected virtual OsuTabControl<T> CreateTabControl() => new OverlayHeaderTabControl();
public class OverlayHeaderTabControl : OverlayTabControl<T>
2020-01-03 14:01:42 +08:00
{
public OverlayHeaderTabControl()
{
BarHeight = 1;
RelativeSizeAxes = Axes.None;
AutoSizeAxes = Axes.X;
Anchor = Anchor.BottomLeft;
Origin = Anchor.BottomLeft;
Height = 35;
}
2020-01-21 11:00:12 +08:00
protected override TabItem<T> CreateTabItem(T value) => new OverlayHeaderTabItem(value);
2020-01-03 14:01:42 +08:00
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
{
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5, 0),
};
private class OverlayHeaderTabItem : OverlayTabItem
{
public OverlayHeaderTabItem(T value)
2020-01-03 14:01:42 +08:00
: base(value)
{
Text.Text = value.ToString().ToLower();
2020-01-03 14:01:42 +08:00
Text.Font = OsuFont.GetFont(size: 14);
Bar.ExpandedSize = 5;
}
}
}
}
}