1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-30 08:42:55 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/ExpandingBar.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

106 lines
2.5 KiB
C#
Raw Normal View History

2019-05-22 15:44:47 +08: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.
2022-06-17 15:37:17 +08:00
#nullable disable
2019-05-22 15:44:47 +08:00
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
{
private bool expanded = true;
2019-05-22 15:44:47 +08:00
public bool Expanded
2019-05-22 15:44:47 +08:00
{
get => expanded;
2019-05-22 15:44:47 +08:00
set
{
if (value == expanded)
2019-05-22 15:44:47 +08:00
return;
expanded = value;
2019-05-22 15:44:47 +08: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();
}
public void Collapse() => Expanded = false;
2019-05-22 15:44:47 +08:00
public void Expand() => Expanded = true;
2019-05-22 15:44:47 +08:00
private void updateState()
{
float newSize = expanded ? ExpandedSize : CollapsedSize;
Easing easingType = expanded ? Easing.OutElastic : Easing.Out;
2019-05-22 15:44:47 +08:00
if (RelativeSizeAxes == Axes.X)
this.ResizeHeightTo(newSize, 400, easingType);
else
this.ResizeWidthTo(newSize, 400, easingType);
this.FadeTo(expanded ? 1 : 0.5f, 100, Easing.OutQuint);
2019-05-22 15:44:47 +08:00
}
}
}