1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 22:07:25 +08:00

Add ScrollIntoView method which accepts an offset to allow usage in mod select

This commit is contained in:
Dean Herbert 2022-04-28 20:03:54 +09:00
parent f3a0e2ed55
commit f300b62877
2 changed files with 22 additions and 1 deletions

View File

@ -3,6 +3,7 @@
#nullable enable
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -57,6 +58,26 @@ namespace osu.Game.Graphics.Containers
{
}
/// <summary>
/// Scrolls a <see cref="Drawable"/> into view.
/// </summary>
/// <param name="d">The <see cref="Drawable"/> to scroll into view.</param>
/// <param name="animated">Whether to animate the movement.</param>
/// <param name="extraScroll">An added amount to scroll beyond the requirement to bring the target into view.</param>
public void ScrollIntoView(Drawable d, bool animated = true, float extraScroll = 0)
{
float childPos0 = GetChildPosInContent(d);
float childPos1 = GetChildPosInContent(d, d.DrawSize);
float minPos = Math.Min(childPos0, childPos1);
float maxPos = Math.Max(childPos0, childPos1);
if (minPos < Current || (minPos > Current && d.DrawSize[ScrollDim] > DisplayableContent))
ScrollTo(minPos - extraScroll, animated);
else if (maxPos > Current + DisplayableContent)
ScrollTo(maxPos - DisplayableContent + extraScroll, animated);
}
protected override bool OnMouseDown(MouseDownEvent e)
{
if (shouldPerformRightMouseScroll(e))

View File

@ -161,7 +161,7 @@ namespace osu.Game.Overlays.Mods
{
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
RequestScroll = column => columnScroll.ScrollTo(Math.Clamp(column.DrawPosition.X - 70, 0, columnScroll.ScrollableExtent))
RequestScroll = column => columnScroll.ScrollIntoView(column, extraScroll: 140)
};
protected override void LoadComplete()