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