osu/osu.Game/Graphics/UserInterface/PageTabControl.cs

98 lines
3.0 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
2017-06-21 08:03:47 +00:00
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using osu.Game.Graphics.Sprites;
namespace osu.Game.Graphics.UserInterface
{
public class PageTabControl<T> : OsuTabControl<T>
{
protected override TabItem<T> CreateTabItem(T value) => new PageTabItem(value);
public PageTabControl()
{
Height = 30;
}
2017-06-09 08:01:16 +00:00
public class PageTabItem : TabItem<T>
{
2017-05-19 22:50:45 +00:00
private const float transition_duration = 100;
2017-05-19 22:50:45 +00:00
private readonly Box box;
2017-06-09 08:01:16 +00:00
protected readonly SpriteText Text;
public PageTabItem(T value) : base(value)
{
AutoSizeAxes = Axes.X;
RelativeSizeAxes = Axes.Y;
Children = new Drawable[]
{
2017-06-09 08:01:16 +00:00
Text = new OsuSpriteText
2017-05-19 19:22:54 +00:00
{
Margin = new MarginPadding { Top = 8, Bottom = 8 },
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
2017-06-09 08:01:16 +00:00
Text = (value as Enum)?.GetDescription() ?? value.ToString(),
2017-05-19 19:22:54 +00:00
TextSize = 14,
Font = @"Exo2.0-Bold",
},
box = new Box
{
RelativeSizeAxes = Axes.X,
Height = 5,
Scale = new Vector2(1f, 0f),
Colour = Color4.White,
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
},
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
box.Colour = colours.Yellow;
}
protected override bool OnHover(InputState state)
{
if (!Active)
slideActive();
return true;
}
protected override void OnHoverLost(InputState state)
{
if (!Active)
slideInactive();
}
private void slideActive()
{
box.ScaleTo(new Vector2(1f), transition_duration);
}
private void slideInactive()
{
box.ScaleTo(new Vector2(1f, 0f), transition_duration);
}
2017-06-12 09:39:22 +00:00
protected override void OnActivated() => slideActive();
protected override void OnDeactivated() => slideInactive();
}
}
}