osu/osu.Game/Graphics/UserInterface/BreadcrumbControl.cs

85 lines
3.1 KiB
C#
Raw Normal View History

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