2019-05-22 07:44:47 +00:00
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A rounded bar which can be expanded or collapsed.
|
|
|
|
|
/// Generally used for tabs or breadcrumbs.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ExpandingBar : Circle
|
|
|
|
|
{
|
2020-03-02 11:16:58 +00:00
|
|
|
|
private bool expanded = true;
|
2019-05-22 07:44:47 +00:00
|
|
|
|
|
2020-03-02 11:16:58 +00:00
|
|
|
|
public bool Expanded
|
2019-05-22 07:44:47 +00:00
|
|
|
|
{
|
2020-03-02 11:16:58 +00:00
|
|
|
|
get => expanded;
|
2019-05-22 07:44:47 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2020-03-02 11:16:58 +00:00
|
|
|
|
if (value == expanded)
|
2019-05-22 07:44:47 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-03-02 11:16:58 +00:00
|
|
|
|
expanded = value;
|
2019-05-22 07:44:47 +00:00
|
|
|
|
updateState();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private float expandedSize = 4;
|
|
|
|
|
|
|
|
|
|
public float ExpandedSize
|
|
|
|
|
{
|
|
|
|
|
get => expandedSize;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == expandedSize)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
expandedSize = value;
|
|
|
|
|
updateState();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private float collapsedSize = 2;
|
|
|
|
|
|
|
|
|
|
public float CollapsedSize
|
|
|
|
|
{
|
|
|
|
|
get => collapsedSize;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == collapsedSize)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
collapsedSize = value;
|
|
|
|
|
updateState();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Axes RelativeSizeAxes
|
|
|
|
|
{
|
|
|
|
|
get => base.RelativeSizeAxes;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
base.RelativeSizeAxes = Axes.None;
|
|
|
|
|
Size = Vector2.Zero;
|
|
|
|
|
|
|
|
|
|
base.RelativeSizeAxes = value;
|
|
|
|
|
updateState();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ExpandingBar()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
updateState();
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-02 11:16:58 +00:00
|
|
|
|
public void Collapse() => Expanded = false;
|
2019-05-22 07:44:47 +00:00
|
|
|
|
|
2020-03-02 11:16:58 +00:00
|
|
|
|
public void Expand() => Expanded = true;
|
2019-05-22 07:44:47 +00:00
|
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
|
{
|
2020-03-02 11:16:58 +00:00
|
|
|
|
float newSize = expanded ? ExpandedSize : CollapsedSize;
|
|
|
|
|
Easing easingType = expanded ? Easing.OutElastic : Easing.Out;
|
2019-05-22 07:44:47 +00:00
|
|
|
|
|
|
|
|
|
if (RelativeSizeAxes == Axes.X)
|
|
|
|
|
this.ResizeHeightTo(newSize, 400, easingType);
|
|
|
|
|
else
|
|
|
|
|
this.ResizeWidthTo(newSize, 400, easingType);
|
2020-03-02 11:16:58 +00:00
|
|
|
|
|
|
|
|
|
this.FadeTo(expanded ? 1 : 0.5f, 100, Easing.OutQuint);
|
2019-05-22 07:44:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|