mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 19:22:54 +08:00
Contract sidebar on click
Also makes queueing of expand more correct.
This commit is contained in:
parent
939e167d6a
commit
2ff92ac25a
@ -1,6 +1,7 @@
|
||||
// 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;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Graphics;
|
||||
@ -12,7 +13,7 @@ using osu.Game.Overlays.Toolbar;
|
||||
|
||||
namespace osu.Game.Overlays.Settings
|
||||
{
|
||||
public class Sidebar : Container
|
||||
public class Sidebar : Container, IStateful<ExpandedState>
|
||||
{
|
||||
private readonly FillFlowContainer content;
|
||||
internal const float DEFAULT_WIDTH = ToolbarButton.WIDTH;
|
||||
@ -47,21 +48,18 @@ namespace osu.Game.Overlays.Settings
|
||||
}
|
||||
|
||||
private ScheduledDelegate expandEvent;
|
||||
private ExpandedState state;
|
||||
|
||||
protected override bool OnHover(InputState state)
|
||||
{
|
||||
expandEvent?.Cancel();
|
||||
expandEvent = Scheduler.AddDelayed(() =>
|
||||
{
|
||||
ResizeTo(new Vector2(EXPANDED_WIDTH, Height), 500, EasingTypes.OutQuint);
|
||||
}, 750);
|
||||
queueExpandIfHovering();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(InputState state)
|
||||
{
|
||||
expandEvent?.Cancel();
|
||||
ResizeTo(new Vector2(DEFAULT_WIDTH, Height), 500, EasingTypes.OutQuint);
|
||||
State = ExpandedState.Contracted;
|
||||
base.OnHoverLost(state);
|
||||
}
|
||||
|
||||
@ -74,5 +72,44 @@ namespace osu.Game.Overlays.Settings
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
}
|
||||
}
|
||||
|
||||
public ExpandedState State
|
||||
{
|
||||
get { return state; }
|
||||
set
|
||||
{
|
||||
// if the state is changed externally, we want to re-queue a delayed expand.
|
||||
queueExpandIfHovering();
|
||||
|
||||
if (state == value) return;
|
||||
|
||||
state = value;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
default:
|
||||
ResizeTo(new Vector2(DEFAULT_WIDTH, Height), 500, EasingTypes.OutQuint);
|
||||
break;
|
||||
case ExpandedState.Expanded:
|
||||
ResizeTo(new Vector2(EXPANDED_WIDTH, Height), 500, EasingTypes.OutQuint);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void queueExpandIfHovering()
|
||||
{
|
||||
if (IsHovered)
|
||||
{
|
||||
expandEvent?.Cancel();
|
||||
expandEvent = Scheduler.AddDelayed(() => State = ExpandedState.Expanded, 750);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum ExpandedState
|
||||
{
|
||||
Contracted,
|
||||
Expanded,
|
||||
}
|
||||
}
|
@ -96,7 +96,11 @@ namespace osu.Game.Overlays
|
||||
new SidebarButton
|
||||
{
|
||||
Section = section,
|
||||
Action = s => sectionsContainer.ScrollTo(s),
|
||||
Action = s =>
|
||||
{
|
||||
sectionsContainer.ScrollTo(s);
|
||||
sidebar.State = ExpandedState.Contracted;
|
||||
},
|
||||
}
|
||||
).ToArray()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user