浏览代码

Remove unnecessary TabToRender class.

BDisp 8 月之前
父节点
当前提交
63a755d692

+ 9 - 9
Terminal.Gui/Views/TabView/TabRowView.cs

@@ -143,17 +143,17 @@ internal class TabRowView : View
             return;
         }
 
-        TabToRender [] tabLocations = _host._tabLocations;
+        Tab [] tabLocations = _host._tabLocations;
         int selectedTab = -1;
         var lc = new LineCanvas ();
 
         for (var i = 0; i < tabLocations.Length; i++)
         {
-            View tab = tabLocations [i].Tab;
+            View tab = tabLocations [i];
             Rectangle vts = tab.ViewportToScreen (tab.Viewport);
-            int selectedOffset = _host.Style.ShowTopLine && tabLocations [i].IsSelected ? 0 : 1;
+            int selectedOffset = _host.Style.ShowTopLine && tabLocations [i] == _host.SelectedTab ? 0 : 1;
 
-            if (tabLocations [i].IsSelected)
+            if (tabLocations [i] == _host.SelectedTab)
             {
                 selectedTab = i;
 
@@ -691,11 +691,11 @@ internal class TabRowView : View
         View? selected = null;
         int topLine = _host.Style.ShowTopLine ? 1 : 0;
 
-        foreach (TabToRender toRender in _host._tabLocations)
+        foreach (Tab toRender in _host._tabLocations)
         {
-            Tab tab = toRender.Tab;
+            Tab tab = toRender;
 
-            if (toRender.IsSelected)
+            if (toRender == _host.SelectedTab)
             {
                 selected = tab;
 
@@ -748,7 +748,7 @@ internal class TabRowView : View
     {
         int y = GetUnderlineYPosition ();
 
-        TabToRender? selected = _host._tabLocations?.FirstOrDefault (t => t.IsSelected);
+        Tab? selected = _host._tabLocations?.FirstOrDefault (t => t == _host.SelectedTab);
 
         if (selected is null)
         {
@@ -792,5 +792,5 @@ internal class TabRowView : View
         }
     }
 
-    private bool ShouldDrawRightScrollIndicator () { return _host._tabLocations!.LastOrDefault ()?.Tab != _host.Tabs.LastOrDefault (); }
+    private bool ShouldDrawRightScrollIndicator () { return _host._tabLocations!.LastOrDefault () != _host.Tabs.LastOrDefault (); }
 }

+ 0 - 17
Terminal.Gui/Views/TabView/TabToRender.cs

@@ -1,17 +0,0 @@
-#nullable enable
-namespace Terminal.Gui;
-
-internal class TabToRender
-{
-    public TabToRender (Tab tab, bool isSelected)
-    {
-        Tab = tab;
-        IsSelected = isSelected;
-    }
-
-    /// <summary>True if the tab that is being rendered is the selected one.</summary>
-    /// <value></value>
-    public bool IsSelected { get; }
-
-    public Tab Tab { get; }
-}

+ 9 - 10
Terminal.Gui/Views/TabView/TabView.cs

@@ -20,8 +20,7 @@ public class TabView : View
 
     private Tab? _selectedTab;
 
-    // BUGBUG: Horrible containment design.
-    internal TabToRender []? _tabLocations;
+    internal Tab []? _tabLocations;
     private int _tabScrollOffset;
 
     /// <summary>Initializes a <see cref="TabView"/> class.</summary>
@@ -287,7 +286,7 @@ public class TabView : View
         }
 
         // if current viewport does not include the selected tab
-        if (!CalculateViewport (Viewport).Any (r => Equals (SelectedTab, r.Tab)))
+        if (!CalculateViewport (Viewport).Any (t => Equals (SelectedTab, t)))
         {
             // Set scroll offset so the first tab rendered is the
             TabScrollOffset = Math.Max (0, Tabs.IndexOf (SelectedTab));
@@ -428,7 +427,7 @@ public class TabView : View
 
     /// <summary>Returns which tabs to render at each x location.</summary>
     /// <returns></returns>
-    internal IEnumerable<TabToRender> CalculateViewport (Rectangle bounds)
+    internal IEnumerable<Tab> CalculateViewport (Rectangle bounds)
     {
         UnSetCurrentTabs ();
 
@@ -467,7 +466,7 @@ public class TabView : View
                 tab.MouseClick += Tab_MouseClick!;
                 tab.Border!.MouseClick += Tab_MouseClick!;
 
-                yield return new (tab, Equals (SelectedTab, tab));
+                yield return tab;
 
                 break;
             }
@@ -498,7 +497,7 @@ public class TabView : View
             tab.MouseClick += Tab_MouseClick!;
             tab.Border!.MouseClick += Tab_MouseClick!;
 
-            yield return new (tab, Equals (SelectedTab, tab));
+            yield return tab;
 
             prevTab = tab;
 
@@ -557,11 +556,11 @@ public class TabView : View
         }
         else if (_tabLocations is { })
         {
-            foreach (TabToRender tabToRender in _tabLocations)
+            foreach (Tab tabToRender in _tabLocations)
             {
-                tabToRender.Tab.MouseClick -= Tab_MouseClick!;
-                tabToRender.Tab.Border!.MouseClick -= Tab_MouseClick!;
-                tabToRender.Tab.Visible = false;
+                tabToRender.MouseClick -= Tab_MouseClick!;
+                tabToRender.Border!.MouseClick -= Tab_MouseClick!;
+                tabToRender.Visible = false;
             }
 
             _tabLocations = null;