Skip to content

Commit 97c2d52

Browse files
committed
Add TabsTextAlignment feature.
1 parent 43c83ee commit 97c2d52

File tree

4 files changed

+497
-1
lines changed

4 files changed

+497
-1
lines changed

Terminal.Gui/Views/TabView/TabStyle.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ public class TabStyle
2020

2121
/// <summary>Gets or sets the tabs side to render.</summary>
2222
public TabSide TabsSide { get; set; }
23+
24+
/// <summary>
25+
/// Gets or sets the tabs text alignments.
26+
/// </summary>
27+
public Alignment TabsTextAlignment { get; set; }
2328
}

Terminal.Gui/Views/TabView/TabView.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ protected override void Dispose (bool disposing)
643643
int maxHeight = Math.Max (0, Math.Min (bounds.Height - 2, 2));
644644

645645
tab.Height = 2;
646+
tab.TextAlignment = Style.TabsTextAlignment;
646647

647648
// if tab view is height <= 3 don't render any tabs
648649
if (maxHeight == 0)

UICatalog/Scenarios/TabViewExample.cs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class TabViewExample : Scenario
1616
private MenuItem _miShowTopLine;
1717
private MenuItem [] _miTabsSide;
1818
private MenuItem _cachedTabsSide;
19+
private MenuItem [] _miTabsTextAlignment;
20+
private MenuItem _cachedTabsTextAlignment;
1921
private TabView _tabView;
2022

2123
public override void Main ()
@@ -27,6 +29,7 @@ public override void Main ()
2729
Toplevel appWindow = new ();
2830

2931
_miTabsSide = SetTabsSide ();
32+
_miTabsTextAlignment = SetTabsTextAlignment ();
3033

3134
var menu = new MenuBar
3235
{
@@ -70,7 +73,12 @@ public override void Main ()
7073
"_Show TabView Border",
7174
"",
7275
ShowTabViewBorder
73-
) { Checked = true, CheckType = MenuItemCheckStyle.Checked }
76+
) { Checked = true, CheckType = MenuItemCheckStyle.Checked },
77+
null,
78+
_miTabsTextAlignment [0],
79+
_miTabsTextAlignment [1],
80+
_miTabsTextAlignment [2],
81+
_miTabsTextAlignment [3]
7482
}
7583
)
7684
]
@@ -284,6 +292,43 @@ private MenuItem [] SetTabsSide ()
284292
return menuItems.ToArray ();
285293
}
286294

295+
private MenuItem [] SetTabsTextAlignment ()
296+
{
297+
List<MenuItem> menuItems = [];
298+
299+
foreach (TabSide align in Enum.GetValues (typeof (Alignment)))
300+
{
301+
string alignName = Enum.GetName (typeof (Alignment), align);
302+
var item = new MenuItem { Title = $"_{alignName}", Data = align };
303+
item.CheckType |= MenuItemCheckStyle.Radio;
304+
305+
item.Action += () =>
306+
{
307+
if (_cachedTabsTextAlignment == item)
308+
{
309+
return;
310+
}
311+
312+
_cachedTabsTextAlignment.Checked = false;
313+
item.Checked = true;
314+
_cachedTabsTextAlignment = item;
315+
_tabView.Style.TabsTextAlignment = (Alignment)item.Data;
316+
_tabView.ApplyStyleChanges ();
317+
};
318+
item.ShortcutKey = ((Key)alignName! [0].ToString ().ToLower ()).WithCtrl;
319+
320+
if (alignName == "Start")
321+
{
322+
item.Checked = true;
323+
_cachedTabsTextAlignment = item;
324+
}
325+
326+
menuItems.Add (item);
327+
}
328+
329+
return menuItems.ToArray ();
330+
}
331+
287332
private void ShowBorder ()
288333
{
289334
_miShowBorder.Checked = !_miShowBorder.Checked;

0 commit comments

Comments
 (0)