-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9307 from robloo/control-sizechanged
Add Control.SizeChanged Event
- Loading branch information
Showing
3 changed files
with
152 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using Avalonia.Interactivity; | ||
using Avalonia.Layout; | ||
using Avalonia.Utilities; | ||
|
||
namespace Avalonia.Controls | ||
{ | ||
/// <summary> | ||
/// Provides data specific to a SizeChanged event. | ||
/// </summary> | ||
public class SizeChangedEventArgs : RoutedEventArgs | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SizeChangedEventArgs"/> class. | ||
/// </summary> | ||
/// <param name="routedEvent">The routed event associated with these event args.</param> | ||
public SizeChangedEventArgs(RoutedEvent? routedEvent) | ||
: base (routedEvent) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SizeChangedEventArgs"/> class. | ||
/// </summary> | ||
/// <param name="routedEvent">The routed event associated with these event args.</param> | ||
/// <param name="source">The source object that raised the routed event.</param> | ||
public SizeChangedEventArgs(RoutedEvent? routedEvent, IInteractive? source) | ||
: base(routedEvent, source) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SizeChangedEventArgs"/> class. | ||
/// </summary> | ||
/// <param name="routedEvent">The routed event associated with these event args.</param> | ||
/// <param name="source">The source object that raised the routed event.</param> | ||
/// <param name="previousSize">The previous size (or bounds) of the object.</param> | ||
/// <param name="newSize">The new size (or bounds) of the object.</param> | ||
public SizeChangedEventArgs( | ||
RoutedEvent? routedEvent, | ||
IInteractive? source, | ||
Size previousSize, | ||
Size newSize) | ||
: base(routedEvent, source) | ||
{ | ||
PreviousSize = previousSize; | ||
NewSize = newSize; | ||
} | ||
|
||
/// <summary> | ||
/// 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 => !MathUtilities.AreClose(NewSize.Height, PreviousSize.Height, LayoutHelper.LayoutEpsilon); | ||
|
||
/// <summary> | ||
/// Gets the new size (or bounds) of the object. | ||
/// </summary> | ||
public Size NewSize { get; init; } | ||
|
||
/// <summary> | ||
/// Gets the previous size (or bounds) of the object. | ||
/// </summary> | ||
public Size PreviousSize { get; init; } | ||
|
||
/// <summary> | ||
/// 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 | ||
/// widths 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 => !MathUtilities.AreClose(NewSize.Width, PreviousSize.Width, LayoutHelper.LayoutEpsilon); | ||
} | ||
} |