Browse Source

Make GritSplitter calculations match the ones in WPF.

pull/5767/head
Dariusz Komosinski 5 years ago
parent
commit
3ac615c4e3
  1. 15
      src/Avalonia.Base/Utilities/MathUtilities.cs
  2. 4
      src/Avalonia.Controls/GridSplitter.cs
  3. 6
      src/Avalonia.Layout/LayoutHelper.cs

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

@ -30,6 +30,21 @@ namespace Avalonia.Utilities
return (-eps < delta) && (eps > delta);
}
/// <summary>
/// AreClose - Returns whether or not two doubles are "close". That is, whether or
/// 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>
/// <param name="eps"> The fixed epsilon value used to compare.</param>
public static bool AreClose(double value1, double value2, double eps)
{
//in case they are Infinities (then epsilon check does not work)
if (value1 == value2) return true;
double delta = value1 - value2;
return (-eps < delta) && (eps > delta);
}
/// <summary>
/// AreClose - Returns whether or not two floats are "close". That is, whether or
/// not they are within epsilon of each other.

4
src/Avalonia.Controls/GridSplitter.cs

@ -632,11 +632,11 @@ namespace Avalonia.Controls
double actualLength2 = GetActualLength(definition2);
// When splitting, Check to see if the total pixels spanned by the definitions
// is the same asbefore starting resize. If not cancel the drag
// is the same as before starting resize. If not cancel the drag.
if (_resizeData.SplitBehavior == SplitBehavior.Split &&
!MathUtilities.AreClose(
actualLength1 + actualLength2,
_resizeData.OriginalDefinition1ActualLength + _resizeData.OriginalDefinition2ActualLength))
_resizeData.OriginalDefinition1ActualLength + _resizeData.OriginalDefinition2ActualLength, LayoutHelper.LayoutEpsilon))
{
CancelResize();

6
src/Avalonia.Layout/LayoutHelper.cs

@ -9,6 +9,12 @@ namespace Avalonia.Layout
/// </summary>
public static class LayoutHelper
{
/// <summary>
/// Epsilon value used for certain layout calculations.
/// Based on the value in WPF LayoutDoubleUtil.
/// </summary>
public const double LayoutEpsilon = 0.00000153;
/// <summary>
/// Calculates a control's size based on its <see cref="ILayoutable.Width"/>,
/// <see cref="ILayoutable.Height"/>, <see cref="ILayoutable.MinWidth"/>,

Loading…
Cancel
Save