mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 21:52:55 +08:00
Tidy up SectionsContainer class layout/ordering
This commit is contained in:
parent
4c5d01a611
commit
0be2dc9b2d
@ -17,12 +17,7 @@ namespace osu.Game.Graphics.Containers
|
||||
public class SectionsContainer<T> : Container<T>
|
||||
where T : Drawable
|
||||
{
|
||||
private Drawable expandableHeader, fixedHeader, footer, headerBackground;
|
||||
private readonly OsuScrollContainer scrollContainer;
|
||||
private readonly Container headerBackgroundContainer;
|
||||
private FlowContainer<T> scrollContentContainer;
|
||||
|
||||
protected override Container<T> Content => scrollContentContainer;
|
||||
public Bindable<T> SelectedSection { get; } = new Bindable<T>();
|
||||
|
||||
public Drawable ExpandableHeader
|
||||
{
|
||||
@ -84,6 +79,7 @@ namespace osu.Game.Graphics.Containers
|
||||
|
||||
headerBackgroundContainer.Clear();
|
||||
headerBackground = value;
|
||||
|
||||
if (value == null) return;
|
||||
|
||||
headerBackgroundContainer.Add(headerBackground);
|
||||
@ -92,37 +88,17 @@ namespace osu.Game.Graphics.Containers
|
||||
}
|
||||
}
|
||||
|
||||
public Bindable<T> SelectedSection { get; } = new Bindable<T>();
|
||||
protected override Container<T> Content => scrollContentContainer;
|
||||
|
||||
protected virtual FlowContainer<T> CreateScrollContentContainer()
|
||||
=> new FillFlowContainer<T>
|
||||
{
|
||||
Direction = FillDirection.Vertical,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
};
|
||||
|
||||
public override void Add(T drawable)
|
||||
{
|
||||
base.Add(drawable);
|
||||
lastKnownScroll = float.NaN;
|
||||
headerHeight = float.NaN;
|
||||
footerHeight = float.NaN;
|
||||
}
|
||||
private readonly OsuScrollContainer scrollContainer;
|
||||
private readonly Container headerBackgroundContainer;
|
||||
private readonly MarginPadding originalSectionsMargin;
|
||||
private Drawable expandableHeader, fixedHeader, footer, headerBackground;
|
||||
private FlowContainer<T> scrollContentContainer;
|
||||
|
||||
private float headerHeight, footerHeight;
|
||||
private readonly MarginPadding originalSectionsMargin;
|
||||
|
||||
private void updateSectionsMargin()
|
||||
{
|
||||
if (!Children.Any()) return;
|
||||
|
||||
var newMargin = originalSectionsMargin;
|
||||
newMargin.Top += headerHeight;
|
||||
newMargin.Bottom += footerHeight;
|
||||
|
||||
scrollContentContainer.Margin = newMargin;
|
||||
}
|
||||
private float lastKnownScroll;
|
||||
|
||||
public SectionsContainer()
|
||||
{
|
||||
@ -133,22 +109,41 @@ namespace osu.Game.Graphics.Containers
|
||||
s.RelativeSizeAxes = Axes.Both;
|
||||
s.Masking = true;
|
||||
s.ScrollbarVisible = false;
|
||||
s.Children = new Drawable[] { scrollContentContainer = CreateScrollContentContainer() };
|
||||
s.Child = scrollContentContainer = CreateScrollContentContainer();
|
||||
}),
|
||||
headerBackgroundContainer = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X
|
||||
}
|
||||
});
|
||||
|
||||
originalSectionsMargin = scrollContentContainer.Margin;
|
||||
}
|
||||
|
||||
public override void Add(T drawable)
|
||||
{
|
||||
base.Add(drawable);
|
||||
lastKnownScroll = float.NaN;
|
||||
headerHeight = float.NaN;
|
||||
footerHeight = float.NaN;
|
||||
}
|
||||
|
||||
public void ScrollTo(Drawable section) =>
|
||||
scrollContainer.ScrollTo(scrollContainer.GetChildPosInContent(section) - (FixedHeader?.BoundingBox.Height ?? 0));
|
||||
|
||||
public void ScrollToTop() => scrollContainer.ScrollTo(0);
|
||||
|
||||
[NotNull]
|
||||
protected virtual OsuScrollContainer CreateScrollContainer() => new OsuScrollContainer();
|
||||
|
||||
public void ScrollTo(Drawable section) => scrollContainer.ScrollTo(scrollContainer.GetChildPosInContent(section) - (FixedHeader?.BoundingBox.Height ?? 0));
|
||||
|
||||
public void ScrollToTop() => scrollContainer.ScrollTo(0);
|
||||
[NotNull]
|
||||
protected virtual FlowContainer<T> CreateScrollContentContainer() =>
|
||||
new FillFlowContainer<T>
|
||||
{
|
||||
Direction = FillDirection.Vertical,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
};
|
||||
|
||||
protected override bool OnInvalidate(Invalidation invalidation, InvalidationSource source)
|
||||
{
|
||||
@ -163,8 +158,6 @@ namespace osu.Game.Graphics.Containers
|
||||
return result;
|
||||
}
|
||||
|
||||
private float lastKnownScroll;
|
||||
|
||||
protected override void UpdateAfterChildren()
|
||||
{
|
||||
base.UpdateAfterChildren();
|
||||
@ -215,5 +208,16 @@ namespace osu.Game.Graphics.Containers
|
||||
SelectedSection.Value = bestMatch;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSectionsMargin()
|
||||
{
|
||||
if (!Children.Any()) return;
|
||||
|
||||
var newMargin = originalSectionsMargin;
|
||||
newMargin.Top += headerHeight;
|
||||
newMargin.Bottom += footerHeight;
|
||||
|
||||
scrollContentContainer.Margin = newMargin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user