mirror of
https://github.com/ppy/osu.git
synced 2025-02-22 01:23:24 +08:00
Fix (and rename) ExpandingBar
This commit is contained in:
parent
555822a68d
commit
92c991494d
@ -4,17 +4,17 @@
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Game.Overlays.Changelog.Components;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
{
|
{
|
||||||
public class TestSceneLineBadge : OsuTestScene
|
public class TestSceneExpandingBar : OsuTestScene
|
||||||
{
|
{
|
||||||
public TestSceneLineBadge()
|
public TestSceneExpandingBar()
|
||||||
{
|
{
|
||||||
Container container;
|
Container container;
|
||||||
LineBadge lineBadge;
|
ExpandingBar expandingBar;
|
||||||
|
|
||||||
Add(container = new Container
|
Add(container = new Container
|
||||||
{
|
{
|
||||||
@ -28,24 +28,23 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
Alpha = 0.5f,
|
Alpha = 0.5f,
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
},
|
},
|
||||||
lineBadge = new LineBadge
|
expandingBar = new ExpandingBar
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
UncollapsedSize = 10,
|
ExpandedSize = 10,
|
||||||
CollapsedSize = 2,
|
CollapsedSize = 2,
|
||||||
Colour = Color4.DeepSkyBlue,
|
Colour = Color4.DeepSkyBlue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
AddStep(@"", () => { });
|
AddStep(@"Collapse", () => expandingBar.Collapse());
|
||||||
AddStep(@"Collapse", () => lineBadge.Collapse());
|
AddStep(@"Uncollapse", () => expandingBar.Expand());
|
||||||
AddStep(@"Uncollapse", () => lineBadge.Uncollapse());
|
|
||||||
AddSliderStep(@"Resize container", 1, 300, 150, value => container.ResizeTo(value));
|
AddSliderStep(@"Resize container", 1, 300, 150, value => container.ResizeTo(value));
|
||||||
AddStep(@"Horizontal", () => lineBadge.IsHorizontal = true);
|
AddStep(@"Horizontal", () => expandingBar.RelativeSizeAxes = Axes.X);
|
||||||
AddStep(@"Anchor top", () => lineBadge.Anchor = Anchor.TopCentre);
|
AddStep(@"Anchor top", () => expandingBar.Anchor = Anchor.TopCentre);
|
||||||
AddStep(@"Vertical", () => lineBadge.IsHorizontal = false);
|
AddStep(@"Vertical", () => expandingBar.RelativeSizeAxes = Axes.Y);
|
||||||
AddStep(@"Anchor left", () => lineBadge.Anchor = Anchor.CentreLeft);
|
AddStep(@"Anchor left", () => expandingBar.Anchor = Anchor.CentreLeft);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
101
osu.Game/Graphics/UserInterface/ExpandingBar.cs
Normal file
101
osu.Game/Graphics/UserInterface/ExpandingBar.cs
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
// 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
|
||||||
|
{
|
||||||
|
private bool isCollapsed;
|
||||||
|
|
||||||
|
public bool IsCollapsed
|
||||||
|
{
|
||||||
|
get => isCollapsed;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value == isCollapsed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
isCollapsed = value;
|
||||||
|
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() => IsCollapsed = true;
|
||||||
|
|
||||||
|
public void Expand() => IsCollapsed = false;
|
||||||
|
|
||||||
|
private void updateState()
|
||||||
|
{
|
||||||
|
float newSize = IsCollapsed ? CollapsedSize : ExpandedSize;
|
||||||
|
Easing easingType = IsCollapsed ? Easing.Out : Easing.OutElastic;
|
||||||
|
|
||||||
|
if (RelativeSizeAxes == Axes.X)
|
||||||
|
this.ResizeHeightTo(newSize, 400, easingType);
|
||||||
|
else
|
||||||
|
this.ResizeWidthTo(newSize, 400, easingType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,86 +0,0 @@
|
|||||||
// 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;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Changelog.Components
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// A simple rounded expandable line. Set its <see cref="Anchor"/>
|
|
||||||
/// property to the center of the edge it's meant stick with. By default,
|
|
||||||
/// takes up the full parent's axis defined by <see cref="IsHorizontal"/>.
|
|
||||||
/// </summary>
|
|
||||||
public class LineBadge : Circle
|
|
||||||
{
|
|
||||||
public float UncollapsedSize;
|
|
||||||
public float CollapsedSize;
|
|
||||||
|
|
||||||
public bool IsCollapsed { get; private set; }
|
|
||||||
private bool isHorizontal;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Automatically sets the RelativeSizeAxes and switches X and Y size components when changed.
|
|
||||||
/// </summary>
|
|
||||||
public bool IsHorizontal
|
|
||||||
{
|
|
||||||
get => isHorizontal;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (value == isHorizontal)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (IsLoaded)
|
|
||||||
{
|
|
||||||
FinishTransforms();
|
|
||||||
var height = Height;
|
|
||||||
var width = Width;
|
|
||||||
RelativeSizeAxes = value ? Axes.X : Axes.Y;
|
|
||||||
Width = height;
|
|
||||||
Height = width;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
RelativeSizeAxes = value ? Axes.X : Axes.Y;
|
|
||||||
|
|
||||||
isHorizontal = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <param name="startCollapsed">Whether to initialize with the
|
|
||||||
/// <see cref="CollapsedSize"/> or the <see cref="UncollapsedSize"/>.</param>
|
|
||||||
public LineBadge(bool startCollapsed = true)
|
|
||||||
{
|
|
||||||
IsCollapsed = startCollapsed;
|
|
||||||
RelativeSizeAxes = Axes.X;
|
|
||||||
isHorizontal = true;
|
|
||||||
Origin = Anchor.Centre;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void LoadComplete()
|
|
||||||
{
|
|
||||||
if (isHorizontal)
|
|
||||||
Height = IsCollapsed ? CollapsedSize : UncollapsedSize;
|
|
||||||
else
|
|
||||||
Width = IsCollapsed ? CollapsedSize : UncollapsedSize;
|
|
||||||
base.LoadComplete();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Collapse(float transitionDuration = 400, Easing easing = Easing.Out)
|
|
||||||
{
|
|
||||||
IsCollapsed = true;
|
|
||||||
if (IsHorizontal)
|
|
||||||
this.ResizeHeightTo(CollapsedSize, transitionDuration, easing);
|
|
||||||
else
|
|
||||||
this.ResizeWidthTo(CollapsedSize, transitionDuration, easing);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Uncollapse(float transitionDuration = 400, Easing easing = Easing.OutElastic)
|
|
||||||
{
|
|
||||||
IsCollapsed = false;
|
|
||||||
if (IsHorizontal)
|
|
||||||
this.ResizeHeightTo(UncollapsedSize, transitionDuration, easing);
|
|
||||||
else
|
|
||||||
this.ResizeWidthTo(UncollapsedSize, transitionDuration, easing);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -12,7 +12,7 @@ using osu.Game.Graphics;
|
|||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using System;
|
using System;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Overlays.Changelog.Components;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Changelog
|
namespace osu.Game.Overlays.Changelog
|
||||||
@ -27,7 +27,7 @@ namespace osu.Game.Overlays.Changelog
|
|||||||
|
|
||||||
private bool isActivated;
|
private bool isActivated;
|
||||||
|
|
||||||
private readonly LineBadge lineBadge;
|
private readonly ExpandingBar expandingBar;
|
||||||
private SampleChannel sampleClick;
|
private SampleChannel sampleClick;
|
||||||
private SampleChannel sampleHover;
|
private SampleChannel sampleHover;
|
||||||
|
|
||||||
@ -71,11 +71,11 @@ namespace osu.Game.Overlays.Changelog
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
lineBadge = new LineBadge(false)
|
expandingBar = new ExpandingBar
|
||||||
{
|
{
|
||||||
Anchor = Anchor.TopCentre,
|
Anchor = Anchor.TopCentre,
|
||||||
Colour = stream.Colour,
|
Colour = stream.Colour,
|
||||||
UncollapsedSize = 4,
|
ExpandedSize = 4,
|
||||||
CollapsedSize = 2,
|
CollapsedSize = 2,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -87,7 +87,7 @@ namespace osu.Game.Overlays.Changelog
|
|||||||
{
|
{
|
||||||
isActivated = true;
|
isActivated = true;
|
||||||
this.FadeIn(transition_duration);
|
this.FadeIn(transition_duration);
|
||||||
lineBadge.Uncollapse();
|
expandingBar.Expand();
|
||||||
if (!withoutFiringUpdates)
|
if (!withoutFiringUpdates)
|
||||||
Selected?.Invoke();
|
Selected?.Invoke();
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ namespace osu.Game.Overlays.Changelog
|
|||||||
if (!IsHovered)
|
if (!IsHovered)
|
||||||
{
|
{
|
||||||
this.FadeTo(0.5f, transition_duration);
|
this.FadeTo(0.5f, transition_duration);
|
||||||
lineBadge.Collapse(200);
|
expandingBar.Collapse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ namespace osu.Game.Overlays.Changelog
|
|||||||
sampleHover?.Play();
|
sampleHover?.Play();
|
||||||
DisableDim();
|
DisableDim();
|
||||||
this.FadeIn(transition_duration);
|
this.FadeIn(transition_duration);
|
||||||
lineBadge.Uncollapse();
|
expandingBar.Expand();
|
||||||
return base.OnHover(e);
|
return base.OnHover(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ namespace osu.Game.Overlays.Changelog
|
|||||||
if (!isActivated)
|
if (!isActivated)
|
||||||
{
|
{
|
||||||
this.FadeTo(0.5f, transition_duration);
|
this.FadeTo(0.5f, transition_duration);
|
||||||
lineBadge.Collapse(200);
|
expandingBar.Collapse();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
EnableDim();
|
EnableDim();
|
||||||
|
@ -67,7 +67,7 @@ namespace osu.Game.Overlays
|
|||||||
private class HeaderTabItem : TabItem<string>
|
private class HeaderTabItem : TabItem<string>
|
||||||
{
|
{
|
||||||
private readonly OsuSpriteText text;
|
private readonly OsuSpriteText text;
|
||||||
private readonly Drawable bar;
|
private readonly ExpandingBar bar;
|
||||||
|
|
||||||
private Color4 accentColour;
|
private Color4 accentColour;
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ namespace osu.Game.Overlays
|
|||||||
AutoSizeAxes = Axes.X;
|
AutoSizeAxes = Axes.X;
|
||||||
RelativeSizeAxes = Axes.Y;
|
RelativeSizeAxes = Axes.Y;
|
||||||
|
|
||||||
Children = new[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
text = new OsuSpriteText
|
text = new OsuSpriteText
|
||||||
{
|
{
|
||||||
@ -102,12 +102,11 @@ namespace osu.Game.Overlays
|
|||||||
Text = value,
|
Text = value,
|
||||||
Font = OsuFont.GetFont()
|
Font = OsuFont.GetFont()
|
||||||
},
|
},
|
||||||
bar = new Circle
|
bar = new ExpandingBar
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
Anchor = Anchor.BottomCentre,
|
||||||
Height = 0,
|
ExpandedSize = 7.5f,
|
||||||
Origin = Anchor.CentreLeft,
|
CollapsedSize = 0
|
||||||
Anchor = Anchor.BottomLeft,
|
|
||||||
},
|
},
|
||||||
new HoverClickSounds()
|
new HoverClickSounds()
|
||||||
};
|
};
|
||||||
@ -138,7 +137,7 @@ namespace osu.Game.Overlays
|
|||||||
if (Active.Value || IsHovered)
|
if (Active.Value || IsHovered)
|
||||||
{
|
{
|
||||||
text.FadeColour(Color4.White, 120, Easing.InQuad);
|
text.FadeColour(Color4.White, 120, Easing.InQuad);
|
||||||
bar.ResizeHeightTo(7.5f, 120, Easing.InQuad);
|
bar.Expand();
|
||||||
|
|
||||||
if (Active.Value)
|
if (Active.Value)
|
||||||
text.Font = text.Font.With(weight: FontWeight.Bold);
|
text.Font = text.Font.With(weight: FontWeight.Bold);
|
||||||
@ -146,7 +145,7 @@ namespace osu.Game.Overlays
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
text.FadeColour(AccentColour, 120, Easing.InQuad);
|
text.FadeColour(AccentColour, 120, Easing.InQuad);
|
||||||
bar.ResizeHeightTo(0, 120, Easing.InQuad);
|
bar.Collapse();
|
||||||
text.Font = text.Font.With(weight: FontWeight.Medium);
|
text.Font = text.Font.With(weight: FontWeight.Medium);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user