mirror of
https://github.com/ppy/osu.git
synced 2025-02-26 15:02:55 +08:00
Refactor code into UserTrackingScrollContainer
This commit is contained in:
parent
668f89d8b2
commit
78c14fd696
@ -95,7 +95,7 @@ namespace osu.Game.Graphics.Containers
|
|||||||
|
|
||||||
protected override Container<T> Content => scrollContentContainer;
|
protected override Container<T> Content => scrollContentContainer;
|
||||||
|
|
||||||
private readonly OsuScrollContainer scrollContainer;
|
private readonly UserTrackingScrollContainer scrollContainer;
|
||||||
private readonly Container headerBackgroundContainer;
|
private readonly Container headerBackgroundContainer;
|
||||||
private readonly MarginPadding originalSectionsMargin;
|
private readonly MarginPadding originalSectionsMargin;
|
||||||
private Drawable expandableHeader, fixedHeader, footer, headerBackground;
|
private Drawable expandableHeader, fixedHeader, footer, headerBackground;
|
||||||
@ -139,7 +139,7 @@ namespace osu.Game.Graphics.Containers
|
|||||||
public void ScrollToTop() => scrollContainer.ScrollTo(0);
|
public void ScrollToTop() => scrollContainer.ScrollTo(0);
|
||||||
|
|
||||||
[NotNull]
|
[NotNull]
|
||||||
protected virtual OsuScrollContainer CreateScrollContainer() => new OsuScrollContainer();
|
protected virtual UserTrackingScrollContainer CreateScrollContainer() => new UserTrackingScrollContainer();
|
||||||
|
|
||||||
[NotNull]
|
[NotNull]
|
||||||
protected virtual FlowContainer<T> CreateScrollContentContainer() =>
|
protected virtual FlowContainer<T> CreateScrollContentContainer() =>
|
||||||
|
49
osu.Game/Graphics/Containers/UserTrackingScrollContainer.cs
Normal file
49
osu.Game/Graphics/Containers/UserTrackingScrollContainer.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
|
||||||
|
namespace osu.Game.Graphics.Containers
|
||||||
|
{
|
||||||
|
public class UserTrackingScrollContainer : UserTrackingScrollContainer<Drawable>
|
||||||
|
{
|
||||||
|
public UserTrackingScrollContainer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserTrackingScrollContainer(Direction direction)
|
||||||
|
: base(direction)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class UserTrackingScrollContainer<T> : OsuScrollContainer<T>
|
||||||
|
where T : Drawable
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the last scroll event was user triggered, directly on the scroll container.
|
||||||
|
/// </summary>
|
||||||
|
public bool UserScrolling { get; private set; }
|
||||||
|
|
||||||
|
public UserTrackingScrollContainer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserTrackingScrollContainer(Direction direction)
|
||||||
|
: base(direction)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnUserScroll(float value, bool animated = true, double? distanceDecay = default)
|
||||||
|
{
|
||||||
|
UserScrolling = true;
|
||||||
|
base.OnUserScroll(value, animated, distanceDecay);
|
||||||
|
}
|
||||||
|
|
||||||
|
public new void ScrollTo(float value, bool animated = true, double? distanceDecay = null)
|
||||||
|
{
|
||||||
|
UserScrolling = false;
|
||||||
|
base.ScrollTo(value, animated, distanceDecay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -17,9 +17,9 @@ using osuTK.Graphics;
|
|||||||
namespace osu.Game.Overlays
|
namespace osu.Game.Overlays
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="OsuScrollContainer"/> which provides <see cref="ScrollToTopButton"/>. Mostly used in <see cref="FullscreenOverlay{T}"/>.
|
/// <see cref="UserTrackingScrollContainer"/> which provides <see cref="ScrollToTopButton"/>. Mostly used in <see cref="FullscreenOverlay{T}"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class OverlayScrollContainer : OsuScrollContainer
|
public class OverlayScrollContainer : UserTrackingScrollContainer
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Scroll position at which the <see cref="ScrollToTopButton"/> will be shown.
|
/// Scroll position at which the <see cref="ScrollToTopButton"/> will be shown.
|
||||||
|
@ -202,7 +202,7 @@ namespace osu.Game.Overlays
|
|||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override OsuScrollContainer CreateScrollContainer() => new OverlayScrollContainer();
|
protected override UserTrackingScrollContainer CreateScrollContainer() => new OverlayScrollContainer();
|
||||||
|
|
||||||
protected override FlowContainer<ProfileSection> CreateScrollContentContainer() => new FillFlowContainer<ProfileSection>
|
protected override FlowContainer<ProfileSection> CreateScrollContentContainer() => new FillFlowContainer<ProfileSection>
|
||||||
{
|
{
|
||||||
|
@ -901,15 +901,10 @@ namespace osu.Game.Screens.Select
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class CarouselScrollContainer : OsuScrollContainer<DrawableCarouselItem>
|
protected class CarouselScrollContainer : UserTrackingScrollContainer<DrawableCarouselItem>
|
||||||
{
|
{
|
||||||
private bool rightMouseScrollBlocked;
|
private bool rightMouseScrollBlocked;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether the last scroll event was user triggered, directly on the scroll container.
|
|
||||||
/// </summary>
|
|
||||||
public bool UserScrolling { get; private set; }
|
|
||||||
|
|
||||||
public CarouselScrollContainer()
|
public CarouselScrollContainer()
|
||||||
{
|
{
|
||||||
// size is determined by the carousel itself, due to not all content necessarily being loaded.
|
// size is determined by the carousel itself, due to not all content necessarily being loaded.
|
||||||
@ -919,19 +914,6 @@ namespace osu.Game.Screens.Select
|
|||||||
Masking = false;
|
Masking = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReSharper disable once OptionalParameterHierarchyMismatch 2020.3 EAP4 bug. (https://youtrack.jetbrains.com/issue/RSRP-481535?p=RIDER-51910)
|
|
||||||
protected override void OnUserScroll(float value, bool animated = true, double? distanceDecay = default)
|
|
||||||
{
|
|
||||||
UserScrolling = true;
|
|
||||||
base.OnUserScroll(value, animated, distanceDecay);
|
|
||||||
}
|
|
||||||
|
|
||||||
public new void ScrollTo(float value, bool animated = true, double? distanceDecay = null)
|
|
||||||
{
|
|
||||||
UserScrolling = false;
|
|
||||||
base.ScrollTo(value, animated, distanceDecay);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool OnMouseDown(MouseDownEvent e)
|
protected override bool OnMouseDown(MouseDownEvent e)
|
||||||
{
|
{
|
||||||
if (e.Button == MouseButton.Right)
|
if (e.Button == MouseButton.Right)
|
||||||
|
Loading…
Reference in New Issue
Block a user