From 63a755d6926f8010ea4becea94ed4eb471939f18 Mon Sep 17 00:00:00 2001 From: BDisp Date: Tue, 19 Nov 2024 22:16:45 +0000 Subject: [PATCH] Remove unnecessary TabToRender class. --- Terminal.Gui/Views/TabView/TabRowView.cs | 18 +++++++++--------- Terminal.Gui/Views/TabView/TabToRender.cs | 17 ----------------- Terminal.Gui/Views/TabView/TabView.cs | 19 +++++++++---------- 3 files changed, 18 insertions(+), 36 deletions(-) delete mode 100644 Terminal.Gui/Views/TabView/TabToRender.cs diff --git a/Terminal.Gui/Views/TabView/TabRowView.cs b/Terminal.Gui/Views/TabView/TabRowView.cs index afee3fa5b..4ae96614c 100644 --- a/Terminal.Gui/Views/TabView/TabRowView.cs +++ b/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 (); } } diff --git a/Terminal.Gui/Views/TabView/TabToRender.cs b/Terminal.Gui/Views/TabView/TabToRender.cs deleted file mode 100644 index d29930a9e..000000000 --- a/Terminal.Gui/Views/TabView/TabToRender.cs +++ /dev/null @@ -1,17 +0,0 @@ -#nullable enable -namespace Terminal.Gui; - -internal class TabToRender -{ - public TabToRender (Tab tab, bool isSelected) - { - Tab = tab; - IsSelected = isSelected; - } - - /// True if the tab that is being rendered is the selected one. - /// - public bool IsSelected { get; } - - public Tab Tab { get; } -} diff --git a/Terminal.Gui/Views/TabView/TabView.cs b/Terminal.Gui/Views/TabView/TabView.cs index 627e251fd..324ba01de 100644 --- a/Terminal.Gui/Views/TabView/TabView.cs +++ b/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; /// Initializes a class. @@ -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 /// Returns which tabs to render at each x location. /// - internal IEnumerable CalculateViewport (Rectangle bounds) + internal IEnumerable 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;