Skip to content

Commit 23a79d3

Browse files
committed
refactor(JoinDiagnostics, StateDivergence): Consolidate control visibility logic
- Replaced inline control visibility logic in `JoinFailureDiagnosticsPanel` and `StateDivergenceDiagnosticsPanel` with a new method `EnsureMainScrollControlVisible`. - Improved code readability and maintainability by centralizing the visibility check for controls in the main scroll.
1 parent 5cb44c7 commit 23a79d3

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

Networking/JoinDiagnostics/JoinFailureDiagnosticsPanel.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,14 +658,26 @@ private void AttachControllerFocusChromeRecursive(Node node)
658658
{
659659
button.SetMeta(FocusRefreshAttachedMeta, true);
660660
button.Pressed += ScheduleFocusRefresh;
661-
button.FocusEntered += () => _mainScroll?.EnsureControlVisible(button);
661+
button.FocusEntered += () => EnsureMainScrollControlVisible(button);
662662
}
663663
}
664664

665665
foreach (var child in node.GetChildren())
666666
AttachControllerFocusChromeRecursive(child);
667667
}
668668

669+
private void EnsureMainScrollControlVisible(Control control)
670+
{
671+
var scroll = _mainScroll;
672+
if (scroll == null ||
673+
!IsInstanceValid(scroll) ||
674+
!IsInstanceValid(control) ||
675+
!scroll.IsAncestorOf(control))
676+
return;
677+
678+
scroll.EnsureControlVisible(control);
679+
}
680+
669681
private void ScheduleFocusRefresh()
670682
{
671683
if (_focusRefreshScheduled)

Networking/StateDivergence/StateDivergenceDiagnosticsPanel.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,14 +795,26 @@ private void AttachControllerFocusChromeRecursive(Node node)
795795
{
796796
button.SetMeta(FocusRefreshAttachedMeta, true);
797797
button.Pressed += ScheduleFocusRefresh;
798-
button.FocusEntered += () => _mainScroll?.EnsureControlVisible(button);
798+
button.FocusEntered += () => EnsureMainScrollControlVisible(button);
799799
}
800800
}
801801

802802
foreach (var child in node.GetChildren())
803803
AttachControllerFocusChromeRecursive(child);
804804
}
805805

806+
private void EnsureMainScrollControlVisible(Control control)
807+
{
808+
var scroll = _mainScroll;
809+
if (scroll == null ||
810+
!IsInstanceValid(scroll) ||
811+
!IsInstanceValid(control) ||
812+
!scroll.IsAncestorOf(control))
813+
return;
814+
815+
scroll.EnsureControlVisible(control);
816+
}
817+
806818
private void ScheduleFocusRefresh()
807819
{
808820
if (_focusRefreshScheduled)

0 commit comments

Comments
 (0)