diff --git a/Robust.Client/UserInterface/Controls/TabContainer.cs b/Robust.Client/UserInterface/Controls/TabContainer.cs index 623ac18ac1a..5ffd9724ce1 100644 --- a/Robust.Client/UserInterface/Controls/TabContainer.cs +++ b/Robust.Client/UserInterface/Controls/TabContainer.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Numerics; using Robust.Client.Graphics; using Robust.Shared.Input; @@ -21,6 +22,8 @@ public class TabContainer : Container private int _currentTab; private bool _tabsVisible = true; + // The right-most coordinate of each tab header + private List _tabRight = new(); public int CurrentTab { @@ -157,11 +160,14 @@ protected internal override void Draw(DrawingHandleScreen handle) var headerOffset = 0f; + _tabRight.Clear(); + // Then, draw the tabs. for (var i = 0; i < ChildCount; i++) { if (!GetTabVisible(i)) { + _tabRight.Add(headerOffset); continue; } @@ -214,6 +220,8 @@ protected internal override void Draw(DrawingHandleScreen handle) } headerOffset += boxAdvance; + // Remember the right-most point of this tab, for testing clicked areas + _tabRight.Add(headerOffset); } } @@ -283,46 +291,17 @@ protected internal override void KeyBindDown(GUIBoundKeyEventArgs args) args.Handle(); var relX = args.RelativePixelPosition.X; - - var font = _getFont(); - var boxActive = _getTabBoxActive(); - var boxInactive = _getTabBoxInactive(); - - var headerOffset = 0f; - + float tabLeft = 0; for (var i = 0; i < ChildCount; i++) { - if (!GetTabVisible(i)) + if (relX > tabLeft && relX <= _tabRight[i]) { - continue; - } - - var title = GetActualTabTitle(i); - - var titleLength = 0; - // Get string length. - foreach (var rune in title.EnumerateRunes()) - { - if (!font.TryGetCharMetrics(rune, UIScale, out var metrics)) - { - continue; - } - - titleLength += metrics.Advance; - } - - var active = _currentTab == i; - var box = active ? boxActive : boxInactive; - var boxAdvance = titleLength + (box?.MinimumSize.X ?? 0); - - if (headerOffset < relX && headerOffset + boxAdvance > relX) - { - // Got em. CurrentTab = i; return; } - headerOffset += boxAdvance; + // Next tab starts here + tabLeft = _tabRight[i]; } }