mirror of
https://github.com/ppy/osu.git
synced 2025-02-16 17:43:12 +08:00
Slightly adjust scroll handling and also apply to ModSettingsContainer
This commit is contained in:
parent
a408776734
commit
497e5e3a36
@ -195,63 +195,6 @@ namespace osu.Game.Overlays.Mods
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A scroll container that handles the case of vertically scrolling content inside a larger horizontally scrolling parent container.
|
|
||||||
/// </summary>
|
|
||||||
private class NestedVerticalScrollContainer : OsuScrollContainer
|
|
||||||
{
|
|
||||||
private OsuScrollContainer? parentScrollContainer;
|
|
||||||
|
|
||||||
protected override void LoadComplete()
|
|
||||||
{
|
|
||||||
base.LoadComplete();
|
|
||||||
|
|
||||||
parentScrollContainer = findClosestParent<OsuScrollContainer>();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool OnScroll(ScrollEvent e)
|
|
||||||
{
|
|
||||||
if (parentScrollContainer == null)
|
|
||||||
return base.OnScroll(e);
|
|
||||||
|
|
||||||
bool topRightInView = parentScrollContainer.ScreenSpaceDrawQuad.Contains(ScreenSpaceDrawQuad.TopRight);
|
|
||||||
bool bottomLeftInView = parentScrollContainer.ScreenSpaceDrawQuad.Contains(ScreenSpaceDrawQuad.BottomLeft);
|
|
||||||
|
|
||||||
// If not completely on-screen, handle scroll but also allow parent to scroll at the same time (to hopefully bring our content into full view).
|
|
||||||
if (!topRightInView || !bottomLeftInView)
|
|
||||||
{
|
|
||||||
base.OnScroll(e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool scrollingPastEnd = e.ScrollDelta.Y < 0 && IsScrolledToEnd();
|
|
||||||
bool scrollingPastStart = e.ScrollDelta.Y > 0 && Target <= 0;
|
|
||||||
|
|
||||||
// If at either of our extents, allow the parent scroll to handle as a horizontal scroll to view more content.
|
|
||||||
if (scrollingPastStart || scrollingPastEnd)
|
|
||||||
{
|
|
||||||
base.OnScroll(e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return base.OnScroll(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: remove when https://github.com/ppy/osu-framework/pull/5092 is available.
|
|
||||||
private T? findClosestParent<T>() where T : class, IDrawable
|
|
||||||
{
|
|
||||||
Drawable cursor = this;
|
|
||||||
|
|
||||||
while ((cursor = cursor.Parent) != null)
|
|
||||||
{
|
|
||||||
if (cursor is T match)
|
|
||||||
return match;
|
|
||||||
}
|
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createHeaderText()
|
private void createHeaderText()
|
||||||
{
|
{
|
||||||
IEnumerable<string> headerTextWords = ModType.Humanize(LetterCasing.Title).Split(' ');
|
IEnumerable<string> headerTextWords = ModType.Humanize(LetterCasing.Title).Split(' ');
|
||||||
|
@ -54,6 +54,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
ScrollbarOverlapsContent = false,
|
ScrollbarOverlapsContent = false,
|
||||||
|
ClampExtension = 100,
|
||||||
Child = modSettingsFlow = new FillFlowContainer
|
Child = modSettingsFlow = new FillFlowContainer
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.X,
|
AutoSizeAxes = Axes.X,
|
||||||
@ -157,9 +158,10 @@ namespace osu.Game.Overlays.Mods
|
|||||||
new[] { Empty() },
|
new[] { Empty() },
|
||||||
new Drawable[]
|
new Drawable[]
|
||||||
{
|
{
|
||||||
new OsuScrollContainer(Direction.Vertical)
|
new NestedVerticalScrollContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
ClampExtension = 100,
|
||||||
Child = new FillFlowContainer
|
Child = new FillFlowContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
|
61
osu.Game/Overlays/Mods/NestedVerticalScrollContainer.cs
Normal file
61
osu.Game/Overlays/Mods/NestedVerticalScrollContainer.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Game.Graphics.Containers;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Mods
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A scroll container that handles the case of vertically scrolling content inside a larger horizontally scrolling parent container.
|
||||||
|
/// </summary>
|
||||||
|
public class NestedVerticalScrollContainer : OsuScrollContainer
|
||||||
|
{
|
||||||
|
private OsuScrollContainer? parentScrollContainer;
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
parentScrollContainer = findClosestParent<OsuScrollContainer>();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnScroll(ScrollEvent e)
|
||||||
|
{
|
||||||
|
if (parentScrollContainer == null)
|
||||||
|
return base.OnScroll(e);
|
||||||
|
|
||||||
|
bool topRightInView = parentScrollContainer.ScreenSpaceDrawQuad.Contains(ScreenSpaceDrawQuad.TopRight);
|
||||||
|
bool bottomLeftInView = parentScrollContainer.ScreenSpaceDrawQuad.Contains(ScreenSpaceDrawQuad.BottomLeft);
|
||||||
|
|
||||||
|
// If not completely on-screen, handle scroll but also allow parent to scroll at the same time (to hopefully bring our content into full view).
|
||||||
|
if (!topRightInView || !bottomLeftInView)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
bool scrollingPastEnd = e.ScrollDelta.Y < 0 && IsScrolledToEnd();
|
||||||
|
bool scrollingPastStart = e.ScrollDelta.Y > 0 && Target <= 0;
|
||||||
|
|
||||||
|
// If at either of our extents, delegate scroll to the horizontal parent container.
|
||||||
|
if (scrollingPastStart || scrollingPastEnd)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return base.OnScroll(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: remove when https://github.com/ppy/osu-framework/pull/5092 is available.
|
||||||
|
private T? findClosestParent<T>() where T : class, IDrawable
|
||||||
|
{
|
||||||
|
Drawable cursor = this;
|
||||||
|
|
||||||
|
while ((cursor = cursor.Parent) != null)
|
||||||
|
{
|
||||||
|
if (cursor is T match)
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user