From cbecc4cc4b3413f507d3c8612ea3394a783d5dd9 Mon Sep 17 00:00:00 2001 From: pathetic meowmeow Date: Sun, 23 Feb 2025 12:47:13 -0500 Subject: [PATCH] Use new engine APIs for setting the scroll target of views (#35401) --- .../AtmosAlertsComputerWindow.xaml.cs | 28 ++----------------- .../AtmosMonitoringConsoleWindow.xaml.cs | 24 ++-------------- .../CrewMonitoringWindow.xaml.cs | 23 ++------------- .../PowerMonitoringWindow.xaml.Widgets.cs | 28 ++----------------- 4 files changed, 8 insertions(+), 95 deletions(-) diff --git a/Content.Client/Atmos/Consoles/AtmosAlertsComputerWindow.xaml.cs b/Content.Client/Atmos/Consoles/AtmosAlertsComputerWindow.xaml.cs index 81c9a409a3..1268433cab 100644 --- a/Content.Client/Atmos/Consoles/AtmosAlertsComputerWindow.xaml.cs +++ b/Content.Client/Atmos/Consoles/AtmosAlertsComputerWindow.xaml.cs @@ -512,39 +512,15 @@ public sealed partial class AtmosAlertsComputerWindow : FancyWindow if (scroll == null) return; - if (!TryGetVerticalScrollbar(scroll, out var vScrollbar)) - return; - if (!TryGetNextScrollPosition(out float? nextScrollPosition)) return; - vScrollbar.ValueTarget = nextScrollPosition.Value; + scroll.VScrollTarget = nextScrollPosition.Value; - if (MathHelper.CloseToPercent(vScrollbar.Value, vScrollbar.ValueTarget)) + if (MathHelper.CloseToPercent(scroll.VScroll, scroll.VScrollTarget)) _autoScrollActive = false; } - private bool TryGetVerticalScrollbar(ScrollContainer scroll, [NotNullWhen(true)] out VScrollBar? vScrollBar) - { - vScrollBar = null; - - foreach (var child in scroll.Children) - { - if (child is not VScrollBar) - continue; - - var castChild = child as VScrollBar; - - if (castChild != null) - { - vScrollBar = castChild; - return true; - } - } - - return false; - } - private bool TryGetNextScrollPosition([NotNullWhen(true)] out float? nextScrollPosition) { nextScrollPosition = null; diff --git a/Content.Client/Atmos/Consoles/AtmosMonitoringConsoleWindow.xaml.cs b/Content.Client/Atmos/Consoles/AtmosMonitoringConsoleWindow.xaml.cs index 515f91790f..e25c3af9e9 100644 --- a/Content.Client/Atmos/Consoles/AtmosMonitoringConsoleWindow.xaml.cs +++ b/Content.Client/Atmos/Consoles/AtmosMonitoringConsoleWindow.xaml.cs @@ -350,35 +350,15 @@ public sealed partial class AtmosMonitoringConsoleWindow : FancyWindow if (scroll == null) return; - if (!TryGetVerticalScrollbar(scroll, out var vScrollbar)) - return; - if (!TryGetNextScrollPosition(out float? nextScrollPosition)) return; - vScrollbar.ValueTarget = nextScrollPosition.Value; + scroll.VScrollTarget = nextScrollPosition.Value; - if (MathHelper.CloseToPercent(vScrollbar.Value, vScrollbar.ValueTarget)) + if (MathHelper.CloseToPercent(scroll.VScroll, scroll.VScrollTarget)) _autoScrollActive = false; } - private bool TryGetVerticalScrollbar(ScrollContainer scroll, [NotNullWhen(true)] out VScrollBar? vScrollBar) - { - vScrollBar = null; - - foreach (var control in scroll.Children) - { - if (control is not VScrollBar) - continue; - - vScrollBar = (VScrollBar)control; - - return true; - } - - return false; - } - private bool TryGetNextScrollPosition([NotNullWhen(true)] out float? nextScrollPosition) { nextScrollPosition = null; diff --git a/Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml.cs b/Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml.cs index ac23e8216b..18c54cd231 100644 --- a/Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml.cs +++ b/Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml.cs @@ -372,14 +372,11 @@ public sealed partial class CrewMonitoringWindow : FancyWindow if (!_tryToScrollToListFocus) return; - if (!TryGetVerticalScrollbar(SensorScroller, out var vScrollbar)) - return; - if (TryGetNextScrollPosition(out float? nextScrollPosition)) { - vScrollbar.ValueTarget = nextScrollPosition.Value; + SensorScroller.VScrollTarget = nextScrollPosition.Value; - if (MathHelper.CloseToPercent(vScrollbar.Value, vScrollbar.ValueTarget)) + if (MathHelper.CloseToPercent(SensorScroller.VScroll, SensorScroller.VScrollTarget)) { _tryToScrollToListFocus = false; return; @@ -387,22 +384,6 @@ public sealed partial class CrewMonitoringWindow : FancyWindow } } - private bool TryGetVerticalScrollbar(ScrollContainer scroll, [NotNullWhen(true)] out VScrollBar? vScrollBar) - { - vScrollBar = null; - - foreach (var child in scroll.Children) - { - if (child is not VScrollBar) - continue; - - vScrollBar = (VScrollBar) child; - return true; - } - - return false; - } - private bool TryGetNextScrollPosition([NotNullWhen(true)] out float? nextScrollPosition) { nextScrollPosition = 0; diff --git a/Content.Client/Power/PowerMonitoringWindow.xaml.Widgets.cs b/Content.Client/Power/PowerMonitoringWindow.xaml.Widgets.cs index 87b252e9d5..d3671e265a 100644 --- a/Content.Client/Power/PowerMonitoringWindow.xaml.Widgets.cs +++ b/Content.Client/Power/PowerMonitoringWindow.xaml.Widgets.cs @@ -269,27 +269,6 @@ public sealed partial class PowerMonitoringWindow return false; } - private bool TryGetVerticalScrollbar(ScrollContainer scroll, [NotNullWhen(true)] out VScrollBar? vScrollBar) - { - vScrollBar = null; - - foreach (var child in scroll.Children) - { - if (child is not VScrollBar) - continue; - - var castChild = child as VScrollBar; - - if (castChild != null) - { - vScrollBar = castChild; - return true; - } - } - - return false; - } - private void AutoScrollToFocus() { if (!_autoScrollActive) @@ -299,15 +278,12 @@ public sealed partial class PowerMonitoringWindow if (scroll == null) return; - if (!TryGetVerticalScrollbar(scroll, out var vScrollbar)) - return; - if (!TryGetNextScrollPosition(out float? nextScrollPosition)) return; - vScrollbar.ValueTarget = nextScrollPosition.Value; + scroll.VScrollTarget = nextScrollPosition.Value; - if (MathHelper.CloseToPercent(vScrollbar.Value, vScrollbar.ValueTarget)) + if (MathHelper.CloseToPercent(scroll.VScroll, scroll.VScrollTarget)) _autoScrollActive = false; }