From 8853ac04d97e2419da6b4f2db2a464d680173d3b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 21 Jan 2021 15:08:36 +0900 Subject: [PATCH] Rename some variable and add xmldoc for scroll centre position --- osu.Game/Graphics/Containers/SectionsContainer.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/osu.Game/Graphics/Containers/SectionsContainer.cs b/osu.Game/Graphics/Containers/SectionsContainer.cs index 87c3007ca4..6ed161fa77 100644 --- a/osu.Game/Graphics/Containers/SectionsContainer.cs +++ b/osu.Game/Graphics/Containers/SectionsContainer.cs @@ -108,7 +108,10 @@ namespace osu.Game.Graphics.Containers private float? lastKnownScroll; - private const float scroll_target_multiplier = 0.2f; + /// + /// The percentage of the container to consider the centre-point for deciding the active section (and scrolling to a requested section). + /// + private const float scroll_y_centre = 0.2f; public SectionsContainer() { @@ -144,7 +147,7 @@ namespace osu.Game.Graphics.Containers public void ScrollTo(Drawable section) { lastClickedSection = section; - scrollContainer.ScrollTo(scrollContainer.GetChildPosInContent(section) - scrollContainer.DisplayableContent * scroll_target_multiplier - (FixedHeader?.BoundingBox.Height ?? 0)); + scrollContainer.ScrollTo(scrollContainer.GetChildPosInContent(section) - scrollContainer.DisplayableContent * scroll_y_centre - (FixedHeader?.BoundingBox.Height ?? 0)); } public void ScrollToTop() => scrollContainer.ScrollTo(0); @@ -217,9 +220,9 @@ namespace osu.Game.Graphics.Containers // scroll offset is our fixed header height if we have it plus 20% of content height // plus 5% to fix floating point errors and to not have a section instantly unselect when scrolling upwards // but the 5% can't be bigger than our smallest section height, otherwise it won't get selected correctly - float scrollIntoSectionAmount = Math.Min(smallestSectionHeight / 2.0f, scrollContainer.DisplayableContent * 0.05f); + float selectionLenienceAboveSection = Math.Min(smallestSectionHeight / 2.0f, scrollContainer.DisplayableContent * 0.05f); - float scrollOffset = fixedHeaderSize + scrollContainer.DisplayableContent * scroll_target_multiplier + scrollIntoSectionAmount; + float scrollCentre = fixedHeaderSize + scrollContainer.DisplayableContent * scroll_y_centre + selectionLenienceAboveSection; if (Precision.AlmostBigger(0, scrollContainer.Current)) SelectedSection.Value = lastClickedSection as T ?? Children.FirstOrDefault(); @@ -228,7 +231,7 @@ namespace osu.Game.Graphics.Containers else { SelectedSection.Value = Children - .TakeWhile(section => scrollContainer.GetChildPosInContent(section) - currentScroll - scrollOffset <= 0) + .TakeWhile(section => scrollContainer.GetChildPosInContent(section) - currentScroll - scrollCentre <= 0) .LastOrDefault() ?? Children.FirstOrDefault(); } }