1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 05:57:29 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/BreadcrumbControl.cs

85 lines
3.1 KiB
C#
Raw Normal View History

2017-05-26 18:49:45 +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
using OpenTK;
using osu.Framework;
2017-05-26 18:49:45 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2017-05-26 18:49:45 +08:00
using osu.Framework.Graphics.UserInterface;
2017-05-29 15:18:07 +08:00
using System.Linq;
2017-05-26 18:49:45 +08:00
namespace osu.Game.Graphics.UserInterface
{
public class BreadcrumbControl<T> : OsuTabControl<T>
{
2017-05-27 03:46:09 +08:00
private const float padding = 10;
2017-05-26 18:49:45 +08:00
protected override TabItem<T> CreateTabItem(T value) => new BreadcrumbTabItem(value);
public BreadcrumbControl()
{
2017-05-27 03:21:37 +08:00
Height = 26;
2017-05-27 03:46:09 +08:00
TabContainer.Spacing = new Vector2(padding, 0f);
2017-05-26 18:49:45 +08:00
Current.ValueChanged += tab =>
{
2017-05-29 15:18:07 +08:00
foreach (var t in TabContainer.Children.OfType<BreadcrumbTabItem>())
2017-05-26 18:49:45 +08:00
{
var tIndex = TabContainer.IndexOf(t);
var tabIndex = TabContainer.IndexOf(TabMap[tab]);
2017-05-29 15:18:07 +08:00
t.State = tIndex < tabIndex ? Visibility.Hidden : Visibility.Visible;
t.Chevron.FadeTo(tIndex <= tabIndex ? 0f : 1f, 500, EasingTypes.OutQuint);
2017-05-26 18:49:45 +08:00
}
};
}
private class BreadcrumbTabItem : OsuTabItem, IStateful<Visibility>
2017-05-26 18:49:45 +08:00
{
public readonly TextAwesome Chevron;
//don't allow clicking between transitions and don't make the chevron clickable
2017-05-27 03:29:20 +08:00
protected override bool InternalContains(Vector2 screenSpacePos) => Alpha == 1f && Text.Contains(screenSpacePos);
public override bool HandleInput => State == Visibility.Visible;
private Visibility state;
public Visibility State
{
get { return state; }
set
{
if (value == state) return;
state = value;
const float transition_duration = 500;
if (State == Visibility.Visible)
{
FadeIn(transition_duration, EasingTypes.OutQuint);
ScaleTo(new Vector2(1f), transition_duration, EasingTypes.OutQuint);
}
else
{
FadeOut(transition_duration, EasingTypes.OutQuint);
ScaleTo(new Vector2(0.8f, 1f), transition_duration, EasingTypes.OutQuint);
}
}
}
2017-05-26 18:49:45 +08:00
public BreadcrumbTabItem(T value) : base(value)
{
2017-05-27 03:21:37 +08:00
Text.TextSize = 16;
2017-05-27 03:46:09 +08:00
Padding = new MarginPadding { Right = padding + 8 }; //padding + chevron width
2017-05-26 18:49:45 +08:00
Add(Chevron = new TextAwesome
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreLeft,
TextSize = 12,
Icon = FontAwesome.fa_chevron_right,
2017-05-27 03:46:09 +08:00
Margin = new MarginPadding { Left = padding },
2017-05-26 18:49:45 +08:00
Alpha = 0f,
});
}
}
}
}