Skip to content

Fixes #3875. Add left and right tab sides with alignments to the TabView. #3876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 18 commits into
base: v2_develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 91 additions & 14 deletions Examples/UICatalog/Scenarios/TabViewExample.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Linq;
using System.Text;
using System.Text;

namespace UICatalog.Scenarios;

Expand All @@ -11,7 +10,10 @@ public class TabViewExample : Scenario
private MenuItem _miShowBorder;
private MenuItem _miShowTabViewBorder;
private MenuItem _miShowTopLine;
private MenuItem _miTabsOnBottom;
private MenuItem [] _miTabsSide;
private MenuItem _cachedTabsSide;
private MenuItem [] _miTabsTextAlignment;
private MenuItem _cachedTabsTextAlignment;
private TabView _tabView;

public override void Main ()
Expand All @@ -22,6 +24,9 @@ public override void Main ()
// Setup - Create a top-level application window and configure it.
Toplevel appWindow = new ();

_miTabsSide = SetTabsSide ();
_miTabsTextAlignment = SetTabsTextAlignment ();

var menu = new MenuBar
{
Menus =
Expand Down Expand Up @@ -53,17 +58,23 @@ public override void Main ()
{
Checked = true, CheckType = MenuItemCheckStyle.Checked
},
_miTabsOnBottom =
new ("_Tabs On Bottom", "", SetTabsOnBottom)
{
Checked = false, CheckType = MenuItemCheckStyle.Checked
},
null,
_miTabsSide [0],
_miTabsSide [1],
_miTabsSide [2],
_miTabsSide [3],
null,
_miShowTabViewBorder =
new (
"_Show TabView Border",
"",
ShowTabViewBorder
) { Checked = true, CheckType = MenuItemCheckStyle.Checked }
) { Checked = true, CheckType = MenuItemCheckStyle.Checked },
null,
_miTabsTextAlignment [0],
_miTabsTextAlignment [1],
_miTabsTextAlignment [2],
_miTabsTextAlignment [3]
}
)
]
Expand Down Expand Up @@ -240,12 +251,78 @@ private View GetInteractiveTab ()

private void Quit () { Application.RequestStop (); }

private void SetTabsOnBottom ()
private MenuItem [] SetTabsSide ()
{
_miTabsOnBottom.Checked = !_miTabsOnBottom.Checked;
List<MenuItem> menuItems = [];

_tabView.Style.TabsOnBottom = (bool)_miTabsOnBottom.Checked;
_tabView.ApplyStyleChanges ();
foreach (TabSide side in Enum.GetValues (typeof (TabSide)))
{
string sideName = Enum.GetName (typeof (TabSide), side);
var item = new MenuItem { Title = $"_{sideName}", Data = side };
item.CheckType |= MenuItemCheckStyle.Radio;

item.Action += () =>
{
if (_cachedTabsSide == item)
{
return;
}

_cachedTabsSide.Checked = false;
item.Checked = true;
_cachedTabsSide = item;
_tabView.Style.TabsSide = (TabSide)item.Data;
_tabView.ApplyStyleChanges ();
};
item.ShortcutKey = ((Key)sideName! [0].ToString ().ToLower ()).WithCtrl;

if (sideName == "Top")
{
item.Checked = true;
_cachedTabsSide = item;
}

menuItems.Add (item);
}

return menuItems.ToArray ();
}

private MenuItem [] SetTabsTextAlignment ()
{
List<MenuItem> menuItems = [];

foreach (TabSide align in Enum.GetValues (typeof (Alignment)))
{
string alignName = Enum.GetName (typeof (Alignment), align);
var item = new MenuItem { Title = $"_{alignName}", Data = align };
item.CheckType |= MenuItemCheckStyle.Radio;

item.Action += () =>
{
if (_cachedTabsTextAlignment == item)
{
return;
}

_cachedTabsTextAlignment.Checked = false;
item.Checked = true;
_cachedTabsTextAlignment = item;
_tabView.Style.TabsTextAlignment = (Alignment)item.Data;
_tabView.ApplyStyleChanges ();
};
item.ShortcutKey = ((Key)alignName! [0].ToString ().ToLower ()).WithCtrl;

if (alignName == "Start")
{
item.Checked = true;
_cachedTabsTextAlignment = item;
}

menuItems.Add (item);
}

return menuItems.ToArray ();
}

private void ShowBorder ()
Expand All @@ -270,7 +347,7 @@ private void ShowTopLine ()
{
_miShowTopLine.Checked = !_miShowTopLine.Checked;

_tabView.Style.ShowTopLine = (bool)_miShowTopLine.Checked;
_tabView.Style.ShowInitialLine = (bool)_miShowTopLine.Checked;
_tabView.ApplyStyleChanges ();
}
}
6 changes: 6 additions & 0 deletions Terminal.Gui/Views/TabView/Tab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ public string DisplayText
set
{
_displayText = value;
DisplayTextChanged?.Invoke (this, EventArgs.Empty);
SetNeedsLayout ();
}
}

/// <summary>The control to display when the tab is selected.</summary>
/// <value></value>
public View? View { get; set; }

/// <summary>
/// Raised when <see cref="DisplayText"/> changed.
/// </summary>
public event EventHandler? DisplayTextChanged;
}
Loading
Loading