Browse Source

Take into account LayoutEpsilon when calculating Height/WidthChanged

pull/9307/head
robloo 4 years ago
parent
commit
bdd637298e
  1. 2
      src/Avalonia.Base/Interactivity/RoutedEventArgs.cs
  2. 29
      src/Avalonia.Controls/SizeChangedEventArgs.cs

2
src/Avalonia.Base/Interactivity/RoutedEventArgs.cs

@ -3,7 +3,7 @@ using System;
namespace Avalonia.Interactivity
{
/// <summary>
/// Provices state information and data specific to a routed event.
/// Provides state information and data specific to a routed event.
/// </summary>
public class RoutedEventArgs : EventArgs
{

29
src/Avalonia.Controls/SizeChangedEventArgs.cs

@ -1,4 +1,6 @@
using Avalonia.Interactivity;
using Avalonia.Layout;
using Avalonia.Utilities;
namespace Avalonia.Controls
{
@ -42,14 +44,23 @@ namespace Avalonia.Controls
{
PreviousSize = previousSize;
NewSize = newSize;
HeightChanged = newSize.Height != previousSize.Height;
WidthChanged = newSize.Width != previousSize.Width;
// Only consider changed when the size difference is greater than LayoutEpsilon
// This compensates for any rounding or precision difference between layout cycles
HeightChanged = !MathUtilities.AreClose(newSize.Height, previousSize.Height, LayoutHelper.LayoutEpsilon);
WidthChanged = !MathUtilities.AreClose(newSize.Width, previousSize.Width, LayoutHelper.LayoutEpsilon);
}
/// <summary>
/// Gets a value indicating whether the height of the new size is different
/// than the previous size height.
/// Gets a value indicating whether the height of the new size is considered
/// different than the previous size height.
/// </summary>
/// <remarks>
/// This will take into account layout epsilon and will not be true if both
/// heights are considered equivalent for layout purposes. Remember there can
/// be small variations in the calculations between layout cycles due to
/// rounding and precision even when the size has not otherwise changed.
/// </remarks>
public bool HeightChanged { get; init; }
/// <summary>
@ -63,9 +74,15 @@ namespace Avalonia.Controls
public Size PreviousSize { get; init; }
/// <summary>
/// Gets a value indicating whether the width of the new size is different
/// than the previous size width.
/// Gets a value indicating whether the width of the new size is considered
/// different than the previous size width.
/// </summary>
/// <remarks>
/// This will take into account layout epsilon and will not be true if both
/// heights are considered equivalent for layout purposes. Remember there can
/// be small variations in the calculations between layout cycles due to
/// rounding and precision even when the size has not otherwise changed.
/// </remarks>
public bool WidthChanged { get; init; }
}
}

Loading…
Cancel
Save