Skip to content

Commit

Permalink
Changes from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
BobSilent committed Jan 28, 2022
1 parent 05b7517 commit 4732d14
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/Spectre.Console/Widgets/GridColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed class GridColumn : IColumn, IHasDirtyState

/// <summary>
/// Gets or sets the width of the column.
/// The interpretation of width depends on the value of <see cref="SizeMode"/>.<br/>
/// The interpretation of width depends on the value of <see cref="SizeMode"/>.
/// <br/>
/// By default it is set to <see langword="null"/>, and the column will size to its contents <see cref="SizeMode.SizeToContent"/>
/// is set to <see cref="SizeMode.SizeToContent" />.
Expand All @@ -44,9 +44,9 @@ public double? Width
/// <description><see cref="Width" /> value is interpreted as double and means proportional sizing. If the width value is <see langword="null"/> 1 is implied</description>
/// </item>
/// </list>
/// If mixed <see cref="SizeMode.SizeToContent" /> and <see cref="SizeMode.Fixed" /> widths with <see cref="SizeMode.Star" /> (proportional) widths:<br/>
/// If mixed <see cref="SizeMode.SizeToContent" /> and <see cref="SizeMode.Fixed" /> widths with <see cref="SizeMode.Star" /> (proportional) widths:
/// The <see cref="SizeMode.Star" /> columns are apportioned to the remainder after the <see cref="SizeMode.SizeToContent" /> and
/// <see cref="SizeMode.Fixed" /> widths have been calculated.<br/>
/// <see cref="SizeMode.Fixed" /> widths have been calculated.
/// </summary>
public SizeMode SizeMode
{
Expand Down
8 changes: 4 additions & 4 deletions src/Spectre.Console/Widgets/Table/TableColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed class TableColumn : IColumn

/// <summary>
/// Gets or sets the width of the column.
/// The interpretation of width depends on the value of <see cref="SizeMode"/>.<br/>
/// The interpretation of width depends on the value of <see cref="SizeMode"/>.
/// <br/>
/// By default it is set to <see langword="null"/>, and the column will size to its contents <see cref="SizeMode.SizeToContent"/>
/// is set to <see cref="SizeMode.SizeToContent" />.
Expand All @@ -37,12 +37,12 @@ public sealed class TableColumn : IColumn
/// </item>
/// <item>
/// <term><see cref="SizeMode.Star">Star (*)</see></term>
/// <description><see cref="Width" /> value is interpreted as double and means proportional sizing.</description>
/// <description><see cref="Width" /> value is interpreted as double and means proportional sizing. If the width value is <see langword="null"/> 1 is implied</description>
/// </item>
/// </list>
/// If mixed <see cref="SizeMode.SizeToContent" /> and <see cref="SizeMode.Fixed" /> widths with <see cref="SizeMode.Star" /> (proportional) widths:<br/>
/// If mixed <see cref="SizeMode.SizeToContent" /> and <see cref="SizeMode.Fixed" /> widths with <see cref="SizeMode.Star" /> (proportional) widths:
/// The <see cref="SizeMode.Star" /> columns are apportioned to the remainder after the <see cref="SizeMode.SizeToContent" /> and
/// <see cref="SizeMode.Fixed" /> widths have been calculated.<br/>
/// <see cref="SizeMode.Fixed" /> widths have been calculated.
/// </summary>
public SizeMode SizeMode { get; set; }

Expand Down
10 changes: 5 additions & 5 deletions src/Spectre.Console/Widgets/Table/TableMeasurer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public List<int> CalculateColumnWidths(int maxWidth)
widths = CollapseWidths(widths, wrappable, maxWidth);
tableWidth = widths.Sum();

// last resort, reduce columns evenly
// Last resort, reduce columns evenly
if (tableWidth > maxWidth)
{
var excessWidth = tableWidth - maxWidth;
Expand Down Expand Up @@ -96,19 +96,19 @@ internal Measurement[] MeasureColumns(int maxWidth)
}
}

// index and separate columns
// Index and separate columns
var indexColumns = Columns.Select((column, index) => (column, index)).ToList();
var fixedColumns = indexColumns.Where(x => x.column.SizeMode != SizeMode.Star);
var starColumns = indexColumns.Where(x => x.column.SizeMode == SizeMode.Star);

// first calculate fixed cells
// First calculate fixed cells
var fixedWidth_ranges = fixedColumns.Select(x => (x.index, measurement: MeasureColumn(x.column, maxWidth))).ToList();

// get remainder
// Get remainder
var consumedWidth = fixedWidth_ranges.Sum(x => x.measurement.Max);
var totalWidthForStar = Math.Max(0, maxWidth - consumedWidth);

// and apportioned to the remainder
// And apportioned to the remainder
var starWidth_ranges = MeasureStarColumns(starColumns, totalWidthForStar);
var width_ranges = fixedWidth_ranges.Concat(starWidth_ranges).OrderBy(x => x.Item1).Select(x => x.Item2);

Expand Down

0 comments on commit 4732d14

Please sign in to comment.