Use a better method of cancelling user scroll

This commit is contained in:
Dean Herbert
2021-02-02 15:44:03 +09:00
parent 398ab9c2c2
commit bb0753f68d
2 changed files with 10 additions and 4 deletions

View File

@ -25,6 +25,8 @@ namespace osu.Game.Graphics.Containers
/// </summary> /// </summary>
public bool UserScrolling { get; private set; } public bool UserScrolling { get; private set; }
public void CancelUserScroll() => UserScrolling = false;
public UserTrackingScrollContainer() public UserTrackingScrollContainer()
{ {
} }

View File

@ -262,17 +262,21 @@ namespace osu.Game.Overlays.Chat
base.UpdateAfterChildren(); base.UpdateAfterChildren();
// If the user has scrolled to the bottom of the container, we should resume tracking new content. // If the user has scrolled to the bottom of the container, we should resume tracking new content.
bool cancelUserScroll = UserScrolling && IsScrolledToEnd(auto_scroll_leniency); if (UserScrolling && IsScrolledToEnd(auto_scroll_leniency))
CancelUserScroll();
// If the user hasn't overridden our behaviour and there has been new content added to the container, we should update our scroll position to track it. // If the user hasn't overridden our behaviour and there has been new content added to the container, we should update our scroll position to track it.
bool requiresScrollUpdate = !UserScrolling && (lastExtent == null || Precision.AlmostBigger(ScrollableExtent, lastExtent.Value)); bool requiresScrollUpdate = !UserScrolling && (lastExtent == null || Precision.AlmostBigger(ScrollableExtent, lastExtent.Value));
if (cancelUserScroll || requiresScrollUpdate) if (requiresScrollUpdate)
{ {
ScheduleAfterChildren(() => ScheduleAfterChildren(() =>
{
if (!UserScrolling)
{ {
ScrollToEnd(); ScrollToEnd();
lastExtent = ScrollableExtent; lastExtent = ScrollableExtent;
}
}); });
} }
} }