mirror of
https://github.com/ppy/osu.git
synced 2026-05-17 08:42:35 +08:00
Tidy up how SettingsSubsection headings are created
Previously we were always making header content in the base class then overwriting it, which felt ick.
This commit is contained in:
@@ -30,6 +30,8 @@ namespace osu.Game.Overlays.Settings.Sections
|
||||
|
||||
private readonly BindableBool handlerEnabled = new BindableBool();
|
||||
|
||||
private ToggleableHeader header = null!;
|
||||
|
||||
public InputSubsection(InputHandler handler)
|
||||
{
|
||||
this.handler = handler;
|
||||
@@ -37,14 +39,10 @@ namespace osu.Game.Overlays.Settings.Sections
|
||||
FlowContent.AlwaysPresent = true;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
protected override Drawable CreateHeader() => header = new ToggleableHeader(Header, IsToggleable)
|
||||
{
|
||||
HeaderContainer.Child = new ToggleableHeader(Header, IsToggleable)
|
||||
{
|
||||
Current = { BindTarget = handlerEnabled },
|
||||
};
|
||||
}
|
||||
Current = { BindTarget = handlerEnabled },
|
||||
};
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
@@ -58,7 +56,7 @@ namespace osu.Game.Overlays.Settings.Sections
|
||||
{
|
||||
// set negative bottom margin to not have too much vertical gap between disabled input subsections.
|
||||
bool negativeBottomMargin = !handlerEnabled.Value || FlowContent.Count == 0;
|
||||
HeaderContainer.TransformTo(nameof(Margin), new MarginPadding { Bottom = negativeBottomMargin ? -15 : 0 }, 300, Easing.OutQuint);
|
||||
header.TransformTo(nameof(Margin), new MarginPadding { Bottom = negativeBottomMargin ? -VERTICAL_PADDING : 0 }, 300, Easing.OutQuint);
|
||||
|
||||
FlowContent.ClearTransforms();
|
||||
|
||||
@@ -92,6 +90,11 @@ namespace osu.Game.Overlays.Settings.Sections
|
||||
|
||||
public ToggleableHeader(LocalisableString text, bool toggleable)
|
||||
{
|
||||
Padding = SettingsPanel.CONTENT_PADDING;
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
|
||||
this.text = text;
|
||||
this.toggleable = toggleable;
|
||||
}
|
||||
@@ -105,8 +108,6 @@ namespace osu.Game.Overlays.Settings.Sections
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
switchButton = new SwitchButton
|
||||
|
||||
@@ -14,12 +14,12 @@ namespace osu.Game.Overlays.Settings
|
||||
{
|
||||
public abstract partial class SettingsSubsection : FillFlowContainer, IFilterable
|
||||
{
|
||||
public const float VERTICAL_PADDING = (header_height - header_font_size) * 0.5f;
|
||||
|
||||
protected override Container<Drawable> Content => FlowContent;
|
||||
|
||||
protected readonly FillFlowContainer FlowContent;
|
||||
|
||||
protected Container HeaderContainer { get; private set; } = null!;
|
||||
|
||||
protected abstract LocalisableString Header { get; }
|
||||
|
||||
public virtual IEnumerable<LocalisableString> FilterTerms => new[] { Header };
|
||||
@@ -53,25 +53,22 @@ namespace osu.Game.Overlays.Settings
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
AddRangeInternal(new Drawable[]
|
||||
AddRangeInternal(new[]
|
||||
{
|
||||
HeaderContainer = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Padding = SettingsPanel.CONTENT_PADDING,
|
||||
Children = new[]
|
||||
{
|
||||
new OsuSpriteText
|
||||
{
|
||||
Text = Header,
|
||||
Font = OsuFont.GetFont(size: header_font_size),
|
||||
Margin = new MarginPadding { Vertical = (header_height - header_font_size) * 0.5f },
|
||||
},
|
||||
},
|
||||
},
|
||||
CreateHeader(),
|
||||
FlowContent
|
||||
});
|
||||
}
|
||||
|
||||
protected virtual Drawable CreateHeader()
|
||||
{
|
||||
return new OsuSpriteText
|
||||
{
|
||||
Text = Header,
|
||||
Font = OsuFont.GetFont(size: header_font_size),
|
||||
Margin = new MarginPadding { Vertical = VERTICAL_PADDING },
|
||||
Padding = SettingsPanel.CONTENT_PADDING,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user