1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 18:20:34 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/PageTabControl.cs

99 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 16:03:47 +08: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 16:01:16 +08:00
public class PageTabItem : TabItem<T>
{
2017-05-20 06:50:45 +08:00
private const float transition_duration = 100;
2017-05-20 06:50:45 +08:00
private readonly Box box;
2017-06-09 16:01:16 +08:00
protected readonly SpriteText Text;
public PageTabItem(T value) : base(value)
{
AutoSizeAxes = Axes.X;
RelativeSizeAxes = Axes.Y;
Children = new Drawable[]
{
2017-06-09 16:01:16 +08:00
Text = new OsuSpriteText
2017-05-20 03:22:54 +08:00
{
Margin = new MarginPadding { Top = 8, Bottom = 8 },
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
2017-06-09 16:01:16 +08:00
Text = (value as Enum)?.GetDescription() ?? value.ToString(),
2017-05-20 03:22:54 +08: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,
},
new HoverClickSounds()
};
}
[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 17:39:22 +08:00
protected override void OnActivated() => slideActive();
protected override void OnDeactivated() => slideInactive();
}
}
}