Skip to content
Merged
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
4 changes: 4 additions & 0 deletions Examples/UICatalog/Scenarios/TableViewTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public override void Main ()
("ShowVerticalHeaderLines", () => tableView.Style.ShowVerticalHeaderLines, b => tableView.Style.ShowVerticalHeaderLines = b),
("ShowHorizontalHeaderUnderline", () => tableView.Style.ShowHorizontalHeaderUnderline, b => tableView.Style.ShowHorizontalHeaderUnderline = b),
("ShowVerticalCellLines", () => tableView.Style.ShowVerticalCellLines, b => tableView.Style.ShowVerticalCellLines = b),
("ShowVerticalCellLineForFirstColumn", () => tableView.Style.ShowVerticalCellLineForFirstColumn,
b => tableView.Style.ShowVerticalCellLineForFirstColumn = b),
("ShowVerticalCellLineForLastColumn", () => tableView.Style.ShowVerticalCellLineForLastColumn,
b => tableView.Style.ShowVerticalCellLineForLastColumn = b),
("InvertSelectedCellFirstCharacter", () => tableView.Style.InvertSelectedCellFirstCharacter,
b => tableView.Style.InvertSelectedCellFirstCharacter = b),
("ShowHorizontalBottomline", () => tableView.Style.ShowHorizontalBottomLine, b => tableView.Style.ShowHorizontalBottomLine = b),
Expand Down
6 changes: 4 additions & 2 deletions Terminal.Gui/Views/FileDialogs/FileDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,10 @@ internal FileDialog (IFileSystem? fileSystem)
_tableViewContainer.Add (_tableView);

_tableView.Style.ShowHorizontalHeaderOverline = false;
_tableView.Style.ShowVerticalCellLines = false;
_tableView.Style.ShowVerticalHeaderLines = false;
_tableView.Style.ShowVerticalCellLines = true;
_tableView.Style.ShowVerticalCellLineForFirstColumn = false;
_tableView.Style.ShowVerticalCellLineForLastColumn = false;
_tableView.Style.ShowVerticalHeaderLines = true;
_tableView.Style.AlwaysShowHeaders = true;
_tableView.Style.ShowHorizontalHeaderUnderline = false;
_tableView.Style.ShowHorizontalBottomLine = false;
Expand Down
12 changes: 12 additions & 0 deletions Terminal.Gui/Views/TableView/TableStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ public class TableStyle
/// <summary>True to render a solid line vertical line between cells</summary>
public bool ShowVerticalCellLines { get; set; } = true;

/// <summary>
/// Gets or sets whether the left-most visible column renders a vertical line on its left side when vertical
/// lines are enabled.
/// </summary>
public bool ShowVerticalCellLineForFirstColumn { get; set; } = true;

/// <summary>
/// Gets or sets whether the right-most visible column renders a vertical line on its right side when vertical
/// lines are enabled.
/// </summary>
public bool ShowVerticalCellLineForLastColumn { get; set; } = true;

/// <summary>True to render a solid line vertical line between headers</summary>
public bool ShowVerticalHeaderLines { get; set; } = true;

Expand Down
33 changes: 26 additions & 7 deletions Terminal.Gui/Views/TableView/TableView.Content.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ public void EnsureValidScrollOffsets ()
{
int headerHeight = GetHeaderHeightIfAny ();
int headerHeightVisible = CurrentHeaderHeightVisible ();
int leftOuterBorderWidth = ShouldRenderFirstOuterVerticalLine () ? 1 : 0;
int rightOuterBorderWidth = ShouldRenderLastOuterVerticalLine () ? 1 : 0;
contentSize.Height += headerHeight + Table?.Rows ?? 0;

if (Style.ShowHorizontalBottomLine)
Expand Down Expand Up @@ -200,8 +202,7 @@ public void EnsureValidScrollOffsets ()
reservedFromIndex [i] = minWidths [i] + separator + reservedFromIndex [i + 1];
}

//right border
contentSize.Width += Style.ShowVerticalHeaderLines || Style.ShowVerticalCellLines ? 1 : 0;
contentSize.Width += leftOuterBorderWidth;

var startRow = 0;
int rowsToRender = Table.Rows;
Expand Down Expand Up @@ -238,7 +239,7 @@ public void EnsureValidScrollOffsets ()
if (isVeryLast)
{
//remaining space for last column
int remainingSpace = Viewport.Width - contentSize.Width - (Style.ShowVerticalHeaderLines || Style.ShowVerticalCellLines ? 1 : 0);
int remainingSpace = Viewport.Width - contentSize.Width - rightOuterBorderWidth;

if (Style.ExpandLastColumn && colWidth < remainingSpace)
{
Expand All @@ -250,8 +251,7 @@ public void EnsureValidScrollOffsets ()
// Reserve at least the header width for each subsequent visible column so that a wide
// column does not consume all viewport space and push later columns off-screen.
int reservedForRemaining = reservedFromIndex [columnIndex + 1];
int borderWidth = Style.ShowVerticalHeaderLines || Style.ShowVerticalCellLines ? 1 : 0;
int availableForThisCol = Viewport.Width - contentSize.Width - reservedForRemaining - borderWidth - 1; // -1 for this column's separator
int availableForThisCol = Viewport.Width - contentSize.Width - reservedForRemaining - rightOuterBorderWidth - 1; // -1 for this column's separator

// Don't shrink below this column's own minimum (header width or configured minimum)
int thisColMin = minWidths [columnIndex];
Expand All @@ -275,8 +275,7 @@ public void EnsureValidScrollOffsets ()
columnIndex++;
}

// for left border
contentSize.Width += Style.ShowVerticalHeaderLines || Style.ShowVerticalCellLines ? 1 : 0;
contentSize.Width += rightOuterBorderWidth;
}
else
{
Expand Down Expand Up @@ -349,4 +348,24 @@ private int MinimumWidthFor (int colIdx, ColumnStyle? colStyle)

return min;
}

private bool ShouldRenderFirstOuterVerticalLine ()
{
if (!Style.ShowVerticalCellLineForFirstColumn)
{
return false;
}

return Style.ShowVerticalHeaderLines || Style.ShowVerticalCellLines;
}

private bool ShouldRenderLastOuterVerticalLine ()
{
if (!Style.ShowVerticalCellLineForLastColumn)
{
return false;
}

return Style.ShowVerticalHeaderLines || Style.ShowVerticalCellLines;
}
}
58 changes: 42 additions & 16 deletions Terminal.Gui/Views/TableView/TableView.Drawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ private void RenderBottomLine (int row, int availableWidth, ColumnToRender [] co
{
// Renders a line at the bottom of the table after all the data like:
// └─────────────────────────────────┴──────────┴──────┴──────────┴────────┴────────────────────────────────────────────┘
bool renderFirstOuterVerticalLine = Style.ShowVerticalCellLines && Style.ShowVerticalCellLineForFirstColumn;
bool renderLastOuterVerticalLine = Style.ShowVerticalCellLines && Style.ShowVerticalCellLineForLastColumn;

for (var c = 0; c < availableWidth; c++)
{
// Start by assuming we just draw a straight line the
Expand All @@ -195,8 +198,10 @@ private void RenderBottomLine (int row, int availableWidth, ColumnToRender [] co
{
if (c == 0)
{
// for first character render line
rune = Glyphs.LLCorner;
if (renderFirstOuterVerticalLine)
{
rune = Glyphs.LLCorner;
}
}
else if (columnsToRender.Any (r => r.X == c + 1))
{
Expand All @@ -205,8 +210,10 @@ private void RenderBottomLine (int row, int availableWidth, ColumnToRender [] co
}
else if (c == availableWidth - 1)
{
// for the last character in the table
rune = Glyphs.LRCorner;
if (renderLastOuterVerticalLine)
{
rune = Glyphs.LRCorner;
}
}
else if (!Style.ExpandLastColumn && columnsToRender.Any (r => r.IsVeryLast && r.X + r.Width - 1 == c))
{
Expand Down Expand Up @@ -234,7 +241,7 @@ private void RenderHeaderMidline (int row, int availableWidth, ColumnToRender []
ClearLine (row, Viewport.Width);

// render start of line
if (_style.ShowVerticalHeaderLines)
if (_style.ShowVerticalHeaderLines && Style.ShowVerticalCellLineForFirstColumn)
{
RenderRune (0, row, Glyphs.VLine);
}
Expand All @@ -259,7 +266,7 @@ private void RenderHeaderMidline (int row, int availableWidth, ColumnToRender []
Move (current.X - Viewport.X, row);
AddStr (TruncateOrPad (colName, colName, current.Width, colStyle));

if (!Style.ExpandLastColumn && current.IsVeryLast)
if (!Style.ExpandLastColumn && current.IsVeryLast && Style.ShowVerticalCellLineForLastColumn)
{
SetAttribute (GetAttributeForRole (VisualRole.Normal));
RenderSeparator (current.X + current.Width - 1, row, true);
Expand All @@ -270,7 +277,7 @@ private void RenderHeaderMidline (int row, int availableWidth, ColumnToRender []
SetAttribute (GetAttributeForRole (VisualRole.Normal));

// render end of line
if (_style.ShowVerticalHeaderLines)
if (_style.ShowVerticalHeaderLines && Style.ShowVerticalCellLineForLastColumn)
{
RenderRune (availableWidth - 1, row, Glyphs.VLine);
}
Expand All @@ -280,6 +287,9 @@ private void RenderHeaderOverline (int row, int availableWidth, ColumnToRender [
{
// Renders a line above table headers (when visible) like:
// ┌────────────────────┬──────────┬───────────┬──────────────┬─────────┐
bool renderFirstOuterVerticalLine = Style.ShowVerticalHeaderLines && Style.ShowVerticalCellLineForFirstColumn;
bool renderLastOuterVerticalLine = Style.ShowVerticalHeaderLines && Style.ShowVerticalCellLineForLastColumn;

for (var c = 0; c < availableWidth; c++)
{
Rune rune = Glyphs.HLine;
Expand All @@ -288,7 +298,10 @@ private void RenderHeaderOverline (int row, int availableWidth, ColumnToRender [
{
if (c == 0)
{
rune = Glyphs.ULCorner;
if (renderFirstOuterVerticalLine)
{
rune = Glyphs.ULCorner;
}
}

// if the next column is the start of a header
Expand All @@ -298,7 +311,10 @@ private void RenderHeaderOverline (int row, int availableWidth, ColumnToRender [
}
else if (c == availableWidth - 1)
{
rune = Glyphs.URCorner;
if (renderLastOuterVerticalLine)
{
rune = Glyphs.URCorner;
}
}

// if the next console column is the last column's end
Expand All @@ -322,6 +338,9 @@ private void RenderHeaderUnderline (int row, int availableWidth, ColumnToRender
*/
// Renders a line below the table headers (when visible) like:
// ├──────────┼───────────┼───────────────────┼──────────┼────────┼─────────────┤
bool renderFirstOuterVerticalLine = Style.ShowVerticalHeaderLines && Style.ShowVerticalCellLineForFirstColumn;
bool renderLastOuterVerticalLine = Style.ShowVerticalHeaderLines && Style.ShowVerticalCellLineForLastColumn;

for (var c = 0; c < availableWidth; c++)
{
// Start by assuming we just draw a straight line the
Expand All @@ -333,8 +352,10 @@ private void RenderHeaderUnderline (int row, int availableWidth, ColumnToRender
{
if (c == 0)
{
// for first character render line
rune = Style.ShowVerticalCellLines ? Glyphs.LeftTee : Glyphs.LLCorner;
if (renderFirstOuterVerticalLine)
{
rune = Style.ShowVerticalCellLines ? Glyphs.LeftTee : Glyphs.LLCorner;
}
}

// if the next column is the start of a header
Expand All @@ -344,8 +365,10 @@ private void RenderHeaderUnderline (int row, int availableWidth, ColumnToRender
}
else if (c == availableWidth - 1)
{
// for the last character in the table
rune = Style.ShowVerticalCellLines ? Glyphs.RightTee : Glyphs.LRCorner;
if (renderLastOuterVerticalLine)
{
rune = Style.ShowVerticalCellLines ? Glyphs.RightTee : Glyphs.LRCorner;
}
}

// if the next console column is the last column's end
Expand Down Expand Up @@ -446,7 +469,7 @@ private void RenderRow (int row, int rowToRender, ColumnToRender [] columnsToRen

RenderSeparator (current.X - 1, row, false);

if (!Style.ExpandLastColumn && current.IsVeryLast)
if (!Style.ExpandLastColumn && current.IsVeryLast && Style.ShowVerticalCellLineForLastColumn)
{
RenderSeparator (current.X + current.Width - 1, row, false);
}
Expand Down Expand Up @@ -477,11 +500,14 @@ private void RenderRow (int row, int rowToRender, ColumnToRender [] columnsToRen
SetAttribute (rowScheme.Normal);

// render start and end of line
RenderRune (0, row, Glyphs.VLine);
if (Style.ShowVerticalCellLineForFirstColumn)
{
RenderRune (0, row, Glyphs.VLine);
}

ColumnToRender? lastCol = columnsToRender.LastOrDefault ();

if (lastCol != null)
if (lastCol != null && Style.ShowVerticalCellLineForLastColumn)
{
RenderRune (lastCol.X + lastCol.Width - 1, row, Glyphs.VLine);
}
Expand Down
17 changes: 17 additions & 0 deletions Tests/UnitTestsParallelizable/Views/FileDialogResultTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copilot

using System.Reflection;
using System.IO.Abstractions.TestingHelpers;

namespace UnitTests.Views;
Expand Down Expand Up @@ -153,6 +154,22 @@ public void FileDialog_Cancel_ClearsResult_WhenPreviouslyAccepted ()
Assert.True (sd.Canceled);
}

[Fact]
public void OpenDialog_UsesInnerTableSeparatorsWithoutOuterBorders ()
{
using OpenDialog od = new TestableOpenDialog ();

FieldInfo? tableViewField = typeof (FileDialog).GetField ("_tableView", BindingFlags.Instance | BindingFlags.NonPublic);
Assert.NotNull (tableViewField);

TableView tableView = Assert.IsType<TableView> (tableViewField!.GetValue (od));

Assert.True (tableView.Style.ShowVerticalCellLines);
Assert.True (tableView.Style.ShowVerticalHeaderLines);
Assert.False (tableView.Style.ShowVerticalCellLineForFirstColumn);
Assert.False (tableView.Style.ShowVerticalCellLineForLastColumn);
}

/// <summary>Testable subclass that exposes the internal file-system constructor.</summary>
private sealed class TestableFileDialog : FileDialog
{
Expand Down
Loading
Loading