From 99ab245cf0686e2fa24fd33553eef4b2015ca2fc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 25 Feb 2026 14:34:00 +0900 Subject: [PATCH] Tidy up how `SettingsSubsection` headings are created Previously we were always making header content in the base class then overwriting it, which felt ick. --- .../Settings/Sections/InputSubsection.cs | 21 ++++++------ .../Overlays/Settings/SettingsSubsection.cs | 33 +++++++++---------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/osu.Game/Overlays/Settings/Sections/InputSubsection.cs b/osu.Game/Overlays/Settings/Sections/InputSubsection.cs index 71d844e8ef..740102765a 100644 --- a/osu.Game/Overlays/Settings/Sections/InputSubsection.cs +++ b/osu.Game/Overlays/Settings/Sections/InputSubsection.cs @@ -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 diff --git a/osu.Game/Overlays/Settings/SettingsSubsection.cs b/osu.Game/Overlays/Settings/SettingsSubsection.cs index 669425b667..8d7d9844a8 100644 --- a/osu.Game/Overlays/Settings/SettingsSubsection.cs +++ b/osu.Game/Overlays/Settings/SettingsSubsection.cs @@ -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 Content => FlowContent; protected readonly FillFlowContainer FlowContent; - protected Container HeaderContainer { get; private set; } = null!; - protected abstract LocalisableString Header { get; } public virtual IEnumerable 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, + }; + } } }