Skip to content

Commit c63b16f

Browse files
committed
Add TabsTextAlignment feature.
1 parent e012b2b commit c63b16f

File tree

4 files changed

+497
-1
lines changed

4 files changed

+497
-1
lines changed

Examples/UICatalog/Scenarios/TabViewExample.cs

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

2022
public override void Main ()
@@ -26,6 +28,7 @@ public override void Main ()
2628
Toplevel appWindow = new ();
2729

2830
_miTabsSide = SetTabsSide ();
31+
_miTabsTextAlignment = SetTabsTextAlignment ();
2932

3033
var menu = new MenuBar
3134
{
@@ -69,7 +72,12 @@ public override void Main ()
6972
"_Show TabView Border",
7073
"",
7174
ShowTabViewBorder
72-
) { Checked = true, CheckType = MenuItemCheckStyle.Checked }
75+
) { Checked = true, CheckType = MenuItemCheckStyle.Checked },
76+
null,
77+
_miTabsTextAlignment [0],
78+
_miTabsTextAlignment [1],
79+
_miTabsTextAlignment [2],
80+
_miTabsTextAlignment [3]
7381
}
7482
)
7583
]
@@ -283,6 +291,43 @@ private MenuItem [] SetTabsSide ()
283291
return menuItems.ToArray ();
284292
}
285293

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

Terminal.Gui/Views/TabView/TabStyle.cs

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

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

Terminal.Gui/Views/TabView/TabView.cs

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

740740
tab.Height = 2;
741+
tab.TextAlignment = Style.TabsTextAlignment;
741742

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

0 commit comments

Comments
 (0)