Skip to content

Commit 54f9589

Browse files
committed
Starting TabSide.Left feature.
1 parent bdd9912 commit 54f9589

File tree

2 files changed

+321
-166
lines changed

2 files changed

+321
-166
lines changed

Terminal.Gui/Views/TabView/TabRow.cs

Lines changed: 18 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ public TabRow (TabView host)
4141
Add (_rightScrollIndicator, _leftScrollIndicator);
4242
}
4343

44+
/// <inheritdoc />
45+
public override void EndInit ()
46+
{
47+
_host._tabLocations = _host.CalculateViewport (Viewport);
48+
49+
base.EndInit ();
50+
}
51+
4452
protected override bool OnMouseEvent (MouseEventArgs me)
4553
{
4654
View? parent = me.View is Adornment adornment ? adornment.Parent : me.View;
@@ -119,9 +127,16 @@ protected override void OnHasFocusChanged (bool newHasFocus, View? previousFocus
119127
/// <inheritdoc/>
120128
protected override void OnSubViewLayout (LayoutEventArgs args)
121129
{
122-
_host._tabLocations = _host.CalculateViewport (_host.Viewport).ToArray ();
130+
if (_host._tabLocations is null)
131+
{
132+
return;
133+
}
123134

124-
RenderTabLine ();
135+
if (_host is { SelectedTab: { }, _tabLocations: { } } && !_host._tabLocations!.Contains (_host.SelectedTab))
136+
{
137+
_host.SelectedTab = _host._tabLocations [0];
138+
Application.Invoke (() => _host.SetNeedsLayout ());
139+
}
125140

126141
RenderUnderline ();
127142

@@ -766,7 +781,7 @@ private void RenderTabLineCanvas ()
766781
}
767782
}
768783

769-
_host.LineCanvas.Merge (lc);
784+
LineCanvas.Merge (lc);
770785
}
771786

772787
private int GetUnderlineYPosition ()
@@ -779,96 +794,6 @@ private int GetUnderlineYPosition ()
779794
return _host.Style.ShowInitialLine ? 2 : 1;
780795
}
781796

782-
/// <summary>Renders the line with the tab names in it.</summary>
783-
private void RenderTabLine ()
784-
{
785-
if (_host._tabLocations is null)
786-
{
787-
return;
788-
}
789-
790-
View? selected = null;
791-
int topLine = _host.Style.ShowInitialLine ? 1 : 0;
792-
793-
foreach (Tab toRender in _host._tabLocations)
794-
{
795-
Tab tab = toRender;
796-
797-
if (toRender == _host.SelectedTab)
798-
{
799-
selected = tab;
800-
801-
switch (_host.Style.TabsSide)
802-
{
803-
case TabSide.Top:
804-
tab.Border!.Thickness = new (1, topLine, 1, 0);
805-
tab.Margin!.Thickness = new (0, 0, 0, topLine);
806-
807-
break;
808-
case TabSide.Bottom:
809-
tab.Border!.Thickness = new (1, 0, 1, topLine);
810-
tab.Margin!.Thickness = new (0, 1, 0, 0);
811-
812-
break;
813-
case TabSide.Left:
814-
break;
815-
case TabSide.Right:
816-
break;
817-
default:
818-
throw new ArgumentOutOfRangeException ();
819-
}
820-
}
821-
else if (selected is null)
822-
{
823-
switch (_host.Style.TabsSide)
824-
{
825-
case TabSide.Top:
826-
tab.Border!.Thickness = new (1, topLine, 1, 1);
827-
tab.Margin!.Thickness = new (0, 0, 0, 0);
828-
829-
break;
830-
case TabSide.Bottom:
831-
tab.Border!.Thickness = new (1, 1, 1, topLine);
832-
tab.Margin!.Thickness = new (0, 0, 0, 0);
833-
834-
break;
835-
case TabSide.Left:
836-
break;
837-
case TabSide.Right:
838-
break;
839-
default:
840-
throw new ArgumentOutOfRangeException ();
841-
}
842-
}
843-
else
844-
{
845-
switch (_host.Style.TabsSide)
846-
{
847-
case TabSide.Top:
848-
tab.Border!.Thickness = new (1, topLine, 1, 1);
849-
tab.Margin!.Thickness = new (0, 0, 0, 0);
850-
851-
break;
852-
case TabSide.Bottom:
853-
tab.Border!.Thickness = new (1, 1, 1, topLine);
854-
tab.Margin!.Thickness = new (0, 0, 0, 0);
855-
856-
break;
857-
case TabSide.Left:
858-
break;
859-
case TabSide.Right:
860-
break;
861-
default:
862-
throw new ArgumentOutOfRangeException ();
863-
}
864-
}
865-
866-
// Ensures updating TextFormatter constrains
867-
tab.TextFormatter.ConstrainToWidth = tab.GetContentSize ().Width;
868-
tab.TextFormatter.ConstrainToHeight = tab.GetContentSize ().Height;
869-
}
870-
}
871-
872797
/// <summary>Renders the line of the tab that adjoins the content of the tab.</summary>
873798
private void RenderUnderline ()
874799
{

0 commit comments

Comments
 (0)