Browse Source

Part 6 of n

pull/2563/head
Jumar Macato 7 years ago
parent
commit
aea3bbcbd0
No known key found for this signature in database GPG Key ID: B19884DAC3A5BF3F
  1. 52
      src/Avalonia.Base/Utilities/MathUtilities.cs
  2. 8
      src/Avalonia.Controls/DefinitionBase.cs
  3. 81
      src/Avalonia.Controls/GridWPF.cs

52
src/Avalonia.Base/Utilities/MathUtilities.cs

@ -2,6 +2,7 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Runtime.InteropServices;
namespace Avalonia.Utilities
{
@ -12,17 +13,8 @@ namespace Avalonia.Utilities
{
/// <summary>
/// AreClose - Returns whether or not two doubles are "close". That is, whether or
/// not they are within epsilon of each other. Note that this epsilon is proportional
/// to the numbers themselves to that AreClose survives scalar multiplication.
/// There are plenty of ways for this to return false even for numbers which
/// are theoretically identical, so no code calling this should fail to work if this
/// returns false. This is important enough to repeat:
/// NB: NO CODE CALLING THIS FUNCTION SHOULD DEPEND ON ACCURATE RESULTS - this should be
/// used for optimizations *only*.
/// </summary>
/// <returns>
/// bool - the result of the AreClose comparision.
/// </returns>
/// not they are within epsilon of each other.
/// </summary>
/// <param name="value1"> The first double to compare. </param>
/// <param name="value2"> The second double to compare. </param>
public static bool AreClose(double value1, double value2)
@ -37,17 +29,7 @@ namespace Avalonia.Utilities
/// <summary>
/// LessThan - Returns whether or not the first double is less than the second double.
/// That is, whether or not the first is strictly less than *and* not within epsilon of
/// the other number. Note that this epsilon is proportional to the numbers themselves
/// to that AreClose survives scalar multiplication. Note,
/// There are plenty of ways for this to return false even for numbers which
/// are theoretically identical, so no code calling this should fail to work if this
/// returns false. This is important enough to repeat:
/// NB: NO CODE CALLING THIS FUNCTION SHOULD DEPEND ON ACCURATE RESULTS - this should be
/// used for optimizations *only*.
/// </summary>
/// <returns>
/// bool - the result of the LessThan comparision.
/// </returns>
/// the other number.
/// <param name="value1"> The first double to compare. </param>
/// <param name="value2"> The second double to compare. </param>
public static bool LessThan(double value1, double value2)
@ -55,15 +37,10 @@ namespace Avalonia.Utilities
return (value1 < value2) && !AreClose(value1, value2);
}
/// <summary>
/// GreaterThan - Returns whether or not the first double is greater than the second double.
/// That is, whether or not the first is strictly greater than *and* not within epsilon of
/// the other number. Note that this epsilon is proportional to the numbers themselves
/// to that AreClose survives scalar multiplication.
/// </summary>
/// <returns> - the result of the GreaterThan comparision.
/// </returns>
/// the other number.
/// <param name="value1"> The first double to compare. </param>
/// <param name="value2"> The second double to compare. </param>
public static bool GreaterThan(double value1, double value2)
@ -74,17 +51,7 @@ namespace Avalonia.Utilities
/// <summary>
/// LessThanOrClose - Returns whether or not the first double is less than or close to
/// the second double. That is, whether or not the first is strictly less than or within
/// epsilon of the other number. Note that this epsilon is proportional to the numbers
/// themselves to that AreClose survives scalar multiplication. Note,
/// There are plenty of ways for this to return false even for numbers which
/// are theoretically identical, so no code calling this should fail to work if this
/// returns false. This is important enough to repeat:
/// NB: NO CODE CALLING THIS FUNCTION SHOULD DEPEND ON ACCURATE RESULTS - this should be
/// used for optimizations *only*.
/// </summary>
/// <returns>
/// bool - the result of the LessThanOrClose comparision.
/// </returns>
/// epsilon of the other number.
/// <param name="value1"> The first double to compare. </param>
/// <param name="value2"> The second double to compare. </param>
public static bool LessThanOrClose(double value1, double value2)
@ -99,7 +66,6 @@ namespace Avalonia.Utilities
/// </summary>
/// <param name="value1"> The first double to compare. </param>
/// <param name="value2"> The second double to compare. </param>
/// <returns>the result of the GreaterThanOrClose comparision.</returns>
public static bool GreaterThanOrClose(double value1, double value2)
{
return (value1 > value2) || AreClose(value1, value2);
@ -109,9 +75,6 @@ namespace Avalonia.Utilities
/// IsOne - Returns whether or not the double is "close" to 1. Same as AreClose(double, 1),
/// but this is faster.
/// </summary>
/// <returns>
/// bool - the result of the AreClose comparision.
/// </returns>
/// <param name="value"> The double to compare to 1. </param>
public static bool IsOne(double value)
{
@ -122,9 +85,6 @@ namespace Avalonia.Utilities
/// IsZero - Returns whether or not the double is "close" to 0. Same as AreClose(double, 0),
/// but this is faster.
/// </summary>
/// <returns>
/// bool - the result of the AreClose comparision.
/// </returns>
/// <param name="value"> The double to compare to 0. </param>
public static bool IsZero(double value)
{

8
src/Avalonia.Controls/DefinitionBase.cs

@ -12,7 +12,7 @@ namespace Avalonia.Controls
/// <summary>
/// Base class for <see cref="ColumnDefinition"/> and <see cref="RowDefinition"/>.
/// </summary>
public class DefinitionBase : AvaloniaObject
public class DefinitionBase : ContentControl
{
/// <summary>
@ -307,7 +307,7 @@ namespace Avalonia.Controls
/// <summary>
/// Layout-time user size type.
/// </summary>
internal Grid.LayoutTimeSizeType SizeType
internal Grid.GridLayoutTimeSizeType SizeType
{
get { return (_sizeType); }
set { _sizeType = value; }
@ -333,7 +333,7 @@ namespace Avalonia.Controls
get
{
double preferredSize = MinSize;
if (_sizeType != Grid.LayoutTimeSizeType.Auto
if (_sizeType != Grid.GridLayoutTimeSizeType.Auto
&& preferredSize < _measureSize)
{
preferredSize = _measureSize;
@ -635,7 +635,7 @@ namespace Avalonia.Controls
private Flags _flags; // flags reflecting various aspects of internal state
private int _parentIndex; // this instance's index in parent's children collection
private Grid.LayoutTimeSizeType _sizeType; // layout-time user size type. it may differ from _userSizeValueCache.UnitType when calculating "to-content"
private Grid.GridLayoutTimeSizeType _sizeType; // layout-time user size type. it may differ from _userSizeValueCache.UnitType when calculating "to-content"
private double _minSize; // used during measure to accumulate size for "Auto" and "Star" DefinitionBase's
private double _measureSize; // size, calculated to be the input contstraint size for Child.Measure

81
src/Avalonia.Controls/GridWPF.cs

@ -56,6 +56,14 @@ namespace Avalonia.Controls
public static readonly AttachedProperty<bool> IsSharedSizeScopeProperty =
AvaloniaProperty.RegisterAttached<Grid, Control, bool>("IsSharedSizeScope", false);
/// <summary>
/// Defines the <see cref="ShowGridLines"/> property.
/// </summary>
public static readonly StyledProperty<bool> ShowGridLinesProperty =
AvaloniaProperty.Register<Grid, bool>(
nameof(ShowGridLines),
defaultValue: false);
/// <summary>
/// ShowGridLines property.
/// </summary>
@ -64,6 +72,7 @@ namespace Avalonia.Controls
get { return (CheckFlagsAnd(Flags.ShowGridLinesPropertyValue)); }
set { SetValue(ShowGridLinesProperty, value); }
}
private ColumnDefinitions _columnDefinitions;
private RowDefinitions _rowDefinitions;
@ -1135,10 +1144,10 @@ namespace Avalonia.Controls
// sanity check: totalRemainingSize and sizeToDistribute must be real positive numbers
Debug.Assert(!double.IsInfinity(totalRemainingSize)
&& !MathUtilities.IsNaN(totalRemainingSize)
&& !double.IsNaN(totalRemainingSize)
&& totalRemainingSize > 0
&& !double.IsInfinity(sizeToDistribute)
&& !MathUtilities.IsNaN(sizeToDistribute)
&& !double.IsNaN(sizeToDistribute)
&& sizeToDistribute > 0);
for (int i = 0; i < count; ++i)
@ -1163,15 +1172,6 @@ namespace Avalonia.Controls
}
}
/// <summary>
/// Resolves Star's for given array of definitions.
/// </summary>
/// <param name="definitions">Array of definitions to resolve stars.</param>
/// <param name="availableSize">All available size.</param>
/// <remarks>
/// Must initialize LayoutSize for all Star entries in given array of definitions.
/// </remarks>
// new implementation as of 4.7. Several improvements:
// 1. Allocate to *-defs hitting their min or max constraints, before allocating
// to other *-defs. A def that hits its min uses more space than its
@ -1186,6 +1186,14 @@ namespace Avalonia.Controls
// change in available space resulting in large change to one def's allocation.
// 3. Correct handling of large *-values, including Infinity.
/// <summary>
/// Resolves Star's for given array of definitions.
/// </summary>
/// <param name="definitions">Array of definitions to resolve stars.</param>
/// <param name="availableSize">All available size.</param>
/// <remarks>
/// Must initialize LayoutSize for all Star entries in given array of definitions.
/// </remarks>
private void ResolveStar(
DefinitionBase[] definitions,
double availableSize)
@ -2113,12 +2121,30 @@ namespace Avalonia.Controls
return (flags == 0 || (_flags & flags) != 0);
}
/// <summary>
/// <see cref="PropertyMetadata.PropertyChangedCallback"/>
/// </summary>
private static void OnShowGridLinesPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
private static int ValidateColumn(AvaloniaObject o, int value)
{
Grid grid = (Grid)d;
if (value < 0)
{
throw new ArgumentException("Invalid Grid.Column value.");
}
return value;
}
private static int ValidateRow(AvaloniaObject o, int value)
{
if (value < 0)
{
throw new ArgumentException("Invalid Grid.Row value.");
}
return value;
}
private static void OnShowGridLinesPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
var grid = e.Sender as Grid;
if (grid.ExtData != null // trivial grid is 1 by 1. there is no grid lines anyway
&& grid.ListenToNotifications)
@ -2129,12 +2155,9 @@ namespace Avalonia.Controls
grid.SetFlags((bool)e.NewValue, Flags.ShowGridLinesPropertyValue);
}
/// <summary>
/// <see cref="PropertyMetadata.PropertyChangedCallback"/>
/// </summary>
private static void OnCellAttachedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
private static void OnCellAttachedPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
Visual child = d as Visual;
var child = e.Sender as Visual;
if (child != null)
{
@ -2149,22 +2172,6 @@ namespace Avalonia.Controls
}
}
/// <summary>
/// <see cref="DependencyProperty.ValidateValueCallback"/>
/// </summary>
private static bool IsIntValueNotNegative(object value)
{
return ((int)value >= 0);
}
/// <summary>
/// <see cref="DependencyProperty.ValidateValueCallback"/>
/// </summary>
private static bool IsIntValueGreaterThanZero(object value)
{
return ((int)value > 0);
}
/// <summary>
/// Helper for Comparer methods.
/// </summary>

Loading…
Cancel
Save