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 d5a32d5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Spectre.Console/Extensions/ColumnExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static T NoWrap<T>(this T obj)
/// </summary>
/// <typeparam name="T">An object implementing <see cref="IColumn"/>.</typeparam>
/// <param name="obj">The column.</param>
/// <param name="size">The column width.</param>
/// <param name="size">The column fixed width.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static T FixWidth<T>(this T obj, int size)
where T : class, IColumn
Expand All @@ -53,7 +53,7 @@ public static T FixWidth<T>(this T obj, int size)
/// </summary>
/// <typeparam name="T">An object implementing <see cref="IColumn"/>.</typeparam>
/// <param name="obj">The column.</param>
/// <param name="weight">The column width.</param>
/// <param name="weight">The column weighted width.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static T StarWidth<T>(this T obj, double weight = 1.0)
where T : class, IColumn
Expand Down
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 d5a32d5

Please sign in to comment.