1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 10:42:55 +08:00

Use button boundaries to decide when to expand sidebar

This commit is contained in:
Dean Herbert 2017-07-14 17:57:01 +09:00
parent 3702d4b921
commit 9dba363b08

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
using osu.Framework; using osu.Framework;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
@ -59,10 +60,18 @@ namespace osu.Game.Overlays.Settings
protected override void OnHoverLost(InputState state) protected override void OnHoverLost(InputState state)
{ {
expandEvent?.Cancel(); expandEvent?.Cancel();
lastHoveredButton = null;
State = ExpandedState.Contracted; State = ExpandedState.Contracted;
base.OnHoverLost(state); base.OnHoverLost(state);
} }
protected override bool OnMouseMove(InputState state)
{
queueExpandIfHovering();
return base.OnMouseMove(state);
}
private class SidebarScrollContainer : ScrollContainer private class SidebarScrollContainer : ScrollContainer
{ {
public SidebarScrollContainer() public SidebarScrollContainer()
@ -78,9 +87,6 @@ namespace osu.Game.Overlays.Settings
get { return state; } get { return state; }
set set
{ {
// if the state is changed externally, we want to re-queue a delayed expand.
queueExpandIfHovering();
if (state == value) return; if (state == value) return;
state = value; state = value;
@ -97,13 +103,24 @@ namespace osu.Game.Overlays.Settings
} }
} }
private Drawable lastHoveredButton;
private Drawable hoveredButton => content.Children.FirstOrDefault(c => c.IsHovered);
private void queueExpandIfHovering() private void queueExpandIfHovering()
{ {
if (IsHovered) // only expand when we hover a different button.
if (lastHoveredButton == hoveredButton) return;
if (!IsHovered) return;
if (State != ExpandedState.Expanded)
{ {
expandEvent?.Cancel(); expandEvent?.Cancel();
expandEvent = Scheduler.AddDelayed(() => State = ExpandedState.Expanded, 750); expandEvent = Scheduler.AddDelayed(() => State = ExpandedState.Expanded, 750);
} }
lastHoveredButton = hoveredButton;
} }
} }