Skip to content

Commit e99e12d

Browse files
committed
Add up and down arrows feature.
1 parent 54f9589 commit e99e12d

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
@@ -5,8 +5,8 @@ namespace Terminal.Gui.Views;
55
internal class TabRow : View
66
{
77
private readonly TabView _host;
8-
private readonly View _leftScrollIndicator;
9-
private readonly View _rightScrollIndicator;
8+
private readonly View _leftUpScrollIndicator;
9+
private readonly View _rightDownScrollIndicator;
1010

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

21-
_rightScrollIndicator = new View
21+
_rightDownScrollIndicator = new View
2222
{
23-
Id = "rightScrollIndicator",
23+
Id = "rightDownScrollIndicator",
2424
Width = 1,
2525
Height = 1,
26-
Visible = false,
27-
Text = Glyphs.RightArrow.ToString ()
26+
Visible = false
2827
};
29-
_rightScrollIndicator.MouseClick += _host.Tab_MouseClick!;
28+
_rightDownScrollIndicator.MouseClick += _host.Tab_MouseClick!;
3029

31-
_leftScrollIndicator = new View
30+
_leftUpScrollIndicator = new View
3231
{
33-
Id = "leftScrollIndicator",
32+
Id = "leftUpScrollIndicator",
3433
Width = 1,
3534
Height = 1,
36-
Visible = false,
37-
Text = Glyphs.LeftArrow.ToString ()
35+
Visible = false
3836
};
39-
_leftScrollIndicator.MouseClick += _host.Tab_MouseClick!;
37+
_leftUpScrollIndicator.MouseClick += _host.Tab_MouseClick!;
4038

41-
Add (_rightScrollIndicator, _leftScrollIndicator);
39+
Add (_rightDownScrollIndicator, _leftUpScrollIndicator);
4240
}
4341

4442
/// <inheritdoc />
@@ -84,11 +82,11 @@ protected override bool OnMouseEvent (MouseEventArgs me)
8482
{
8583
var scrollIndicatorHit = 0;
8684

87-
if (me.View is { Id: "rightScrollIndicator" } || me.Flags.HasFlag (MouseFlags.WheeledDown) || me.Flags.HasFlag (MouseFlags.WheeledRight))
85+
if (me.View is { Id: "rightDownScrollIndicator" } || me.Flags.HasFlag (MouseFlags.WheeledDown) || me.Flags.HasFlag (MouseFlags.WheeledRight))
8886
{
8987
scrollIndicatorHit = 1;
9088
}
91-
else if (me.View is { Id: "leftScrollIndicator" } || me.Flags.HasFlag (MouseFlags.WheeledUp) || me.Flags.HasFlag (MouseFlags.WheeledLeft))
89+
else if (me.View is { Id: "leftUpScrollIndicator" } || me.Flags.HasFlag (MouseFlags.WheeledUp) || me.Flags.HasFlag (MouseFlags.WheeledLeft))
9290
{
9391
scrollIndicatorHit = -1;
9492
}
@@ -672,7 +670,7 @@ private void RenderTabLineCanvas ()
672670
int lineLength = tabsBarVts.Right - vts.Right;
673671

674672
// Right horizontal line
675-
if (ShouldDrawRightScrollIndicator ())
673+
if (ShouldDrawRightDownScrollIndicator ())
676674
{
677675
if (lineLength - arrowOffset > 0)
678676
{
@@ -784,20 +782,30 @@ private void RenderTabLineCanvas ()
784782
LineCanvas.Merge (lc);
785783
}
786784

787-
private int GetUnderlineYPosition ()
785+
private int GetUnderlineXOrYPosition ()
788786
{
789-
if (_host.Style.TabsSide == TabSide.Bottom)
787+
switch (_host.Style.TabsSide)
790788
{
791-
return 0;
792-
}
789+
case TabSide.Top:
790+
791+
return _host.Style.ShowInitialLine ? 2 : 1;
792+
case TabSide.Bottom:
793+
794+
return 0;
795+
case TabSide.Left:
793796

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

797805
/// <summary>Renders the line of the tab that adjoins the content of the tab.</summary>
798806
private void RenderUnderline ()
799807
{
800-
int y = GetUnderlineYPosition ();
808+
int xOrY = GetUnderlineXOrYPosition ();
801809

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

@@ -806,42 +814,91 @@ private void RenderUnderline ()
806814
return;
807815
}
808816

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

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

817859
// indicate that
818-
_leftScrollIndicator.Visible = true;
860+
_leftUpScrollIndicator.Visible = true;
819861

820862
// Ensures this is clicked instead of the first tab
821-
MoveSubViewToEnd (_leftScrollIndicator);
863+
MoveSubViewToEnd (_leftUpScrollIndicator);
822864
}
823865
else
824866
{
825-
_leftScrollIndicator.Visible = false;
867+
_leftUpScrollIndicator.Visible = false;
826868
}
827869

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

834891
// indicate that
835-
_rightScrollIndicator.Visible = true;
892+
_rightDownScrollIndicator.Visible = true;
836893

837894
// Ensures this is clicked instead of the last tab if under this
838-
MoveSubViewToStart (_rightScrollIndicator);
895+
MoveSubViewToStart (_rightDownScrollIndicator);
839896
}
840897
else
841898
{
842-
_rightScrollIndicator.Visible = false;
899+
_rightDownScrollIndicator.Visible = false;
843900
}
844901
}
845902

846-
private bool ShouldDrawRightScrollIndicator () { return _host._tabLocations!.LastOrDefault () != _host.Tabs.LastOrDefault (); }
903+
private bool ShouldDrawRightDownScrollIndicator () { return _host._tabLocations!.LastOrDefault () != _host.Tabs.LastOrDefault (); }
847904
}

0 commit comments

Comments
 (0)