1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 16:42:57 +08:00

Improve nested scroll behaviour

This commit is contained in:
Dean Herbert 2022-04-05 16:40:09 +09:00
parent 23dad7bdc4
commit f156cb797d
2 changed files with 60 additions and 1 deletions

View File

@ -151,9 +151,10 @@ namespace osu.Game.Overlays.Mods
},
new Drawable[]
{
new OsuScrollContainer
new NestedVerticalScrollContainer
{
RelativeSizeAxes = Axes.Both,
ClampExtension = 100,
ScrollbarOverlapsContent = false,
Child = panelFlow = new FillFlowContainer<ModPanel>
{
@ -194,6 +195,63 @@ 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);
// If not on screen, handle scroll but also allow parent to scroll at the same time.
bool topRightOutsideOfView = parentScrollContainer.ScreenSpaceDrawQuad.Contains(ScreenSpaceDrawQuad.TopRight) == false;
bool bottomLeftOutsideOfView = parentScrollContainer.ScreenSpaceDrawQuad.Contains(ScreenSpaceDrawQuad.BottomLeft) == false;
if (topRightOutsideOfView || bottomLeftOutsideOfView)
{
base.OnScroll(e);
return false;
}
bool scrollingPastEnd = e.ScrollDelta.Y < 0 && IsScrolledToEnd();
bool scrollingPastStart = e.ScrollDelta.Y > 0 && Target <= 0;
// Same deal if at one of the two extents of the view.
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()
{
IEnumerable<string> headerTextWords = ModType.Humanize(LetterCasing.Title).Split(' ');

View File

@ -106,6 +106,7 @@ namespace osu.Game.Overlays.Mods
{
RelativeSizeAxes = Axes.Both,
Masking = false,
ClampExtension = 100,
ScrollbarOverlapsContent = false,
Child = columnFlow = new ModColumnContainer
{