Browse Source

Fix some spelling and grammar issues.

pull/1517/head
walterlv 8 years ago
parent
commit
b09bd2f2f0
  1. 27
      src/Avalonia.Controls/Grid.cs
  2. 37
      src/Avalonia.Controls/Utils/GridLayout.cs

27
src/Avalonia.Controls/Grid.cs

@ -183,13 +183,13 @@ namespace Avalonia.Controls
} }
/// <summary> /// <summary>
/// Gets the result of last column measuring procedure. /// Gets the result of the last column measurement.
/// Use this result to reduce the arrange calculation. /// Use this result to reduce the arrange calculation.
/// </summary> /// </summary>
private GridLayout.MeasureResult _columnMeasureCache; private GridLayout.MeasureResult _columnMeasureCache;
/// <summary> /// <summary>
/// Gets the result of last row measuring procedure. /// Gets the result of the last row measurement.
/// Use this result to reduce the arrange calculation. /// Use this result to reduce the arrange calculation.
/// </summary> /// </summary>
private GridLayout.MeasureResult _rowMeasureCache; private GridLayout.MeasureResult _rowMeasureCache;
@ -202,8 +202,7 @@ namespace Avalonia.Controls
protected override Size MeasureOverride(Size constraint) protected override Size MeasureOverride(Size constraint)
{ {
// Situation 1/2: // Situation 1/2:
// If the grid doesn't have any column/row definitions, // If the grid doesn't have any column/row definitions, it behaves like a normal panel.
// it behaviors like a nomal panel.
// GridLayout supports this situation but we handle this separately for performance. // GridLayout supports this situation but we handle this separately for performance.
if (ColumnDefinitions.Count == 0 && RowDefinitions.Count == 0) if (ColumnDefinitions.Count == 0 && RowDefinitions.Count == 0)
@ -225,7 +224,7 @@ namespace Avalonia.Controls
// Situation 2/2: // Situation 2/2:
// If the grid defines some columns or rows. // If the grid defines some columns or rows.
// Debug Tip: // Debug Tip:
// - GridLayout doesn't hold any states, so you can drag the debugger execution // - GridLayout doesn't hold any state, so you can drag the debugger execution
// arrow back to any statements and re-run them without any side-effect. // arrow back to any statements and re-run them without any side-effect.
var measureCache = new Dictionary<Control, Size>(); var measureCache = new Dictionary<Control, Size>();
@ -236,11 +235,11 @@ namespace Avalonia.Controls
columnLayout.AppendMeasureConventions(safeColumns, child => MeasureOnce(child, constraint).Width); columnLayout.AppendMeasureConventions(safeColumns, child => MeasureOnce(child, constraint).Width);
rowLayout.AppendMeasureConventions(safeRows, child => MeasureOnce(child, constraint).Height); rowLayout.AppendMeasureConventions(safeRows, child => MeasureOnce(child, constraint).Height);
// Calculate for measuring result. // Calculate measurement.
var columnResult = columnLayout.Measure(constraint.Width); var columnResult = columnLayout.Measure(constraint.Width);
var rowResult = rowLayout.Measure(constraint.Height); var rowResult = rowLayout.Measure(constraint.Height);
// Use the measure result to measure the rest children. // Use the results of the measurement to measure the rest of the children.
foreach (var child in Children.OfType<Control>()) foreach (var child in Children.OfType<Control>())
{ {
var (column, columnSpan) = safeColumns[child]; var (column, columnSpan) = safeColumns[child];
@ -280,8 +279,7 @@ namespace Avalonia.Controls
protected override Size ArrangeOverride(Size finalSize) protected override Size ArrangeOverride(Size finalSize)
{ {
// Situation 1/2: // Situation 1/2:
// If the grid doesn't have any column/row definitions, // If the grid doesn't have any column/row definitions, it behaves like a normal panel.
// it behaviors like a nomal panel.
// GridLayout supports this situation but we handle this separately for performance. // GridLayout supports this situation but we handle this separately for performance.
if (ColumnDefinitions.Count == 0 && RowDefinitions.Count == 0) if (ColumnDefinitions.Count == 0 && RowDefinitions.Count == 0)
@ -297,14 +295,14 @@ namespace Avalonia.Controls
// Situation 2/2: // Situation 2/2:
// If the grid defines some columns or rows. // If the grid defines some columns or rows.
// Debug Tip: // Debug Tip:
// - GridLayout doesn't hold any states, so you can drag the debugger execution // - GridLayout doesn't hold any state, so you can drag the debugger execution
// arrow back to any statements and re-run them without any side-effect. // arrow back to any statements and re-run them without any side-effect.
var (safeColumns, safeRows) = GetSafeColumnRows(); var (safeColumns, safeRows) = GetSafeColumnRows();
var columnLayout = new GridLayout(ColumnDefinitions); var columnLayout = new GridLayout(ColumnDefinitions);
var rowLayout = new GridLayout(RowDefinitions); var rowLayout = new GridLayout(RowDefinitions);
// Calculate for arranging result. // Calculate for arrange result.
var columnResult = columnLayout.Arrange(finalSize.Width, _columnMeasureCache); var columnResult = columnLayout.Arrange(finalSize.Width, _columnMeasureCache);
var rowResult = rowLayout.Arrange(finalSize.Height, _rowMeasureCache); var rowResult = rowLayout.Arrange(finalSize.Height, _rowMeasureCache);
@ -339,8 +337,9 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Get the safe column/columnspan and safe row/rowspan. /// Get the safe column/columnspan and safe row/rowspan.
/// The result of this method ensure that none of the children has a column/row out of the definitions. /// This method ensures that none of the children has a column/row outside the bounds of the definitions.
/// </summary> /// </summary>
[Pure]
private (Dictionary<Control, (int index, int span)> safeColumns, private (Dictionary<Control, (int index, int span)> safeColumns,
Dictionary<Control, (int index, int span)> safeRows) GetSafeColumnRows() Dictionary<Control, (int index, int span)> safeRows) GetSafeColumnRows()
{ {
@ -357,9 +356,9 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Gets the safe row/column and rowspan/columnspan for a specified range. /// Gets the safe row/column and rowspan/columnspan for a specified range.
/// The user may assign the row/column properties out of the row count or column cout, this method helps to keep them in. /// The user may assign row/column properties outside the bounds of the row/column count, this method coerces them inside.
/// </summary> /// </summary>
/// <param name="length">The rows count or the columns count.</param> /// <param name="length">The row or column count.</param>
/// <param name="userIndex">The row or column that the user assigned.</param> /// <param name="userIndex">The row or column that the user assigned.</param>
/// <param name="userSpan">The rowspan or columnspan that the user assigned.</param> /// <param name="userSpan">The rowspan or columnspan that the user assigned.</param>
/// <returns>The safe row/column and rowspan/columnspan.</returns> /// <returns>The safe row/column and rowspan/columnspan.</returns>

37
src/Avalonia.Controls/Utils/GridLayout.cs

@ -16,7 +16,8 @@ namespace Avalonia.Controls.Utils
{ {
/// <summary> /// <summary>
/// Initialize a new <see cref="GridLayout"/> instance from the column definitions. /// Initialize a new <see cref="GridLayout"/> instance from the column definitions.
/// <see cref="GridLayout"/> will forget that the layout data comes from the columns. /// The instance doesn't care about whether the definitions are rows or columns.
/// It will not calculate the column or row differently.
/// </summary> /// </summary>
internal GridLayout([NotNull] ColumnDefinitions columns) internal GridLayout([NotNull] ColumnDefinitions columns)
{ {
@ -28,7 +29,8 @@ namespace Avalonia.Controls.Utils
/// <summary> /// <summary>
/// Initialize a new <see cref="GridLayout"/> instance from the row definitions. /// Initialize a new <see cref="GridLayout"/> instance from the row definitions.
/// <see cref="GridLayout"/> will forget that the layout data comes from the rows. /// The instance doesn't care about whether the definitions are rows or columns.
/// It will not calculate the column or row differently.
/// </summary> /// </summary>
internal GridLayout([NotNull] RowDefinitions rows) internal GridLayout([NotNull] RowDefinitions rows)
{ {
@ -46,6 +48,7 @@ namespace Avalonia.Controls.Utils
/// <summary> /// <summary>
/// Gets all the length conventions that come from column/row definitions. /// Gets all the length conventions that come from column/row definitions.
/// These conventions provide limitations of each grid cell. /// These conventions provide limitations of each grid cell.
/// Limitations: the expected pixel length, the min/max pixel length, the * count.
/// </summary> /// </summary>
[NotNull] [NotNull]
private readonly List<LengthConvention> _conventions; private readonly List<LengthConvention> _conventions;
@ -81,10 +84,10 @@ namespace Avalonia.Controls.Utils
if (getDesiredLength == null) throw new ArgumentNullException(nameof(getDesiredLength)); if (getDesiredLength == null) throw new ArgumentNullException(nameof(getDesiredLength));
// M1/7. Find all the Auto and * length columns/rows. // M1/7. Find all the Auto and * length columns/rows.
// Only these columns/rows' layout can be affected by the children desired size. // Only these columns/rows' layout can be affected by the child desired size.
// //
// Find all columns/rows that has the length Auto or *. We'll measure the children in advance. // Find all columns/rows that have Auto or * length. We'll measure the children in advance.
// Only these kind of columns/rows will affects the Grid layout. // Only these kind of columns/rows will affect the Grid layout.
// Please note: // Please note:
// - The columns/rows of Auto length will definitely be affected by the children size; // - The columns/rows of Auto length will definitely be affected by the children size;
// - However, only the Grid.DesiredSize can be affected by the *-length columns/rows unless the Grid has very much space (Infinitely). // - However, only the Grid.DesiredSize can be affected by the *-length columns/rows unless the Grid has very much space (Infinitely).
@ -99,8 +102,8 @@ namespace Avalonia.Controls.Utils
// 寻找所有行列范围中包含 Auto 和 * 的元素,使用全部可用尺寸提前测量。 // 寻找所有行列范围中包含 Auto 和 * 的元素,使用全部可用尺寸提前测量。
// 因为只有这部分元素的布局才会被 Grid 的子元素尺寸影响。 // 因为只有这部分元素的布局才会被 Grid 的子元素尺寸影响。
// 请注意: // 请注意:
// - Auto 长度的行列必定会受到子元素布局影响,会影响到行列的布局长度; // - Auto 长度的行列必定会受到子元素布局影响,会影响到行列的布局长度和 Grid 本身的 DesiredSize
// - 而对于 * 长度,一般只有 Grid.DesiredSize 会受到子元素布局影响,只有在 Grid 布局空间充足时行列长度才会被子元素布局影响。 // - 而对于 * 长度,只有 Grid.DesiredSize 会受到子元素布局影响,而行列长度不会受影响。
// Find all the Auto and * length columns/rows. // Find all the Auto and * length columns/rows.
var found = new Dictionary<T, (int index, int span)>(); var found = new Dictionary<T, (int index, int span)>();
@ -138,7 +141,7 @@ namespace Avalonia.Controls.Utils
/// The container length. Usually, it is the constraint of the <see cref="Layoutable.MeasureOverride"/> method. /// The container length. Usually, it is the constraint of the <see cref="Layoutable.MeasureOverride"/> method.
/// </param> /// </param>
/// <returns> /// <returns>
/// The measured result that containing the desired size and all the column/row length. /// The measured result that containing the desired size and all the column/row lengths.
/// </returns> /// </returns>
[NotNull, Pure] [NotNull, Pure]
internal MeasureResult Measure(double containerLength) internal MeasureResult Measure(double containerLength)
@ -149,7 +152,7 @@ namespace Avalonia.Controls.Utils
var aggregatedLength = 0.0; var aggregatedLength = 0.0;
double starUnitLength; double starUnitLength;
// M2/7. Aggregate all the pixel lengths. Then we can get the rest length by `containerLength - aggregatedLength`. // M2/7. Aggregate all the pixel lengths. Then we can get the remaining length by `containerLength - aggregatedLength`.
// We mark the aggregated length as "fix" because we can completely determine their values. Same as below. // We mark the aggregated length as "fix" because we can completely determine their values. Same as below.
// //
// +-----------------------------------------------------------+ // +-----------------------------------------------------------+
@ -176,7 +179,7 @@ namespace Avalonia.Controls.Utils
while (shouldTestStarMin) while (shouldTestStarMin)
{ {
// Calculate the unit * length to estimate the length of each column/row that has * length. // Calculate the unit * length to estimate the length of each column/row that has * length.
// Under this estimated length, look for if there is a minimum value that has a length less than its constraint. // Under this estimated length, check if there is a minimum value that has a length less than its constraint.
// If there is such a *, then fix the size of this cell, and then loop it again until there is no * that can be constrained by the minimum value. // If there is such a *, then fix the size of this cell, and then loop it again until there is no * that can be constrained by the minimum value.
// //
// 计算单位 * 的长度,以便预估出每一个 * 行列的长度。 // 计算单位 * 的长度,以便预估出每一个 * 行列的长度。
@ -245,7 +248,7 @@ namespace Avalonia.Controls.Utils
var desiredStarMin = AggregateAdditionalConventionsForStars(conventions); var desiredStarMin = AggregateAdditionalConventionsForStars(conventions);
aggregatedLength += desiredStarMin; aggregatedLength += desiredStarMin;
// M6/7. Determine the desired length of the grid for current container length. Its value stores in desiredLength. // M6/7. Determine the desired length of the grid for current container length. Its value is stored in desiredLength.
// Assume if the container has infinite length, the grid desired length is stored in greedyDesiredLength. // Assume if the container has infinite length, the grid desired length is stored in greedyDesiredLength.
// //
// +-----------------------------------------------------------+ // +-----------------------------------------------------------+
@ -370,7 +373,7 @@ namespace Avalonia.Controls.Utils
// 1. Determine all one-span column's desired widths or row's desired heights. // 1. Determine all one-span column's desired widths or row's desired heights.
// 2. Order the multi-span conventions by its last index // 2. Order the multi-span conventions by its last index
// (Notice that the sorting data source is much smaller than the original children source.) // (Notice that the sorting data source is much smaller than the original children source.)
// 3. Determin each multi-span last index by calculating the maximun desired size. // 3. Determine each multi-span last index by calculating the maximun desired size.
// Before we determine the behavior of this method, we just aggregate the one-span * columns. // Before we determine the behavior of this method, we just aggregate the one-span * columns.
@ -401,10 +404,10 @@ namespace Avalonia.Controls.Utils
} }
/// <summary> /// <summary>
/// This method implement the last procedure (M7/7) of measure. /// This method implements the last procedure (M7/7) of measure.
/// It expand all the * length to the fixed length according to the <paramref name="constraint"/>. /// It expands all the * length to the fixed length according to the <paramref name="constraint"/>.
/// </summary> /// </summary>
/// <param name="conventions">All the conventions that have almost been fixed except the rest *.</param> /// <param name="conventions">All the conventions that have almost been fixed except the remaining *.</param>
/// <param name="constraint">The container length.</param> /// <param name="constraint">The container length.</param>
/// <returns>The final pixel length list.</returns> /// <returns>The final pixel length list.</returns>
[Pure] [Pure]
@ -466,7 +469,7 @@ namespace Avalonia.Controls.Utils
/// We should clip the columns/rows that have been out of the container bounds. /// We should clip the columns/rows that have been out of the container bounds.
/// Note: This method may change the items value of <paramref name="lengthList"/>. /// Note: This method may change the items value of <paramref name="lengthList"/>.
/// </summary> /// </summary>
/// <param name="lengthList">All the column width list or the row height list with fixed pixel length.</param> /// <param name="lengthList">A list of all the column widths and row heights with a fixed pixel length</param>
/// <param name="constraint">the container length. It can be positive infinity.</param> /// <param name="constraint">the container length. It can be positive infinity.</param>
private static void Clip([NotNull] IList<double> lengthList, double constraint) private static void Clip([NotNull] IList<double> lengthList, double constraint)
{ {
@ -582,7 +585,7 @@ namespace Avalonia.Controls.Utils
/// <summary> /// <summary>
/// Contains the convention that comes from the grid children. /// Contains the convention that comes from the grid children.
/// Some child span multiple columns or rows, so even a simple column/row can have multiple conventions. /// Some children span multiple columns or rows, so even a simple column/row can have multiple conventions.
/// </summary> /// </summary>
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")] [DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
internal struct AdditionalLengthConvention internal struct AdditionalLengthConvention

Loading…
Cancel
Save