1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 19:27:24 +08:00

Merge pull request #8740 from EVAST9919/scroll-to-top-overlays

Use OverlayScrollContainer for overlays
This commit is contained in:
Dean Herbert 2020-04-13 20:49:41 +09:00 committed by GitHub
commit 69c371d1f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 56 deletions

View File

@ -3,6 +3,7 @@
using System;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -16,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 readonly FlowContainer<T> scrollContentContainer;
protected override Container<T> Content => scrollContentContainer;
public Bindable<T> SelectedSection { get; } = new Bindable<T>();
public Drawable ExpandableHeader
{
@ -83,6 +79,7 @@ namespace osu.Game.Graphics.Containers
headerBackgroundContainer.Clear();
headerBackground = value;
if (value == null) return;
headerBackgroundContainer.Add(headerBackground);
@ -91,15 +88,37 @@ 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>
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 float lastKnownScroll;
public SectionsContainer()
{
AddRangeInternal(new Drawable[]
{
Direction = FillDirection.Vertical,
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
};
scrollContainer = CreateScrollContainer().With(s =>
{
s.RelativeSizeAxes = Axes.Both;
s.Masking = true;
s.ScrollbarVisible = false;
s.Child = scrollContentContainer = CreateScrollContentContainer();
}),
headerBackgroundContainer = new Container
{
RelativeSizeAxes = Axes.X
}
});
originalSectionsMargin = scrollContentContainer.Margin;
}
public override void Add(T drawable)
{
@ -109,40 +128,23 @@ namespace osu.Game.Graphics.Containers
footerHeight = float.NaN;
}
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;
}
public SectionsContainer()
{
AddInternal(scrollContainer = new OsuScrollContainer
{
RelativeSizeAxes = Axes.Both,
Masking = true,
ScrollbarVisible = false,
Children = new Drawable[] { scrollContentContainer = CreateScrollContentContainer() }
});
AddInternal(headerBackgroundContainer = new Container
{
RelativeSizeAxes = Axes.X
});
originalSectionsMargin = scrollContentContainer.Margin;
}
public void ScrollTo(Drawable section) => scrollContainer.ScrollTo(scrollContainer.GetChildPosInContent(section) - (FixedHeader?.BoundingBox.Height ?? 0));
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();
[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)
{
var result = base.OnInvalidate(invalidation, source);
@ -156,8 +158,6 @@ namespace osu.Game.Graphics.Containers
return result;
}
private float lastKnownScroll;
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
@ -208,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;
}
}
}

View File

@ -54,7 +54,7 @@ namespace osu.Game.Overlays
RelativeSizeAxes = Axes.Both,
Colour = ColourProvider.Background6
},
new BasicScrollContainer
new OverlayScrollContainer
{
RelativeSizeAxes = Axes.Both,
ScrollbarVisible = false,

View File

@ -39,7 +39,7 @@ namespace osu.Game.Overlays
public BeatmapSetOverlay()
: base(OverlayColourScheme.Blue)
{
OsuScrollContainer scroll;
OverlayScrollContainer scroll;
Info info;
CommentsSection comments;
@ -49,7 +49,7 @@ namespace osu.Game.Overlays
{
RelativeSizeAxes = Axes.Both
},
scroll = new OsuScrollContainer
scroll = new OverlayScrollContainer
{
RelativeSizeAxes = Axes.Both,
ScrollbarVisible = false,

View File

@ -50,7 +50,7 @@ namespace osu.Game.Overlays
RelativeSizeAxes = Axes.Both,
Colour = ColourProvider.Background4,
},
new OsuScrollContainer
new OverlayScrollContainer
{
RelativeSizeAxes = Axes.Both,
ScrollbarVisible = false,

View File

@ -8,7 +8,6 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Overlays.News;
namespace osu.Game.Overlays
@ -36,7 +35,7 @@ namespace osu.Game.Overlays
RelativeSizeAxes = Axes.Both,
Colour = colours.PurpleDarkAlternative
},
new OsuScrollContainer
new OverlayScrollContainer
{
RelativeSizeAxes = Axes.Both,
Child = new FillFlowContainer

View File

@ -23,7 +23,7 @@ namespace osu.Game.Overlays
protected Bindable<RankingsScope> Scope => header.Current;
private readonly BasicScrollContainer scrollFlow;
private readonly OverlayScrollContainer scrollFlow;
private readonly Container contentContainer;
private readonly LoadingLayer loading;
private readonly Box background;
@ -44,7 +44,7 @@ namespace osu.Game.Overlays
{
RelativeSizeAxes = Axes.Both
},
scrollFlow = new BasicScrollContainer
scrollFlow = new OverlayScrollContainer
{
RelativeSizeAxes = Axes.Both,
ScrollbarVisible = false,

View File

@ -8,7 +8,6 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor;
namespace osu.Game.Overlays.SearchableList
@ -72,7 +71,7 @@ namespace osu.Game.Overlays.SearchableList
{
RelativeSizeAxes = Axes.Both,
Masking = true,
Child = new OsuScrollContainer
Child = new OverlayScrollContainer
{
RelativeSizeAxes = Axes.Both,
ScrollbarVisible = false,

View File

@ -195,6 +195,8 @@ namespace osu.Game.Overlays
RelativeSizeAxes = Axes.Both;
}
protected override OsuScrollContainer CreateScrollContainer() => new OverlayScrollContainer();
protected override FlowContainer<ProfileSection> CreateScrollContentContainer() => new FillFlowContainer<ProfileSection>
{
Direction = FillDirection.Vertical,