From 133256879685caf181defefe128ddd9e752e51cd Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Mon, 12 Dec 2022 03:10:13 +0300 Subject: [PATCH] Fix SettingsButton receiving input at padded area --- .../UserInterface/TestSceneSettingsButton.cs | 41 +++++++++++++++++++ osu.Game/Overlays/Settings/SettingsButton.cs | 4 ++ 2 files changed, 45 insertions(+) create mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneSettingsButton.cs diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneSettingsButton.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneSettingsButton.cs new file mode 100644 index 0000000000..4353e7ffef --- /dev/null +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneSettingsButton.cs @@ -0,0 +1,41 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics; +using osu.Game.Overlays.Settings; +using NUnit.Framework; +using osuTK; +using osu.Game.Overlays; + +namespace osu.Game.Tests.Visual.UserInterface +{ + public partial class TestSceneSettingsButton : OsuManualInputManagerTestScene + { + private readonly SettingsButton settingsButton; + + public TestSceneSettingsButton() + { + Add(new Container + { + AutoSizeAxes = Axes.Y, + Width = 500, + Child = settingsButton = new SettingsButton + { + Enabled = { Value = true }, + Text = "Test settings button" + } + }); + } + + [Test] + public void TestInputAtPaddedArea() + { + AddStep("Move cursor to button", () => InputManager.MoveMouseTo(settingsButton)); + AddAssert("Button is hovered", () => settingsButton.IsHovered); + AddStep("Move cursor to padded area", () => InputManager.MoveMouseTo(settingsButton.ScreenSpaceDrawQuad.TopLeft + new Vector2(SettingsPanel.CONTENT_MARGINS / 2f, 10))); + AddAssert("Cursor within a button", () => settingsButton.ScreenSpaceDrawQuad.Contains(InputManager.CurrentState.Mouse.Position)); + AddAssert("Button is not hovered", () => !settingsButton.IsHovered); + } + } +} diff --git a/osu.Game/Overlays/Settings/SettingsButton.cs b/osu.Game/Overlays/Settings/SettingsButton.cs index 5091ddc2d0..68cb95a2d8 100644 --- a/osu.Game/Overlays/Settings/SettingsButton.cs +++ b/osu.Game/Overlays/Settings/SettingsButton.cs @@ -9,11 +9,15 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; using osu.Framework.Localisation; using osu.Game.Graphics.UserInterfaceV2; +using osuTK; namespace osu.Game.Overlays.Settings { public partial class SettingsButton : RoundedButton, IHasTooltip, IConditionalFilterable { + // We don't want to receive input at the padded area + public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Content.ReceivePositionalInputAt(screenSpacePos); + public SettingsButton() { RelativeSizeAxes = Axes.X;