1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 15:27:26 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/PageTabControl.cs

100 lines
3.0 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.
2018-04-13 17:19:50 +08:00
using System;
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
2018-10-02 11:02:47 +08:00
using osu.Framework.Input.Events;
2018-04-13 17:19:50 +08:00
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;
}
public class PageTabItem : TabItem<T>
{
private const float transition_duration = 100;
private readonly Box box;
protected readonly SpriteText Text;
public PageTabItem(T value) : base(value)
{
AutoSizeAxes = Axes.X;
RelativeSizeAxes = Axes.Y;
Children = new Drawable[]
{
Text = new OsuSpriteText
{
Margin = new MarginPadding { Top = 8, Bottom = 8 },
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Text = (value as Enum)?.GetDescription() ?? value.ToString(),
Font = OsuFont.GetFont(size: 14)
2018-04-13 17:19:50 +08:00
},
box = new Box
{
RelativeSizeAxes = Axes.X,
Height = 5,
Scale = new Vector2(1f, 0f),
Colour = Color4.White,
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
},
new HoverClickSounds()
};
2019-02-20 15:52:36 +08:00
Active.BindValueChanged(val => Text.Font = OsuFont.GetFont(Text.Font, weight: val ? FontWeight.Bold : FontWeight.Medium), true);
2018-04-13 17:19:50 +08:00
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
box.Colour = colours.Yellow;
}
2018-10-02 11:02:47 +08:00
protected override bool OnHover(HoverEvent e)
2018-04-13 17:19:50 +08:00
{
if (!Active)
slideActive();
return true;
}
2018-10-02 11:02:47 +08:00
protected override void OnHoverLost(HoverLostEvent e)
2018-04-13 17:19:50 +08:00
{
if (!Active)
slideInactive();
}
private void slideActive()
{
box.ScaleTo(new Vector2(1f), transition_duration);
}
private void slideInactive()
{
box.ScaleTo(new Vector2(1f, 0f), transition_duration);
}
protected override void OnActivated() => slideActive();
protected override void OnDeactivated() => slideInactive();
}
}
}