Simplify selected section resolution

This commit is contained in:
Dean Herbert 2021-01-21 14:44:47 +09:00
parent 6d167b7865
commit e5eec27e95

View File

@ -215,23 +215,16 @@ namespace osu.Game.Graphics.Containers
// 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 sectionOrContent = Math.Min(smallestSectionHeight / 2.0f, scrollContainer.DisplayableContent * 0.05f);
float scrollOffset = (FixedHeader?.LayoutSize.Y ?? 0) + scrollContainer.DisplayableContent * scroll_target_multiplier + sectionOrContent;
Func<T, float> diff = section => scrollContainer.GetChildPosInContent(section) - currentScroll - scrollOffset;
if (Precision.AlmostBigger(0, scrollContainer.Current))
{
SelectedSection.Value = lastClickedSection as T ?? Children.FirstOrDefault();
return;
}
if (Precision.AlmostBigger(scrollContainer.Current, scrollContainer.ScrollableExtent))
{
else if (Precision.AlmostBigger(scrollContainer.Current, scrollContainer.ScrollableExtent))
SelectedSection.Value = lastClickedSection as T ?? Children.LastOrDefault();
return;
}
SelectedSection.Value = Children.TakeWhile(section => diff(section) <= 0).LastOrDefault()
?? Children.FirstOrDefault();
else
SelectedSection.Value = Children.TakeWhile(section => diff(section) <= 0).LastOrDefault() ?? Children.FirstOrDefault();
}
}