diff --git a/osu.Game/Graphics/Containers/SectionsContainer.cs b/osu.Game/Graphics/Containers/SectionsContainer.cs
index 055e655f6e..1b8e9e1f34 100644
--- a/osu.Game/Graphics/Containers/SectionsContainer.cs
+++ b/osu.Game/Graphics/Containers/SectionsContainer.cs
@@ -2,7 +2,6 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
-using System.Collections.Generic;
using System.Linq;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
@@ -13,11 +12,15 @@ namespace osu.Game.Graphics.Containers
///
/// A container that can scroll to each section inside it.
///
- public class SectionsContainer : Container
+ public class SectionsContainer : Container
+ where T : Drawable
{
private Drawable expandableHeader, fixedHeader, footer, headerBackground;
public readonly ScrollContainer ScrollContainer;
- private readonly Container sectionsContainer, headerBackgroundContainer;
+ private readonly Container headerBackgroundContainer;
+ private readonly FlowContainer sectionsContainer;
+
+ protected override Container Content => sectionsContainer;
public Drawable ExpandableHeader
{
@@ -26,12 +29,11 @@ namespace osu.Game.Graphics.Containers
{
if (value == expandableHeader) return;
- if (expandableHeader != null)
- Remove(expandableHeader);
+ expandableHeader?.Expire();
expandableHeader = value;
if (value == null) return;
- Add(expandableHeader);
+ AddInternal(expandableHeader);
lastKnownScroll = float.NaN;
}
}
@@ -43,12 +45,11 @@ namespace osu.Game.Graphics.Containers
{
if (value == fixedHeader) return;
- if (fixedHeader != null)
- Remove(fixedHeader);
+ fixedHeader?.Expire();
fixedHeader = value;
if (value == null) return;
- Add(fixedHeader);
+ AddInternal(fixedHeader);
lastKnownScroll = float.NaN;
}
}
@@ -88,39 +89,27 @@ namespace osu.Game.Graphics.Containers
}
}
- public Bindable SelectedSection { get; } = new Bindable();
+ public Bindable SelectedSection { get; } = new Bindable();
- protected virtual Container CreateScrollContentContainer()
- => new FillFlowContainer
+ protected virtual FlowContainer CreateScrollContentContainer()
+ => new FillFlowContainer
{
Direction = FillDirection.Vertical,
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
};
- private List sections = new List();
- public IEnumerable Sections
+ public override void Add(T drawable)
{
- get { return sections; }
- set
- {
- foreach (var section in sections)
- sectionsContainer.Remove(section);
-
- sections = value.ToList();
- if (sections.Count == 0) return;
-
- sectionsContainer.Add(sections);
- SelectedSection.Value = sections[0];
- lastKnownScroll = float.NaN;
- }
+ base.Add(drawable);
+ lastKnownScroll = float.NaN;
}
private float headerHeight, footerHeight;
private readonly MarginPadding originalSectionsMargin;
private void updateSectionsMargin()
{
- if (sections.Count == 0) return;
+ if (!Children.Any()) return;
var newMargin = originalSectionsMargin;
newMargin.Top += headerHeight;
@@ -131,14 +120,14 @@ namespace osu.Game.Graphics.Containers
public SectionsContainer()
{
- Add(ScrollContainer = new ScrollContainer()
+ AddInternal(ScrollContainer = new ScrollContainer()
{
RelativeSizeAxes = Axes.Both,
Masking = true,
Children = new Drawable[] { sectionsContainer = CreateScrollContentContainer() },
Depth = float.MaxValue
});
- Add(headerBackgroundContainer = new Container
+ AddInternal(headerBackgroundContainer = new Container
{
RelativeSizeAxes = Axes.X,
Depth = float.MaxValue / 2
@@ -176,10 +165,10 @@ namespace osu.Game.Graphics.Containers
headerBackgroundContainer.Height = (ExpandableHeader?.LayoutSize.Y ?? 0) + (FixedHeader?.LayoutSize.Y ?? 0);
headerBackgroundContainer.Y = ExpandableHeader?.Y ?? 0;
- Drawable bestMatch = null;
+ T bestMatch = null;
float minDiff = float.MaxValue;
- foreach (var section in sections)
+ foreach (var section in Children)
{
float diff = Math.Abs(ScrollContainer.GetChildPosInContent(section) - currentScroll);
if (diff < minDiff)
diff --git a/osu.Game/Overlays/SettingsOverlay.cs b/osu.Game/Overlays/SettingsOverlay.cs
index 88a0e26dde..b229a9dfec 100644
--- a/osu.Game/Overlays/SettingsOverlay.cs
+++ b/osu.Game/Overlays/SettingsOverlay.cs
@@ -83,7 +83,7 @@ namespace osu.Game.Overlays
},
Exit = Hide,
},
- Sections = sections,
+ Children = sections,
Footer = new SettingsFooter()
},
sidebar = new Sidebar
@@ -148,12 +148,12 @@ namespace osu.Game.Overlays
base.OnFocus(state);
}
- private class SettingsSectionsContainer : SectionsContainer
+ private class SettingsSectionsContainer : SectionsContainer
{
- public SearchContainer SearchContainer;
+ public SearchContainer SearchContainer;
- protected override Container CreateScrollContentContainer()
- => SearchContainer = new SearchContainer
+ protected override FlowContainer CreateScrollContentContainer()
+ => SearchContainer = new SearchContainer
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
diff --git a/osu.Game/Users/UserProfile.cs b/osu.Game/Users/UserProfile.cs
index 5d592a613d..27f18a0f14 100644
--- a/osu.Game/Users/UserProfile.cs
+++ b/osu.Game/Users/UserProfile.cs
@@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd .
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
+using System.Linq;
using OpenTK;
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
@@ -51,7 +52,7 @@ namespace osu.Game.Users
Colour = OsuColour.Gray(0.2f)
});
- var sectionsContainer = new SectionsContainer
+ var sectionsContainer = new SectionsContainer
{
RelativeSizeAxes = Axes.Both,
ExpandableHeader = new ProfileHeader(user),
@@ -61,7 +62,7 @@ namespace osu.Game.Users
Colour = OsuColour.Gray(34),
RelativeSizeAxes = Axes.Both
},
- Sections = sections
+ Children = sections
};
Add(sectionsContainer);
@@ -69,7 +70,7 @@ namespace osu.Game.Users
{
if (lastSection != s)
{
- lastSection = s as ProfileSection;
+ lastSection = s;
tabs.Current.Value = lastSection;
}
};
@@ -78,7 +79,9 @@ namespace osu.Game.Users
{
if (lastSection == null)
{
- lastSection = tabs.Current.Value = sections[0];
+ lastSection = sectionsContainer.Children.FirstOrDefault();
+ if (lastSection != null)
+ tabs.Current.Value = lastSection;
return;
}
if (lastSection != s)