1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/OsuTabControl.cs

50 lines
1.6 KiB
C#
Raw Normal View History

2017-03-05 12:07:47 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2017-03-15 11:19:41 +08:00
using System;
2017-03-16 10:39:09 +08:00
using System.Linq;
2017-03-16 08:52:31 +08:00
using OpenTK.Graphics;
using osu.Framework.Allocation;
2017-03-05 12:07:47 +08:00
using osu.Framework.Graphics.UserInterface.Tab;
2017-03-16 08:11:50 +08:00
namespace osu.Game.Graphics.UserInterface
2017-03-05 12:07:47 +08:00
{
2017-03-16 08:11:50 +08:00
public class OsuTabControl<T> : TabControl<T>
2017-03-05 12:07:47 +08:00
{
2017-03-16 08:11:50 +08:00
protected override TabDropDownMenu<T> CreateDropDownMenu() => new OsuTabDropDownMenu<T>();
2017-03-05 12:07:47 +08:00
2017-03-16 08:11:50 +08:00
protected override TabItem<T> CreateTabItem(T value) => new OsuTabItem<T> { Value = value };
2017-03-08 17:19:00 +08:00
2017-03-16 08:11:50 +08:00
public OsuTabControl(float offset = 0) : base(offset)
2017-03-08 17:19:00 +08:00
{
2017-03-15 11:19:41 +08:00
if (!typeof(T).IsEnum)
2017-03-16 08:11:50 +08:00
throw new InvalidOperationException("OsuTabControl only supports enums as the generic type argument");
2017-03-15 11:19:41 +08:00
foreach (var val in (T[])Enum.GetValues(typeof(T)))
AddTab(val);
2017-03-08 17:19:00 +08:00
}
2017-03-16 08:52:31 +08:00
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
if (accentColour == null)
AccentColour = colours.Blue;
}
private Color4? accentColour;
public Color4 AccentColour
{
get { return accentColour.GetValueOrDefault(); }
set
{
accentColour = value;
2017-03-16 10:39:09 +08:00
var dropDown = DropDown as OsuTabDropDownMenu<T>;
if (dropDown != null)
dropDown.AccentColour = value;
foreach (var item in TabContainer.Children.OfType<OsuTabItem<T>>())
2017-03-16 08:52:31 +08:00
item.AccentColour = value;
}
}
2017-03-05 12:07:47 +08:00
}
}