From 9dba363b0888b32bbe155dedb587ed68bec18697 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Jul 2017 17:57:01 +0900 Subject: [PATCH] Use button boundaries to decide when to expand sidebar --- osu.Game/Overlays/Settings/Sidebar.cs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/osu.Game/Overlays/Settings/Sidebar.cs b/osu.Game/Overlays/Settings/Sidebar.cs index d7ad212902..44d296a079 100644 --- a/osu.Game/Overlays/Settings/Sidebar.cs +++ b/osu.Game/Overlays/Settings/Sidebar.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System.Linq; using osu.Framework; using OpenTK; using OpenTK.Graphics; @@ -59,10 +60,18 @@ protected override bool OnHover(InputState state) protected override void OnHoverLost(InputState state) { expandEvent?.Cancel(); + lastHoveredButton = null; State = ExpandedState.Contracted; + base.OnHoverLost(state); } + protected override bool OnMouseMove(InputState state) + { + queueExpandIfHovering(); + return base.OnMouseMove(state); + } + private class SidebarScrollContainer : ScrollContainer { public SidebarScrollContainer() @@ -78,9 +87,6 @@ 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; @@ -97,13 +103,24 @@ public ExpandedState State } } + private Drawable lastHoveredButton; + + private Drawable hoveredButton => content.Children.FirstOrDefault(c => c.IsHovered); + 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 = Scheduler.AddDelayed(() => State = ExpandedState.Expanded, 750); } + + lastHoveredButton = hoveredButton; } }