update selected section on children count change

This commit is contained in:
Davran Dilshat 2021-08-23 16:27:29 +01:00
parent 34b51100ff
commit 9a507ed273

View File

@ -202,6 +202,8 @@ namespace osu.Game.Graphics.Containers
}); });
} }
private int lastKnownChildrenCount = 0;
protected override void UpdateAfterChildren() protected override void UpdateAfterChildren()
{ {
base.UpdateAfterChildren(); base.UpdateAfterChildren();
@ -220,10 +222,12 @@ namespace osu.Game.Graphics.Containers
} }
float currentScroll = scrollContainer.Current; float currentScroll = scrollContainer.Current;
var presentChildren = Children.Where(c => c.IsPresent);
if (currentScroll != lastKnownScroll) if (currentScroll != lastKnownScroll || presentChildren.Count() != lastKnownChildrenCount)
{ {
lastKnownScroll = currentScroll; lastKnownScroll = currentScroll;
lastKnownChildrenCount = presentChildren.Count();
// reset last clicked section because user started scrolling themselves // reset last clicked section because user started scrolling themselves
if (scrollContainer.UserScrolling) if (scrollContainer.UserScrolling)
@ -249,8 +253,6 @@ namespace osu.Game.Graphics.Containers
float scrollCentre = fixedHeaderSize + scrollContainer.DisplayableContent * scroll_y_centre + selectionLenienceAboveSection; float scrollCentre = fixedHeaderSize + scrollContainer.DisplayableContent * scroll_y_centre + selectionLenienceAboveSection;
var presentChildren = Children.Where(c => c.IsPresent);
if (lastClickedSection != null) if (lastClickedSection != null)
SelectedSection.Value = lastClickedSection; SelectedSection.Value = lastClickedSection;
else if (Precision.AlmostBigger(0, scrollContainer.Current)) else if (Precision.AlmostBigger(0, scrollContainer.Current))