1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 06:52:55 +08:00

Merge pull request #9639 from EVAST9919/overlay-header-padding

Make content side padding adjustable for OverlayHeader
This commit is contained in:
Dan Balasescu 2020-07-23 21:28:19 +09:00 committed by GitHub
commit 497d7a6d0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 14 deletions

View File

@ -36,11 +36,11 @@ namespace osu.Game.Tests.Visual.UserInterface
}
});
addHeader("Orange OverlayHeader (no background)", new TestNoBackgroundHeader(), OverlayColourScheme.Orange);
addHeader("Blue OverlayHeader", new TestNoControlHeader(), OverlayColourScheme.Blue);
addHeader("Orange OverlayHeader (no background, 100 padding)", new TestNoBackgroundHeader(), OverlayColourScheme.Orange);
addHeader("Blue OverlayHeader (default 50 padding)", new TestNoControlHeader(), OverlayColourScheme.Blue);
addHeader("Green TabControlOverlayHeader (string) with ruleset selector", new TestStringTabControlHeader(), OverlayColourScheme.Green);
addHeader("Pink TabControlOverlayHeader (enum)", new TestEnumTabControlHeader(), OverlayColourScheme.Pink);
addHeader("Red BreadcrumbControlOverlayHeader (no background)", new TestBreadcrumbControlHeader(), OverlayColourScheme.Red);
addHeader("Pink TabControlOverlayHeader (enum, 30 padding)", new TestEnumTabControlHeader(), OverlayColourScheme.Pink);
addHeader("Red BreadcrumbControlOverlayHeader (no background, 10 padding)", new TestBreadcrumbControlHeader(), OverlayColourScheme.Red);
}
private void addHeader(string name, OverlayHeader header, OverlayColourScheme colourScheme)
@ -86,6 +86,11 @@ namespace osu.Game.Tests.Visual.UserInterface
private class TestNoBackgroundHeader : OverlayHeader
{
protected override OverlayTitle CreateTitle() => new TestTitle();
public TestNoBackgroundHeader()
{
ContentSidePadding = 100;
}
}
private class TestNoControlHeader : OverlayHeader
@ -112,6 +117,11 @@ namespace osu.Game.Tests.Visual.UserInterface
private class TestEnumTabControlHeader : TabControlOverlayHeader<TestEnum>
{
public TestEnumTabControlHeader()
{
ContentSidePadding = 30;
}
protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/rankings");
protected override OverlayTitle CreateTitle() => new TestTitle();
@ -130,6 +140,8 @@ namespace osu.Game.Tests.Visual.UserInterface
public TestBreadcrumbControlHeader()
{
ContentSidePadding = 10;
TabControl.AddItem("tab1");
TabControl.AddItem("tab2");
TabControl.Current.Value = "tab2";

View File

@ -12,9 +12,26 @@ namespace osu.Game.Overlays
{
public abstract class OverlayHeader : Container
{
public const int CONTENT_X_MARGIN = 50;
private float contentSidePadding;
/// <summary>
/// Horizontal padding of the header content.
/// </summary>
protected float ContentSidePadding
{
get => contentSidePadding;
set
{
contentSidePadding = value;
content.Padding = new MarginPadding
{
Horizontal = value
};
}
}
private readonly Box titleBackground;
private readonly Container content;
protected readonly FillFlowContainer HeaderInfo;
@ -50,14 +67,10 @@ namespace osu.Game.Overlays
RelativeSizeAxes = Axes.Both,
Colour = Color4.Gray,
},
new Container
content = new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding
{
Horizontal = CONTENT_X_MARGIN,
},
Children = new[]
{
CreateTitle().With(title =>
@ -79,6 +92,8 @@ namespace osu.Game.Overlays
CreateContent()
}
});
ContentSidePadding = 50;
}
[BackgroundDependencyLoader]

View File

@ -23,6 +23,8 @@ namespace osu.Game.Overlays.Profile
public ProfileHeader()
{
ContentSidePadding = UserProfileOverlay.CONTENT_X_MARGIN;
User.ValueChanged += e => updateDisplay(e.NewValue);
TabControl.AddItem("info");

View File

@ -22,6 +22,7 @@ namespace osu.Game.Overlays
protected OsuTabControl<T> TabControl;
private readonly Box controlBackground;
private readonly Container tabControlContainer;
private readonly BindableWithCurrent<T> current = new BindableWithCurrent<T>();
public Bindable<T> Current
@ -30,6 +31,16 @@ namespace osu.Game.Overlays
set => current.Current = value;
}
protected new float ContentSidePadding
{
get => base.ContentSidePadding;
set
{
base.ContentSidePadding = value;
tabControlContainer.Padding = new MarginPadding { Horizontal = value };
}
}
protected TabControlOverlayHeader()
{
HeaderInfo.Add(new Container
@ -42,11 +53,16 @@ namespace osu.Game.Overlays
{
RelativeSizeAxes = Axes.Both,
},
TabControl = CreateTabControl().With(control =>
tabControlContainer = new Container
{
control.Margin = new MarginPadding { Left = CONTENT_X_MARGIN };
control.Current = Current;
})
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Horizontal = ContentSidePadding },
Child = TabControl = CreateTabControl().With(control =>
{
control.Current = Current;
})
}
}
});
}