From 04d3aba291afb84276356e96a3d216a59c252328 Mon Sep 17 00:00:00 2001 From: tznind Date: Tue, 4 Apr 2023 05:37:48 +0100 Subject: [PATCH] Fixed rendering empty space when using cell specific styles --- Terminal.Gui/Views/TableView.cs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/Terminal.Gui/Views/TableView.cs b/Terminal.Gui/Views/TableView.cs index 06bce3571..35b93ad13 100644 --- a/Terminal.Gui/Views/TableView.cs +++ b/Terminal.Gui/Views/TableView.cs @@ -640,7 +640,7 @@ namespace Terminal.Gui { private string TruncateOrPad (object originalCellValue, string representation, int availableHorizontalSpace, ColumnStyle colStyle) { if (string.IsNullOrEmpty (representation)) - return representation; + return new string(' ',availableHorizontalSpace); // if value is not wide enough if (representation.Sum (c => Rune.ColumnWidth (c)) < availableHorizontalSpace) { @@ -1493,9 +1493,11 @@ namespace Terminal.Gui { /// private IEnumerable CalculateViewport (Rect bounds, int padding = 1) { - if (TableIsNullOrInvisible ()) - yield break; + if (TableIsNullOrInvisible ()) { + return Enumerable.Empty (); + } + var toReturn = new List (); int usedSpace = 0; //if horizontal space is required at the start of the line (before the first header) @@ -1557,13 +1559,19 @@ namespace Terminal.Gui { usedSpace += colWidth; + // required for if we end up here because first == true i.e. we have a single massive width (overspilling bounds) column to present + colWidth = Math.Min (availableHorizontalSpace, colWidth); + var isVeryLast = lastColumn == col; + // there is space - yield return new ColumnToRender (col, startingIdxForCurrentHeader, - // required for if we end up here because first == true i.e. we have a single massive width (overspilling bounds) column to present - Math.Min (availableHorizontalSpace, colWidth), - lastColumn == col); + toReturn.Add(new ColumnToRender (col, startingIdxForCurrentHeader, colWidth, isVeryLast)); first = false; } + + var last = toReturn.Last (); + last.Width = Math.Max (last.Width, availableHorizontalSpace - last.X); + + return toReturn; } private bool ShouldRenderHeaders () @@ -1876,7 +1884,7 @@ namespace Terminal.Gui { /// The width that the column should occupy as calculated by . Note that this includes /// space for padding i.e. the separator between columns. /// - public int Width { get; } + public int Width { get; internal set; } /// /// True if this column is the very last column in the (not just the last visible column)