TableView - adds last column dividing line (#1289)

* Adds a final vertical column line at the end of the last header in TableView

* Added clear line as first step in RenderRow

* Added TableStyle.EnforceMaxWidthOnLastColumn

* Added Scenario toggle setting and tests

* Fixed EnforceMaxWidthOnLastColumn when Bounds match exactly the last column width

* Fixed whitespace and comment on ColumntoRender.Width

* Renamed EnforceMaxWidthOnLastColumn to ExpandLastColumn
This commit is contained in:
Thomas Nind
2021-05-11 04:58:15 +01:00
committed by GitHub
parent 93d76b1a64
commit 0dd0f2e5c4
3 changed files with 158 additions and 33 deletions

View File

@@ -418,7 +418,92 @@ namespace Terminal.Gui.Views {
Assert.Equal(new Point(8,3),selected[5]);
}
/// <summary>
[Fact]
public void TableView_ExpandLastColumn_True()
{
var tv = SetUpMiniTable();
// the thing we are testing
tv.Style.ExpandLastColumn = true;
tv.Redraw(tv.Bounds);
string expected = @"
┌─┬──────┐
│A│B │
├─┼──────┤
│1│2 │
";
GraphViewTests.AssertDriverContentsAre(expected);
}
[Fact]
public void TableView_ExpandLastColumn_False()
{
var tv = SetUpMiniTable();
// the thing we are testing
tv.Style.ExpandLastColumn = false;
tv.Redraw(tv.Bounds);
string expected = @"
┌─┬─┬────┐
│A│B│ │
├─┼─┼────┤
│1│2│ │
";
GraphViewTests.AssertDriverContentsAre(expected);
}
[Fact]
public void TableView_ExpandLastColumn_False_ExactBounds()
{
var tv = SetUpMiniTable();
// the thing we are testing
tv.Style.ExpandLastColumn = false;
// width exactly matches the max col widths
tv.Bounds = new Rect(0,0,5,4);
tv.Redraw(tv.Bounds);
string expected = @"
┌─┬─┐
│A│B│
├─┼─┤
│1│2│
";
GraphViewTests.AssertDriverContentsAre(expected);
}
private TableView SetUpMiniTable ()
{
var tv = new TableView();
tv.Bounds = new Rect(0,0,10,4);
var dt = new DataTable();
var colA = dt.Columns.Add("A");
var colB = dt.Columns.Add("B");
dt.Rows.Add(1,2);
tv.Table = dt;
tv.Style.GetOrCreateColumnStyle(colA).MinWidth=1;
tv.Style.GetOrCreateColumnStyle(colA).MinWidth=1;
tv.Style.GetOrCreateColumnStyle(colB).MaxWidth=1;
tv.Style.GetOrCreateColumnStyle(colB).MaxWidth=1;
GraphViewTests.InitFakeDriver();
tv.ColorScheme = new ColorScheme(){
Normal = Application.Driver.MakeAttribute(Color.White,Color.Black),
HotFocus = Application.Driver.MakeAttribute(Color.White,Color.Black)
};
return tv;
}
/// <summary>
/// Builds a simple table of string columns with the requested number of columns and rows
/// </summary>
/// <param name="cols"></param>