Skip to content

Commit bb0491e

Browse files
committed
Add up and down arrows feature.
1 parent 427d118 commit bb0491e

File tree

1 file changed

+92
-35
lines changed

1 file changed

+92
-35
lines changed

Terminal.Gui/Views/TabView/TabRow.cs

Lines changed: 92 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ namespace Terminal.Gui;
44
internal class TabRow : View
55
{
66
private readonly TabView _host;
7-
private readonly View _leftScrollIndicator;
8-
private readonly View _rightScrollIndicator;
7+
private readonly View _leftUpScrollIndicator;
8+
private readonly View _rightDownScrollIndicator;
99

1010
public TabRow (TabView host)
1111
{
@@ -17,27 +17,25 @@ public TabRow (TabView host)
1717
TabStop = TabBehavior.TabGroup;
1818
Width = Dim.Fill ();
1919

20-
_rightScrollIndicator = new View
20+
_rightDownScrollIndicator = new View
2121
{
22-
Id = "rightScrollIndicator",
22+
Id = "rightDownScrollIndicator",
2323
Width = 1,
2424
Height = 1,
25-
Visible = false,
26-
Text = Glyphs.RightArrow.ToString ()
25+
Visible = false
2726
};
28-
_rightScrollIndicator.MouseClick += _host.Tab_MouseClick!;
27+
_rightDownScrollIndicator.MouseClick += _host.Tab_MouseClick!;
2928

30-
_leftScrollIndicator = new View
29+
_leftUpScrollIndicator = new View
3130
{
32-
Id = "leftScrollIndicator",
31+
Id = "leftUpScrollIndicator",
3332
Width = 1,
3433
Height = 1,
35-
Visible = false,
36-
Text = Glyphs.LeftArrow.ToString ()
34+
Visible = false
3735
};
38-
_leftScrollIndicator.MouseClick += _host.Tab_MouseClick!;
36+
_leftUpScrollIndicator.MouseClick += _host.Tab_MouseClick!;
3937

40-
Add (_rightScrollIndicator, _leftScrollIndicator);
38+
Add (_rightDownScrollIndicator, _leftUpScrollIndicator);
4139
}
4240

4341
/// <inheritdoc />
@@ -83,11 +81,11 @@ protected override bool OnMouseEvent (MouseEventArgs me)
8381
{
8482
var scrollIndicatorHit = 0;
8583

86-
if (me.View is { Id: "rightScrollIndicator" } || me.Flags.HasFlag (MouseFlags.WheeledDown) || me.Flags.HasFlag (MouseFlags.WheeledRight))
84+
if (me.View is { Id: "rightDownScrollIndicator" } || me.Flags.HasFlag (MouseFlags.WheeledDown) || me.Flags.HasFlag (MouseFlags.WheeledRight))
8785
{
8886
scrollIndicatorHit = 1;
8987
}
90-
else if (me.View is { Id: "leftScrollIndicator" } || me.Flags.HasFlag (MouseFlags.WheeledUp) || me.Flags.HasFlag (MouseFlags.WheeledLeft))
88+
else if (me.View is { Id: "leftUpScrollIndicator" } || me.Flags.HasFlag (MouseFlags.WheeledUp) || me.Flags.HasFlag (MouseFlags.WheeledLeft))
9189
{
9290
scrollIndicatorHit = -1;
9391
}
@@ -671,7 +669,7 @@ private void RenderTabLineCanvas ()
671669
int lineLength = tabsBarVts.Right - vts.Right;
672670

673671
// Right horizontal line
674-
if (ShouldDrawRightScrollIndicator ())
672+
if (ShouldDrawRightDownScrollIndicator ())
675673
{
676674
if (lineLength - arrowOffset > 0)
677675
{
@@ -783,20 +781,30 @@ private void RenderTabLineCanvas ()
783781
LineCanvas.Merge (lc);
784782
}
785783

786-
private int GetUnderlineYPosition ()
784+
private int GetUnderlineXOrYPosition ()
787785
{
788-
if (_host.Style.TabsSide == TabSide.Bottom)
786+
switch (_host.Style.TabsSide)
789787
{
790-
return 0;
791-
}
788+
case TabSide.Top:
789+
790+
return _host.Style.ShowInitialLine ? 2 : 1;
791+
case TabSide.Bottom:
792+
793+
return 0;
794+
case TabSide.Left:
792795

793-
return _host.Style.ShowInitialLine ? 2 : 1;
796+
return _host.Style.ShowInitialLine ? Frame.Right - 1 : Frame.Right;
797+
case TabSide.Right:
798+
return 0;
799+
default:
800+
throw new ArgumentOutOfRangeException ();
801+
}
794802
}
795803

796804
/// <summary>Renders the line of the tab that adjoins the content of the tab.</summary>
797805
private void RenderUnderline ()
798806
{
799-
int y = GetUnderlineYPosition ();
807+
int xOrY = GetUnderlineXOrYPosition ();
800808

801809
Tab? selected = _host._tabLocations?.FirstOrDefault (t => t == _host.SelectedTab);
802810

@@ -805,42 +813,91 @@ private void RenderUnderline ()
805813
return;
806814
}
807815

808-
// draw scroll indicators
816+
// Set the correct glyphs for scroll indicators
817+
switch (_host.Style.TabsSide)
818+
{
819+
case TabSide.Top:
820+
case TabSide.Bottom:
821+
_rightDownScrollIndicator.Text = Glyphs.RightArrow.ToString ();
822+
_leftUpScrollIndicator.Text = Glyphs.LeftArrow.ToString ();
823+
824+
break;
825+
case TabSide.Left:
826+
case TabSide.Right:
827+
_rightDownScrollIndicator.Text = Glyphs.DownArrow.ToString ();
828+
_leftUpScrollIndicator.Text = Glyphs.UpArrow.ToString ();
829+
830+
break;
831+
default:
832+
throw new ArgumentOutOfRangeException ();
833+
}
834+
835+
// position scroll indicators
809836

810837
// if there are more tabs to the left not visible
811838
if (_host.TabScrollOffset > 0)
812839
{
813-
_leftScrollIndicator.X = 0;
814-
_leftScrollIndicator.Y = y;
840+
switch (_host.Style.TabsSide)
841+
{
842+
case TabSide.Top:
843+
case TabSide.Bottom:
844+
_leftUpScrollIndicator.X = 0;
845+
_leftUpScrollIndicator.Y = xOrY;
846+
847+
break;
848+
case TabSide.Left:
849+
case TabSide.Right:
850+
_leftUpScrollIndicator.X = xOrY;
851+
_leftUpScrollIndicator.Y = 0;
852+
853+
break;
854+
default:
855+
throw new ArgumentOutOfRangeException ();
856+
}
815857

816858
// indicate that
817-
_leftScrollIndicator.Visible = true;
859+
_leftUpScrollIndicator.Visible = true;
818860

819861
// Ensures this is clicked instead of the first tab
820-
MoveSubviewToEnd (_leftScrollIndicator);
862+
MoveSubviewToEnd (_leftUpScrollIndicator);
821863
}
822864
else
823865
{
824-
_leftScrollIndicator.Visible = false;
866+
_leftUpScrollIndicator.Visible = false;
825867
}
826868

827869
// if there are more tabs to the right not visible
828-
if (ShouldDrawRightScrollIndicator ())
870+
if (ShouldDrawRightDownScrollIndicator ())
829871
{
830-
_rightScrollIndicator.X = Viewport.Width - 1;
831-
_rightScrollIndicator.Y = y;
872+
switch (_host.Style.TabsSide)
873+
{
874+
case TabSide.Top:
875+
case TabSide.Bottom:
876+
_rightDownScrollIndicator.X = Viewport.Width - 1;
877+
_rightDownScrollIndicator.Y = xOrY;
878+
879+
break;
880+
case TabSide.Left:
881+
case TabSide.Right:
882+
_rightDownScrollIndicator.X = xOrY;
883+
_rightDownScrollIndicator.Y = Viewport.Height - 1;
884+
885+
break;
886+
default:
887+
throw new ArgumentOutOfRangeException ();
888+
}
832889

833890
// indicate that
834-
_rightScrollIndicator.Visible = true;
891+
_rightDownScrollIndicator.Visible = true;
835892

836893
// Ensures this is clicked instead of the last tab if under this
837-
MoveSubviewToStart (_rightScrollIndicator);
894+
MoveSubviewToStart (_rightDownScrollIndicator);
838895
}
839896
else
840897
{
841-
_rightScrollIndicator.Visible = false;
898+
_rightDownScrollIndicator.Visible = false;
842899
}
843900
}
844901

845-
private bool ShouldDrawRightScrollIndicator () { return _host._tabLocations!.LastOrDefault () != _host.Tabs.LastOrDefault (); }
902+
private bool ShouldDrawRightDownScrollIndicator () { return _host._tabLocations!.LastOrDefault () != _host.Tabs.LastOrDefault (); }
846903
}

0 commit comments

Comments
 (0)