Skip to content

Commit 427d118

Browse files
committed
Starting TabSide.Left feature.
1 parent fa1bdae commit 427d118

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
@@ -40,6 +40,14 @@ public TabRow (TabView host)
4040
Add (_rightScrollIndicator, _leftScrollIndicator);
4141
}
4242

43+
/// <inheritdoc />
44+
public override void EndInit ()
45+
{
46+
_host._tabLocations = _host.CalculateViewport (Viewport);
47+
48+
base.EndInit ();
49+
}
50+
4351
protected override bool OnMouseEvent (MouseEventArgs me)
4452
{
4553
View? parent = me.View is Adornment adornment ? adornment.Parent : me.View;
@@ -118,9 +126,16 @@ protected override void OnHasFocusChanged (bool newHasFocus, View? previousFocus
118126
/// <inheritdoc/>
119127
protected override void OnSubviewLayout (LayoutEventArgs args)
120128
{
121-
_host._tabLocations = _host.CalculateViewport (_host.Viewport).ToArray ();
129+
if (_host._tabLocations is null)
130+
{
131+
return;
132+
}
122133

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

125140
RenderUnderline ();
126141

@@ -765,7 +780,7 @@ private void RenderTabLineCanvas ()
765780
}
766781
}
767782

768-
_host.LineCanvas.Merge (lc);
783+
LineCanvas.Merge (lc);
769784
}
770785

771786
private int GetUnderlineYPosition ()
@@ -778,96 +793,6 @@ private int GetUnderlineYPosition ()
778793
return _host.Style.ShowInitialLine ? 2 : 1;
779794
}
780795

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

0 commit comments

Comments
 (0)