Merge pull request #9023 from Fukashi13/sections-container-fix

Fix overlay section display highlighting wrong section
This commit is contained in:
Dan Balasescu 2020-05-18 19:49:28 +09:00 committed by GitHub
commit 490b6dbd7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -189,23 +189,18 @@ namespace osu.Game.Graphics.Containers
headerBackgroundContainer.Height = (ExpandableHeader?.LayoutSize.Y ?? 0) + (FixedHeader?.LayoutSize.Y ?? 0); headerBackgroundContainer.Height = (ExpandableHeader?.LayoutSize.Y ?? 0) + (FixedHeader?.LayoutSize.Y ?? 0);
headerBackgroundContainer.Y = ExpandableHeader?.Y ?? 0; headerBackgroundContainer.Y = ExpandableHeader?.Y ?? 0;
T bestMatch = null;
float minDiff = float.MaxValue;
float scrollOffset = FixedHeader?.LayoutSize.Y ?? 0; float scrollOffset = FixedHeader?.LayoutSize.Y ?? 0;
Func<T, float> diff = section => scrollContainer.GetChildPosInContent(section) - currentScroll - scrollOffset;
foreach (var section in Children) if (scrollContainer.IsScrolledToEnd())
{ {
float diff = Math.Abs(scrollContainer.GetChildPosInContent(section) - currentScroll - scrollOffset); SelectedSection.Value = Children.LastOrDefault();
}
if (diff < minDiff) else
{ {
minDiff = diff; SelectedSection.Value = Children.TakeWhile(section => diff(section) <= 0).LastOrDefault()
bestMatch = section; ?? Children.FirstOrDefault();
}
} }
if (bestMatch != null)
SelectedSection.Value = bestMatch;
} }
} }