From 558f4b5b1671d8a365559b6714ed236d4e44a36e Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Wed, 6 Mar 2024 09:32:22 +1100 Subject: [PATCH] ScrollContainer niceties (#4940) - If scroll is not visible we don't handle it. This means nested containers don't interfere with their parents anymore. - Fallback to Y-scrolling for H-scroll only containers. --- .../UserInterface/Controls/ScrollContainer.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Robust.Client/UserInterface/Controls/ScrollContainer.cs b/Robust.Client/UserInterface/Controls/ScrollContainer.cs index 87065d821..5733fab6b 100644 --- a/Robust.Client/UserInterface/Controls/ScrollContainer.cs +++ b/Robust.Client/UserInterface/Controls/ScrollContainer.cs @@ -20,6 +20,11 @@ namespace Robust.Client.UserInterface.Controls private bool _suppressScrollValueChanged; + /// + /// If true then if we have a y-axis scroll it will convert it to an x-axis scroll. + /// + public bool FallbackDeltaScroll { get; set; } = true; + public int ScrollSpeedX { get; set; } = 50; public int ScrollSpeedY { get; set; } = 50; @@ -246,9 +251,19 @@ namespace Robust.Client.UserInterface.Controls if (_hScrollEnabled) { - _hScrollBar.ValueTarget += args.Delta.X * ScrollSpeedX; + var delta = + args.Delta.X == 0f && + !_vScrollEnabled && + FallbackDeltaScroll ? + -args.Delta.Y : + args.Delta.X; + + _hScrollBar.ValueTarget += delta * ScrollSpeedX; } + if (!_vScrollVisible && !_hScrollVisible) + return; + args.Handle(); }