From 818f35c35f00724e30f4dbbd51fc58a98386627d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 15 Oct 2021 21:44:56 +0200 Subject: [PATCH 1/9] Restyle default value indicator --- .../TestSceneRestoreDefaultValueButton.cs | 53 +++++++++++++++ osu.Game/Graphics/OsuColour.cs | 7 ++ .../Overlays/RestoreDefaultValueButton.cs | 66 ++++++++++--------- 3 files changed, 96 insertions(+), 30 deletions(-) create mode 100644 osu.Game.Tests/Visual/Settings/TestSceneRestoreDefaultValueButton.cs diff --git a/osu.Game.Tests/Visual/Settings/TestSceneRestoreDefaultValueButton.cs b/osu.Game.Tests/Visual/Settings/TestSceneRestoreDefaultValueButton.cs new file mode 100644 index 0000000000..0716907315 --- /dev/null +++ b/osu.Game.Tests/Visual/Settings/TestSceneRestoreDefaultValueButton.cs @@ -0,0 +1,53 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; +using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Game.Graphics; +using osu.Game.Overlays; +using osuTK; + +namespace osu.Game.Tests.Visual.Settings +{ + public class TestSceneRestoreDefaultValueButton : OsuTestScene + { + [Resolved] + private OsuColour colours { get; set; } + + [Test] + public void TestBasic() + { + RestoreDefaultValueButton restoreDefaultValueButton = null; + + AddStep("create button", () => Child = new Container + { + RelativeSizeAxes = Axes.Both, + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = colours.GreySeafoam + }, + restoreDefaultValueButton = new RestoreDefaultValueButton + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Current = new BindableBool(), + } + } + }); + AddSliderStep("set scale", 1, 4, 1, scale => + { + if (restoreDefaultValueButton != null) + restoreDefaultValueButton.Scale = new Vector2(scale); + }); + AddToggleStep("toggle default state", state => restoreDefaultValueButton.Current.Value = state); + AddToggleStep("toggle disabled state", state => restoreDefaultValueButton.Current.Disabled = state); + } + } +} diff --git a/osu.Game/Graphics/OsuColour.cs b/osu.Game/Graphics/OsuColour.cs index af2bb26871..40d163635a 100644 --- a/osu.Game/Graphics/OsuColour.cs +++ b/osu.Game/Graphics/OsuColour.cs @@ -235,11 +235,18 @@ namespace osu.Game.Graphics /// public readonly Color4 Blue3 = Color4Extensions.FromHex(@"3399cc"); + public readonly Color4 Lime0 = Color4Extensions.FromHex(@"ccff99"); + /// /// Equivalent to 's . /// public readonly Color4 Lime1 = Color4Extensions.FromHex(@"b2ff66"); + /// + /// Equivalent to 's . + /// + public readonly Color4 Lime3 = Color4Extensions.FromHex(@"7fcc33"); + /// /// Equivalent to 's . /// diff --git a/osu.Game/Overlays/RestoreDefaultValueButton.cs b/osu.Game/Overlays/RestoreDefaultValueButton.cs index 87a294cc10..de600e8172 100644 --- a/osu.Game/Overlays/RestoreDefaultValueButton.cs +++ b/osu.Game/Overlays/RestoreDefaultValueButton.cs @@ -3,10 +3,8 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; -using osuTK.Graphics; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; -using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.UserInterface; @@ -14,6 +12,7 @@ using osu.Framework.Input.Events; using osu.Framework.Localisation; using osu.Game.Graphics; using osu.Game.Graphics.UserInterface; +using osuTK; namespace osu.Game.Overlays { @@ -45,30 +44,21 @@ namespace osu.Game.Overlays } } - private bool hovering; + [Resolved] + private OsuColour colours { get; set; } - public RestoreDefaultValueButton() - { - Height = 1; - - RelativeSizeAxes = Axes.Y; - Width = SettingsPanel.CONTENT_MARGINS; - } + private const float size = 4; [BackgroundDependencyLoader] private void load(OsuColour colour) { - BackgroundColour = colour.Yellow; - Content.Width = 0.33f; - Content.CornerRadius = 3; - Content.EdgeEffect = new EdgeEffectParameters - { - Colour = BackgroundColour.Opacity(0.1f), - Type = EdgeEffectType.Glow, - Radius = 2, - }; + BackgroundColour = colour.Lime1; + Size = new Vector2(3 * size); + + Content.RelativeSizeAxes = Axes.None; + Content.Size = new Vector2(size); + Content.CornerRadius = size / 2; - Padding = new MarginPadding { Vertical = 1.5f }; Alpha = 0f; Action += () => @@ -81,39 +71,55 @@ namespace osu.Game.Overlays protected override void LoadComplete() { base.LoadComplete(); - - // avoid unnecessary transforms on first display. - Alpha = currentAlpha; - Background.Colour = currentColour; + updateState(); + FinishTransforms(true); } public LocalisableString TooltipText => "revert to default"; protected override bool OnHover(HoverEvent e) { - hovering = true; UpdateState(); return false; } protected override void OnHoverLost(HoverLostEvent e) { - hovering = false; UpdateState(); } public void UpdateState() => Scheduler.AddOnce(updateState); - private float currentAlpha => current.IsDefault ? 0f : hovering && !current.Disabled ? 1f : 0.65f; - private ColourInfo currentColour => current.Disabled ? Color4.Gray : BackgroundColour; + private const double fade_duration = 200; private void updateState() { if (current == null) return; - this.FadeTo(currentAlpha, 200, Easing.OutQuint); - Background.FadeColour(currentColour, 200, Easing.OutQuint); + Enabled.Value = !Current.Disabled; + + if (!Current.Disabled) + { + this.FadeTo(Current.IsDefault ? 0 : 1, fade_duration, Easing.OutQuint); + Background.FadeColour(IsHovered ? colours.Lime0 : colours.Lime1, fade_duration, Easing.OutQuint); + Content.TweenEdgeEffectTo(new EdgeEffectParameters + { + Colour = (IsHovered ? colours.Lime1 : colours.Lime3).Opacity(0.4f), + Radius = IsHovered ? 8 : 4, + Type = EdgeEffectType.Glow + }, fade_duration, Easing.OutQuint); + } + else + { + Background.FadeColour(colours.Lime3, fade_duration, Easing.OutQuint); + Content.TweenEdgeEffectTo(new EdgeEffectParameters + { + Colour = colours.Lime3.Opacity(0.4f).Opacity(0.1f), + Radius = 2, + Type = EdgeEffectType.Glow + }, fade_duration, Easing.OutQuint); + } } } } From f422ebb281edd47e30968ba8ec7d38ca390fe382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 15 Oct 2021 22:44:28 +0200 Subject: [PATCH 2/9] Adjust `SettingsItem` to accommodate new default value indicator --- .../Visual/Settings/TestSceneSettingsItem.cs | 45 ++++++++++++-- .../Overlays/Settings/SettingsDropdown.cs | 6 -- osu.Game/Overlays/Settings/SettingsItem.cs | 61 +++++++++++++++---- osu.Game/Overlays/Settings/SettingsSlider.cs | 1 - 4 files changed, 90 insertions(+), 23 deletions(-) diff --git a/osu.Game.Tests/Visual/Settings/TestSceneSettingsItem.cs b/osu.Game.Tests/Visual/Settings/TestSceneSettingsItem.cs index d9cce69ee3..9c3940af4c 100644 --- a/osu.Game.Tests/Visual/Settings/TestSceneSettingsItem.cs +++ b/osu.Game.Tests/Visual/Settings/TestSceneSettingsItem.cs @@ -4,6 +4,7 @@ using System.Linq; using NUnit.Framework; using osu.Framework.Bindables; +using osu.Framework.Graphics.Containers; using osu.Framework.Testing; using osu.Game.Overlays.Settings; using osu.Game.Overlays; @@ -29,9 +30,10 @@ namespace osu.Game.Tests.Visual.Settings Value = "test" } }; - - restoreDefaultValueButton = textBox.ChildrenOfType>().Single(); }); + AddUntilStep("wait for loaded", () => textBox.IsLoaded); + AddStep("retrieve restore default button", () => restoreDefaultValueButton = textBox.ChildrenOfType>().Single()); + AddAssert("restore button hidden", () => restoreDefaultValueButton.Alpha == 0); AddStep("change value from default", () => textBox.Current.Value = "non-default"); @@ -41,6 +43,41 @@ namespace osu.Game.Tests.Visual.Settings AddUntilStep("restore button hidden", () => restoreDefaultValueButton.Alpha == 0); } + [Test] + public void TestSetAndClearLabelText() + { + SettingsTextBox textBox = null; + GridContainer settingsItemGrid = null; + RestoreDefaultValueButton restoreDefaultValueButton = null; + + AddStep("create settings item", () => + { + Child = textBox = new SettingsTextBox + { + Current = new Bindable + { + Default = "test", + Value = "test" + } + }; + }); + AddUntilStep("wait for loaded", () => textBox.IsLoaded); + AddStep("retrieve components", () => + { + settingsItemGrid = textBox.ChildrenOfType().Single(); + restoreDefaultValueButton = textBox.ChildrenOfType>().Single(); + }); + + AddStep("set non-default value", () => restoreDefaultValueButton.Current.Value = "non-default"); + AddAssert("default value button next to control", () => settingsItemGrid.Content[1][0] == restoreDefaultValueButton); + + AddStep("set label", () => textBox.LabelText = "label text"); + AddAssert("default value button next to label", () => settingsItemGrid.Content[0][0] == restoreDefaultValueButton); + + AddStep("clear label", () => textBox.LabelText = default); + AddAssert("default value button next to control", () => settingsItemGrid.Content[1][0] == restoreDefaultValueButton); + } + /// /// Ensures that the reset to default button uses the correct implementation of IsDefault to determine whether it should be shown or not. /// Values have been chosen so that after being set, Value != Default (but they are close enough that the difference is negligible compared to Precision). @@ -64,9 +101,9 @@ namespace osu.Game.Tests.Visual.Settings Precision = 0.1f, } }; - - restoreDefaultValueButton = sliderBar.ChildrenOfType>().Single(); }); + AddUntilStep("wait for loaded", () => sliderBar.IsLoaded); + AddStep("retrieve restore default button", () => restoreDefaultValueButton = sliderBar.ChildrenOfType>().Single()); AddAssert("restore button hidden", () => restoreDefaultValueButton.Alpha == 0); diff --git a/osu.Game/Overlays/Settings/SettingsDropdown.cs b/osu.Game/Overlays/Settings/SettingsDropdown.cs index a281d03ee7..1e90222d28 100644 --- a/osu.Game/Overlays/Settings/SettingsDropdown.cs +++ b/osu.Game/Overlays/Settings/SettingsDropdown.cs @@ -6,7 +6,6 @@ using System.Linq; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Game.Graphics.UserInterface; -using osuTK; namespace osu.Game.Overlays.Settings { @@ -28,11 +27,6 @@ namespace osu.Game.Overlays.Settings public override IEnumerable FilterTerms => base.FilterTerms.Concat(Control.Items.Select(i => i.ToString())); - public SettingsDropdown() - { - FlowContent.Spacing = new Vector2(0, 10); - } - protected sealed override Drawable CreateControl() => CreateDropdown(); protected virtual OsuDropdown CreateDropdown() => new DropdownControl(); diff --git a/osu.Game/Overlays/Settings/SettingsItem.cs b/osu.Game/Overlays/Settings/SettingsItem.cs index 5282217013..7895f6386b 100644 --- a/osu.Game/Overlays/Settings/SettingsItem.cs +++ b/osu.Game/Overlays/Settings/SettingsItem.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -14,6 +15,7 @@ using osu.Framework.Localisation; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Containers; +using osuTK; namespace osu.Game.Overlays.Settings { @@ -30,6 +32,10 @@ namespace osu.Game.Overlays.Settings protected readonly FillFlowContainer FlowContent; private SpriteText labelText; + private readonly GridContainer gridContainer; + + [CanBeNull] + private RestoreDefaultValueButton defaultValueButton; private OsuTextFlowContainer warningText; @@ -48,12 +54,13 @@ namespace osu.Game.Overlays.Settings if (labelText == null) { // construct lazily for cases where the label is not needed (may be provided by the Control). - FlowContent.Insert(-1, labelText = new OsuSpriteText()); + gridContainer.Content[0][1] = labelText = new OsuSpriteText(); updateDisabled(); } labelText.Text = value; + updateLayout(); } } @@ -106,18 +113,33 @@ namespace osu.Game.Overlays.Settings AutoSizeAxes = Axes.Y; Padding = new MarginPadding { Right = SettingsPanel.CONTENT_MARGINS }; - InternalChildren = new Drawable[] + FlowContent = new FillFlowContainer { - FlowContent = new FillFlowContainer + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Spacing = new Vector2(0, 10), + Child = Control = CreateControl(), + }; + + InternalChild = gridContainer = new GridContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + RowDimensions = new[] { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Padding = new MarginPadding { Left = SettingsPanel.CONTENT_MARGINS }, - Children = new[] - { - Control = CreateControl(), - }, + new Dimension(GridSizeMode.AutoSize), + new Dimension(GridSizeMode.AutoSize) }, + ColumnDimensions = new[] + { + new Dimension(GridSizeMode.Absolute, SettingsPanel.CONTENT_MARGINS), + new Dimension() + }, + Content = new[] + { + new Drawable[2], + new Drawable[] { null, FlowContent } + } }; // IMPORTANT: all bindable logic is in constructor intentionally to support "CreateSettingsControls" being used in a context it is @@ -135,13 +157,28 @@ namespace osu.Game.Overlays.Settings // intentionally done before LoadComplete to avoid overhead. if (ShowsDefaultIndicator) { - AddInternal(new RestoreDefaultValueButton + defaultValueButton = new RestoreDefaultValueButton { Current = controlWithCurrent.Current, - }); + Anchor = Anchor.Centre, + Origin = Anchor.Centre + }; + updateLayout(); } } + private void updateLayout() + { + bool hasLabel = !string.IsNullOrEmpty(labelText?.Text.ToString()); + + gridContainer.Content[0][0] = null; + gridContainer.Content[1][0] = null; + + gridContainer.Content[hasLabel ? 0 : 1][0] = defaultValueButton; + + FlowContent.Margin = new MarginPadding { Top = hasLabel ? 10 : 0 }; + } + private void updateDisabled() { if (labelText != null) diff --git a/osu.Game/Overlays/Settings/SettingsSlider.cs b/osu.Game/Overlays/Settings/SettingsSlider.cs index bb9c0dd4d7..b95b0af11c 100644 --- a/osu.Game/Overlays/Settings/SettingsSlider.cs +++ b/osu.Game/Overlays/Settings/SettingsSlider.cs @@ -19,7 +19,6 @@ namespace osu.Game.Overlays.Settings { protected override Drawable CreateControl() => new TSlider { - Margin = new MarginPadding { Vertical = 10 }, RelativeSizeAxes = Axes.X }; From 552fc1dc8af353a6a9fdc61cf8a732789f8cc6bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 15 Oct 2021 23:15:28 +0200 Subject: [PATCH 3/9] Adjust key binding rows to accommodate new default value indicator --- .../Settings/Sections/Input/KeyBindingRow.cs | 110 ++++++++++-------- 1 file changed, 64 insertions(+), 46 deletions(-) diff --git a/osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs b/osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs index da789db79a..c2667fbdac 100644 --- a/osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs +++ b/osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs @@ -82,64 +82,82 @@ namespace osu.Game.Overlays.Settings.Sections.Input { RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; - Padding = new MarginPadding { Horizontal = SettingsPanel.CONTENT_MARGINS }; - InternalChildren = new Drawable[] + InternalChild = new GridContainer { - new RestoreDefaultValueButton + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + ColumnDimensions = new[] { - Current = isDefault, - Action = RestoreDefaults, - Origin = Anchor.TopRight, + new Dimension(GridSizeMode.Absolute, SettingsPanel.CONTENT_MARGINS), + new Dimension(), + new Dimension(GridSizeMode.Absolute, SettingsPanel.CONTENT_MARGINS), }, - content = new Container + RowDimensions = new[] { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Masking = true, - CornerRadius = padding, - EdgeEffect = new EdgeEffectParameters + new Dimension(GridSizeMode.AutoSize) + }, + Content = new[] + { + new Drawable[] { - Radius = 2, - Colour = colourProvider.Highlight1.Opacity(0), - Type = EdgeEffectType.Shadow, - Hollow = true, - }, - Children = new Drawable[] - { - new Box + new RestoreDefaultValueButton { - RelativeSizeAxes = Axes.Both, - Colour = colourProvider.Background5, + Current = isDefault, + Action = RestoreDefaults, + Anchor = Anchor.Centre, + Origin = Anchor.Centre }, - text = new OsuSpriteText + content = new Container { - Text = action.GetLocalisableDescription(), - Margin = new MarginPadding(1.5f * padding), - }, - buttons = new FillFlowContainer - { - AutoSizeAxes = Axes.Both, - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight - }, - cancelAndClearButtons = new FillFlowContainer - { - AutoSizeAxes = Axes.Both, - Padding = new MarginPadding(padding) { Top = height + padding * 2 }, - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, - Alpha = 0, - Spacing = new Vector2(5), + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Masking = true, + CornerRadius = padding, + EdgeEffect = new EdgeEffectParameters + { + Radius = 2, + Colour = colourProvider.Highlight1.Opacity(0), + Type = EdgeEffectType.Shadow, + Hollow = true, + }, Children = new Drawable[] { - new CancelButton { Action = finalise }, - new ClearButton { Action = clear }, - }, - } + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = colourProvider.Background5, + }, + text = new OsuSpriteText + { + Text = action.GetLocalisableDescription(), + Margin = new MarginPadding(1.5f * padding), + }, + buttons = new FillFlowContainer + { + AutoSizeAxes = Axes.Both, + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight + }, + cancelAndClearButtons = new FillFlowContainer + { + AutoSizeAxes = Axes.Both, + Padding = new MarginPadding(padding) { Top = height + padding * 2 }, + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight, + Alpha = 0, + Spacing = new Vector2(5), + Children = new Drawable[] + { + new CancelButton { Action = finalise }, + new ClearButton { Action = clear }, + }, + } + } + }, + new HoverClickSounds() } - }, - new HoverClickSounds() + } }; foreach (var b in bindings) From 2a41e8bd1fd2d5b87922f167e02302d090b4fcf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 15 Oct 2021 23:24:53 +0200 Subject: [PATCH 4/9] Remove unneeded extra padding from settings number box --- osu.Game/Overlays/Settings/SettingsNumberBox.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Overlays/Settings/SettingsNumberBox.cs b/osu.Game/Overlays/Settings/SettingsNumberBox.cs index d36aa2bfc2..aca7a210b3 100644 --- a/osu.Game/Overlays/Settings/SettingsNumberBox.cs +++ b/osu.Game/Overlays/Settings/SettingsNumberBox.cs @@ -13,7 +13,6 @@ namespace osu.Game.Overlays.Settings protected override Drawable CreateControl() => new NumberControl { RelativeSizeAxes = Axes.X, - Margin = new MarginPadding { Top = 5 } }; private sealed class NumberControl : CompositeDrawable, IHasCurrentValue From 50bde0fe381c6c1d4f160845935e05ea1d2a8c24 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 18 Oct 2021 13:53:27 +0900 Subject: [PATCH 5/9] Refactor test to better keep existing toggle values I also changed the type of the button to `float` because it was mentally hard to parse a default button that is tracking a `bool` state. Probably not what we want for a test like this. --- .../TestSceneRestoreDefaultValueButton.cs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/Settings/TestSceneRestoreDefaultValueButton.cs b/osu.Game.Tests/Visual/Settings/TestSceneRestoreDefaultValueButton.cs index 0716907315..3eb7a77600 100644 --- a/osu.Game.Tests/Visual/Settings/TestSceneRestoreDefaultValueButton.cs +++ b/osu.Game.Tests/Visual/Settings/TestSceneRestoreDefaultValueButton.cs @@ -18,10 +18,18 @@ namespace osu.Game.Tests.Visual.Settings [Resolved] private OsuColour colours { get; set; } + private float scale = 1; + + private readonly Bindable current = new Bindable + { + Default = default, + Value = 1, + }; + [Test] public void TestBasic() { - RestoreDefaultValueButton restoreDefaultValueButton = null; + RestoreDefaultValueButton restoreDefaultValueButton = null; AddStep("create button", () => Child = new Container { @@ -33,21 +41,23 @@ namespace osu.Game.Tests.Visual.Settings RelativeSizeAxes = Axes.Both, Colour = colours.GreySeafoam }, - restoreDefaultValueButton = new RestoreDefaultValueButton + restoreDefaultValueButton = new RestoreDefaultValueButton { Anchor = Anchor.Centre, Origin = Anchor.Centre, - Current = new BindableBool(), + Scale = new Vector2(scale), + Current = current, } } }); AddSliderStep("set scale", 1, 4, 1, scale => { + this.scale = scale; if (restoreDefaultValueButton != null) restoreDefaultValueButton.Scale = new Vector2(scale); }); - AddToggleStep("toggle default state", state => restoreDefaultValueButton.Current.Value = state); - AddToggleStep("toggle disabled state", state => restoreDefaultValueButton.Current.Disabled = state); + AddToggleStep("toggle default state", state => current.Value = state ? default : 1); + AddToggleStep("toggle disabled state", state => current.Disabled = state); } } } From 830f49bca693c1d6c774dd4237cdba58bb337081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 18 Oct 2021 19:43:48 +0200 Subject: [PATCH 6/9] Remove doubled-up opacity specification --- osu.Game/Overlays/RestoreDefaultValueButton.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/RestoreDefaultValueButton.cs b/osu.Game/Overlays/RestoreDefaultValueButton.cs index de600e8172..afc4146199 100644 --- a/osu.Game/Overlays/RestoreDefaultValueButton.cs +++ b/osu.Game/Overlays/RestoreDefaultValueButton.cs @@ -115,7 +115,7 @@ namespace osu.Game.Overlays Background.FadeColour(colours.Lime3, fade_duration, Easing.OutQuint); Content.TweenEdgeEffectTo(new EdgeEffectParameters { - Colour = colours.Lime3.Opacity(0.4f).Opacity(0.1f), + Colour = colours.Lime3.Opacity(0.1f), Radius = 2, Type = EdgeEffectType.Glow }, fade_duration, Easing.OutQuint); From 6c3637a62a993d4cbcfe41eee99cd28f89c99929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 18 Oct 2021 20:36:47 +0200 Subject: [PATCH 7/9] Remove grid usage in `KeyBindingRow` --- .../Settings/Sections/Input/KeyBindingRow.cs | 47 +++++++++---------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs b/osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs index c2667fbdac..f44f02d0ed 100644 --- a/osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs +++ b/osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs @@ -82,32 +82,29 @@ namespace osu.Game.Overlays.Settings.Sections.Input { RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; + Padding = new MarginPadding { Right = SettingsPanel.CONTENT_MARGINS }; - InternalChild = new GridContainer + InternalChildren = new Drawable[] { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - ColumnDimensions = new[] + new Container { - new Dimension(GridSizeMode.Absolute, SettingsPanel.CONTENT_MARGINS), - new Dimension(), - new Dimension(GridSizeMode.Absolute, SettingsPanel.CONTENT_MARGINS), - }, - RowDimensions = new[] - { - new Dimension(GridSizeMode.AutoSize) - }, - Content = new[] - { - new Drawable[] + RelativeSizeAxes = Axes.Y, + Width = SettingsPanel.CONTENT_MARGINS, + Child = new RestoreDefaultValueButton + { + Current = isDefault, + Action = RestoreDefaults, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + } + }, + new Container + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Padding = new MarginPadding { Left = SettingsPanel.CONTENT_MARGINS }, + Children = new Drawable[] { - new RestoreDefaultValueButton - { - Current = isDefault, - Action = RestoreDefaults, - Anchor = Anchor.Centre, - Origin = Anchor.Centre - }, content = new Container { RelativeSizeAxes = Axes.X, @@ -154,10 +151,10 @@ namespace osu.Game.Overlays.Settings.Sections.Input }, } } - }, - new HoverClickSounds() + } } - } + }, + new HoverClickSounds() }; foreach (var b in bindings) From 88a1b31fae9538a0e38ffc3aef9e9167e90a3120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 18 Oct 2021 21:01:43 +0200 Subject: [PATCH 8/9] Remove grid usage in `SettingsItem` --- .../Visual/Settings/TestSceneSettingsItem.cs | 21 +++++--- osu.Game/Overlays/Settings/SettingsItem.cs | 54 ++++++------------- osu.Game/Overlays/Settings/SettingsTextBox.cs | 1 - 3 files changed, 32 insertions(+), 44 deletions(-) diff --git a/osu.Game.Tests/Visual/Settings/TestSceneSettingsItem.cs b/osu.Game.Tests/Visual/Settings/TestSceneSettingsItem.cs index 9c3940af4c..83265e13ad 100644 --- a/osu.Game.Tests/Visual/Settings/TestSceneSettingsItem.cs +++ b/osu.Game.Tests/Visual/Settings/TestSceneSettingsItem.cs @@ -4,8 +4,10 @@ using System.Linq; using NUnit.Framework; using osu.Framework.Bindables; -using osu.Framework.Graphics.Containers; using osu.Framework.Testing; +using osu.Framework.Utils; +using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; using osu.Game.Overlays.Settings; using osu.Game.Overlays; @@ -47,8 +49,8 @@ namespace osu.Game.Tests.Visual.Settings public void TestSetAndClearLabelText() { SettingsTextBox textBox = null; - GridContainer settingsItemGrid = null; RestoreDefaultValueButton restoreDefaultValueButton = null; + OsuTextBox control = null; AddStep("create settings item", () => { @@ -64,18 +66,25 @@ namespace osu.Game.Tests.Visual.Settings AddUntilStep("wait for loaded", () => textBox.IsLoaded); AddStep("retrieve components", () => { - settingsItemGrid = textBox.ChildrenOfType().Single(); restoreDefaultValueButton = textBox.ChildrenOfType>().Single(); + control = textBox.ChildrenOfType().Single(); }); AddStep("set non-default value", () => restoreDefaultValueButton.Current.Value = "non-default"); - AddAssert("default value button next to control", () => settingsItemGrid.Content[1][0] == restoreDefaultValueButton); + AddAssert("default value button centre aligned to control size", () => Precision.AlmostEquals(restoreDefaultValueButton.Parent.DrawHeight, control.DrawHeight, 1)); AddStep("set label", () => textBox.LabelText = "label text"); - AddAssert("default value button next to label", () => settingsItemGrid.Content[0][0] == restoreDefaultValueButton); + AddAssert("default value button centre aligned to label size", () => + { + var label = textBox.ChildrenOfType().Single(spriteText => spriteText.Text == "label text"); + return Precision.AlmostEquals(restoreDefaultValueButton.Parent.DrawHeight, label.DrawHeight, 1); + }); AddStep("clear label", () => textBox.LabelText = default); - AddAssert("default value button next to control", () => settingsItemGrid.Content[1][0] == restoreDefaultValueButton); + AddAssert("default value button centre aligned to control size", () => Precision.AlmostEquals(restoreDefaultValueButton.Parent.DrawHeight, control.DrawHeight, 1)); + + AddStep("set warning text", () => textBox.WarningText = "This is some very important warning text! Hopefully it doesn't break the alignment of the default value indicator..."); + AddAssert("default value button centre aligned to control size", () => Precision.AlmostEquals(restoreDefaultValueButton.Parent.DrawHeight, control.DrawHeight, 1)); } /// diff --git a/osu.Game/Overlays/Settings/SettingsItem.cs b/osu.Game/Overlays/Settings/SettingsItem.cs index 7895f6386b..91998f07d8 100644 --- a/osu.Game/Overlays/Settings/SettingsItem.cs +++ b/osu.Game/Overlays/Settings/SettingsItem.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -32,14 +31,11 @@ namespace osu.Game.Overlays.Settings protected readonly FillFlowContainer FlowContent; private SpriteText labelText; - private readonly GridContainer gridContainer; - - [CanBeNull] - private RestoreDefaultValueButton defaultValueButton; private OsuTextFlowContainer warningText; public bool ShowsDefaultIndicator = true; + private readonly Container defaultValueIndicatorContainer; public LocalisableString TooltipText { get; set; } @@ -54,7 +50,7 @@ namespace osu.Game.Overlays.Settings if (labelText == null) { // construct lazily for cases where the label is not needed (may be provided by the Control). - gridContainer.Content[0][1] = labelText = new OsuSpriteText(); + FlowContent.Insert(-1, labelText = new OsuSpriteText()); updateDisabled(); } @@ -113,32 +109,19 @@ namespace osu.Game.Overlays.Settings AutoSizeAxes = Axes.Y; Padding = new MarginPadding { Right = SettingsPanel.CONTENT_MARGINS }; - FlowContent = new FillFlowContainer + InternalChildren = new Drawable[] { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Spacing = new Vector2(0, 10), - Child = Control = CreateControl(), - }; - - InternalChild = gridContainer = new GridContainer - { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - RowDimensions = new[] + defaultValueIndicatorContainer = new Container { - new Dimension(GridSizeMode.AutoSize), - new Dimension(GridSizeMode.AutoSize) + Width = SettingsPanel.CONTENT_MARGINS, }, - ColumnDimensions = new[] + FlowContent = new FillFlowContainer { - new Dimension(GridSizeMode.Absolute, SettingsPanel.CONTENT_MARGINS), - new Dimension() - }, - Content = new[] - { - new Drawable[2], - new Drawable[] { null, FlowContent } + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Padding = new MarginPadding { Left = SettingsPanel.CONTENT_MARGINS }, + Spacing = new Vector2(0, 10), + Child = Control = CreateControl(), } }; @@ -157,26 +140,23 @@ namespace osu.Game.Overlays.Settings // intentionally done before LoadComplete to avoid overhead. if (ShowsDefaultIndicator) { - defaultValueButton = new RestoreDefaultValueButton + defaultValueIndicatorContainer.Add(new RestoreDefaultValueButton { Current = controlWithCurrent.Current, Anchor = Anchor.Centre, Origin = Anchor.Centre - }; + }); updateLayout(); } } private void updateLayout() { - bool hasLabel = !string.IsNullOrEmpty(labelText?.Text.ToString()); + bool hasLabel = labelText != null && !string.IsNullOrEmpty(labelText.Text.ToString()); - gridContainer.Content[0][0] = null; - gridContainer.Content[1][0] = null; - - gridContainer.Content[hasLabel ? 0 : 1][0] = defaultValueButton; - - FlowContent.Margin = new MarginPadding { Top = hasLabel ? 10 : 0 }; + // if the settings item is providing a label, the default value indicator should be centred vertically to the left of the label. + // otherwise, it should be centred vertically to the left of the main control of the settings item. + defaultValueIndicatorContainer.Height = hasLabel ? labelText.DrawHeight : Control.DrawHeight; } private void updateDisabled() diff --git a/osu.Game/Overlays/Settings/SettingsTextBox.cs b/osu.Game/Overlays/Settings/SettingsTextBox.cs index 68562802cf..a724003183 100644 --- a/osu.Game/Overlays/Settings/SettingsTextBox.cs +++ b/osu.Game/Overlays/Settings/SettingsTextBox.cs @@ -11,7 +11,6 @@ namespace osu.Game.Overlays.Settings { protected override Drawable CreateControl() => new OutlinedTextBox { - Margin = new MarginPadding { Top = 5 }, RelativeSizeAxes = Axes.X, CommitOnFocusLost = true }; From 6d9d85685f73cadaf2619c43af3ff33da6e0a2cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 18 Oct 2021 23:30:38 +0200 Subject: [PATCH 9/9] Fix settings item having zero height --- osu.Game/Overlays/Settings/SettingsItem.cs | 11 ++++++++--- .../Screens/Play/PlayerSettings/PlayerSliderBar.cs | 1 - 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/osu.Game/Overlays/Settings/SettingsItem.cs b/osu.Game/Overlays/Settings/SettingsItem.cs index 91998f07d8..b593dea576 100644 --- a/osu.Game/Overlays/Settings/SettingsItem.cs +++ b/osu.Game/Overlays/Settings/SettingsItem.cs @@ -115,13 +115,18 @@ namespace osu.Game.Overlays.Settings { Width = SettingsPanel.CONTENT_MARGINS, }, - FlowContent = new FillFlowContainer + new Container { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, Padding = new MarginPadding { Left = SettingsPanel.CONTENT_MARGINS }, - Spacing = new Vector2(0, 10), - Child = Control = CreateControl(), + Child = FlowContent = new FillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Spacing = new Vector2(0, 10), + Child = Control = CreateControl(), + } } }; diff --git a/osu.Game/Screens/Play/PlayerSettings/PlayerSliderBar.cs b/osu.Game/Screens/Play/PlayerSettings/PlayerSliderBar.cs index 216e46d429..9903a74043 100644 --- a/osu.Game/Screens/Play/PlayerSettings/PlayerSliderBar.cs +++ b/osu.Game/Screens/Play/PlayerSettings/PlayerSliderBar.cs @@ -17,7 +17,6 @@ namespace osu.Game.Screens.Play.PlayerSettings protected override Drawable CreateControl() => new Sliderbar { - Margin = new MarginPadding { Top = 5, Bottom = 5 }, RelativeSizeAxes = Axes.X };