mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 06:17:23 +08:00
Make sidebar behaviour feel a bit nicer.
This commit is contained in:
parent
e923da1998
commit
1c47773e0d
@ -22,6 +22,7 @@ using osu.Game.Overlays.Options.General;
|
||||
using osu.Game.Overlays.Options.Graphics;
|
||||
using osu.Game.Overlays.Options.Input;
|
||||
using osu.Game.Overlays.Options.Online;
|
||||
using System;
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
{
|
||||
@ -112,8 +113,7 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
Selected = sections[0] == section,
|
||||
Section = section,
|
||||
Action = () => scrollContainer.ScrollTo(
|
||||
scrollContainer.GetChildYInContent(section) - scrollContainer.DrawSize.Y / 2),
|
||||
Action = () => scrollContainer.ScrollIntoView(section),
|
||||
}
|
||||
).ToArray()
|
||||
}
|
||||
@ -130,26 +130,31 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (scrollContainer.Current != lastKnownScroll)
|
||||
float currentScroll = scrollContainer.Current;
|
||||
if (currentScroll != lastKnownScroll)
|
||||
{
|
||||
lastKnownScroll = scrollContainer.Current;
|
||||
lastKnownScroll = currentScroll;
|
||||
|
||||
for (int i = sections.Length - 1; i >= 0; i--)
|
||||
OptionsSection bestCandidate = null;
|
||||
float bestDistance = float.MaxValue;
|
||||
|
||||
foreach (OptionsSection section in sections)
|
||||
{
|
||||
var section = sections[i];
|
||||
float y = scrollContainer.GetChildYInContent(section) - scrollContainer.Current;
|
||||
if (y <= scrollContainer.DrawSize.Y / 2 + 25)
|
||||
float distance = Math.Abs(scrollContainer.GetChildYInContent(section) - currentScroll);
|
||||
if (distance < bestDistance)
|
||||
{
|
||||
var previous = sidebarButtons.SingleOrDefault(sb => sb.Selected);
|
||||
var next = sidebarButtons.SingleOrDefault(sb => sb.Section == section);
|
||||
if (next != null)
|
||||
{
|
||||
previous.Selected = false;
|
||||
next.Selected = true;
|
||||
}
|
||||
break;
|
||||
bestDistance = distance;
|
||||
bestCandidate = section;
|
||||
}
|
||||
}
|
||||
|
||||
var previous = sidebarButtons.SingleOrDefault(sb => sb.Selected);
|
||||
var next = sidebarButtons.SingleOrDefault(sb => sb.Section == bestCandidate);
|
||||
if (next != null)
|
||||
{
|
||||
previous.Selected = false;
|
||||
next.Selected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user