mirror of
https://github.com/ppy/osu.git
synced 2025-03-01 03:03:21 +08:00
Merge pull request #865 from DrabWeb/breadcrumbs
Breadcrumb Tab Control
This commit is contained in:
commit
cc201c4a9f
39
osu.Desktop.VisualTests/Tests/TestCaseBreadcrumbs.cs
Normal file
39
osu.Desktop.VisualTests/Tests/TestCaseBreadcrumbs.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
|
||||||
|
namespace osu.Desktop.VisualTests.Tests
|
||||||
|
{
|
||||||
|
internal class TestCaseBreadcrumbs : TestCase
|
||||||
|
{
|
||||||
|
public override string Description => @"breadcrumb > control";
|
||||||
|
|
||||||
|
public override void Reset()
|
||||||
|
{
|
||||||
|
base.Reset();
|
||||||
|
|
||||||
|
BreadcrumbControl<BreadcrumbTab> c;
|
||||||
|
Add(c = new BreadcrumbControl<BreadcrumbTab>
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
Width = 0.5f,
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep(@"first", () => c.Current.Value = BreadcrumbTab.Click);
|
||||||
|
AddStep(@"second", () => c.Current.Value = BreadcrumbTab.The);
|
||||||
|
AddStep(@"third", () => c.Current.Value = BreadcrumbTab.Circles);
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum BreadcrumbTab
|
||||||
|
{
|
||||||
|
Click,
|
||||||
|
The,
|
||||||
|
Circles,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -223,6 +223,7 @@
|
|||||||
<Compile Include="Tests\TestCaseDrawableRoom.cs" />
|
<Compile Include="Tests\TestCaseDrawableRoom.cs" />
|
||||||
<Compile Include="Tests\TestCaseUserPanel.cs" />
|
<Compile Include="Tests\TestCaseUserPanel.cs" />
|
||||||
<Compile Include="Tests\TestCaseDirect.cs" />
|
<Compile Include="Tests\TestCaseDirect.cs" />
|
||||||
|
<Compile Include="Tests\TestCaseBreadcrumbs.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
|
84
osu.Game/Graphics/UserInterface/BreadcrumbControl.cs
Normal file
84
osu.Game/Graphics/UserInterface/BreadcrumbControl.cs
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
// 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;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.UserInterface;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace osu.Game.Graphics.UserInterface
|
||||||
|
{
|
||||||
|
public class BreadcrumbControl<T> : OsuTabControl<T>
|
||||||
|
{
|
||||||
|
private const float padding = 10;
|
||||||
|
|
||||||
|
protected override TabItem<T> CreateTabItem(T value) => new BreadcrumbTabItem(value);
|
||||||
|
|
||||||
|
public BreadcrumbControl()
|
||||||
|
{
|
||||||
|
Height = 26;
|
||||||
|
TabContainer.Spacing = new Vector2(padding, 0f);
|
||||||
|
Current.ValueChanged += tab =>
|
||||||
|
{
|
||||||
|
foreach (var t in TabContainer.Children.OfType<BreadcrumbTabItem>())
|
||||||
|
{
|
||||||
|
var tIndex = TabContainer.IndexOf(t);
|
||||||
|
var tabIndex = TabContainer.IndexOf(TabMap[tab]);
|
||||||
|
|
||||||
|
t.State = tIndex < tabIndex ? Visibility.Hidden : Visibility.Visible;
|
||||||
|
t.Chevron.FadeTo(tIndex <= tabIndex ? 0f : 1f, 500, EasingTypes.OutQuint);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private class BreadcrumbTabItem : OsuTabItem, IStateful<Visibility>
|
||||||
|
{
|
||||||
|
public readonly TextAwesome Chevron;
|
||||||
|
|
||||||
|
//don't allow clicking between transitions and don't make the chevron clickable
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public BreadcrumbTabItem(T value) : base(value)
|
||||||
|
{
|
||||||
|
Text.TextSize = 16;
|
||||||
|
Padding = new MarginPadding { Right = padding + 8 }; //padding + chevron width
|
||||||
|
Add(Chevron = new TextAwesome
|
||||||
|
{
|
||||||
|
Anchor = Anchor.CentreRight,
|
||||||
|
Origin = Anchor.CentreLeft,
|
||||||
|
TextSize = 12,
|
||||||
|
Icon = FontAwesome.fa_chevron_right,
|
||||||
|
Margin = new MarginPadding { Left = padding },
|
||||||
|
Alpha = 0f,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -451,6 +451,7 @@
|
|||||||
<Compile Include="Overlays\Direct\SlimEnumDropdown.cs" />
|
<Compile Include="Overlays\Direct\SlimEnumDropdown.cs" />
|
||||||
<Compile Include="Graphics\Containers\ReverseDepthFillFlowContainer.cs" />
|
<Compile Include="Graphics\Containers\ReverseDepthFillFlowContainer.cs" />
|
||||||
<Compile Include="Database\RankStatus.cs" />
|
<Compile Include="Database\RankStatus.cs" />
|
||||||
|
<Compile Include="Graphics\UserInterface\BreadcrumbControl.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\osu-framework\osu.Framework\osu.Framework.csproj">
|
<ProjectReference Include="..\osu-framework\osu.Framework\osu.Framework.csproj">
|
||||||
|
Loading…
Reference in New Issue
Block a user