mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Add ScrollIntoView
method which accepts an offset to allow usage in mod select
This commit is contained in:
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#nullable enable
|
#nullable enable
|
||||||
|
|
||||||
|
using System;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
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)
|
protected override bool OnMouseDown(MouseDownEvent e)
|
||||||
{
|
{
|
||||||
if (shouldPerformRightMouseScroll(e))
|
if (shouldPerformRightMouseScroll(e))
|
||||||
|
@ -161,7 +161,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.X,
|
AutoSizeAxes = Axes.X,
|
||||||
RelativeSizeAxes = Axes.Y,
|
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()
|
protected override void LoadComplete()
|
||||||
|
Reference in New Issue
Block a user