-
-
Notifications
You must be signed in to change notification settings - Fork 322
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 #165 from LykosAI/main
- Loading branch information
Showing
333 changed files
with
27,511 additions
and
1,011 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
root = true | ||
root = true | ||
|
||
[*.cs] | ||
max_line_length = 100 | ||
max_line_length = 120 | ||
csharp_style_var_for_built_in_types = true | ||
dotnet_sort_system_directives_first = true | ||
|
||
# ReSharper properties | ||
resharper_csharp_max_line_length = 120 |
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,6 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "nuget" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" |
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
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
108 changes: 108 additions & 0 deletions
108
StabilityMatrix.Avalonia/Animations/ItemsRepeaterArrangeAnimation.cs
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,108 @@ | ||
using System; | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Rendering.Composition; | ||
using Avalonia.Rendering.Composition.Animations; | ||
|
||
namespace StabilityMatrix.Avalonia.Animations; | ||
|
||
public class ItemsRepeaterArrangeAnimation : AvaloniaObject | ||
{ | ||
public static readonly AttachedProperty<bool> EnableItemsArrangeAnimationProperty = | ||
AvaloniaProperty.RegisterAttached<ItemsRepeater, bool>( | ||
"EnableItemsArrangeAnimation", | ||
typeof(ItemsRepeaterArrangeAnimation) | ||
); | ||
|
||
static ItemsRepeaterArrangeAnimation() | ||
{ | ||
EnableItemsArrangeAnimationProperty.Changed.AddClassHandler<ItemsRepeater>( | ||
OnEnableItemsArrangeAnimationChanged | ||
); | ||
} | ||
|
||
private static void OnEnableItemsArrangeAnimationChanged( | ||
ItemsRepeater itemsRepeater, | ||
AvaloniaPropertyChangedEventArgs eventArgs | ||
) | ||
{ | ||
if (eventArgs.NewValue is true) | ||
{ | ||
itemsRepeater.ElementPrepared += OnElementPrepared; | ||
itemsRepeater.ElementIndexChanged += OnElementIndexChanged; | ||
} | ||
else | ||
{ | ||
// itemsRepeater.Opened -= OnOpened; | ||
} | ||
} | ||
|
||
private static void CreateAnimation(Visual item) | ||
{ | ||
var compositionVisual = | ||
ElementComposition.GetElementVisual(item) ?? throw new NullReferenceException(); | ||
|
||
if (compositionVisual.ImplicitAnimations is { } animations && animations.HasKey("Offset")) | ||
{ | ||
return; | ||
} | ||
|
||
var compositor = compositionVisual.Compositor; | ||
|
||
var offsetAnimation = compositor.CreateVector3KeyFrameAnimation(); | ||
offsetAnimation.Target = "Offset"; | ||
// Using the "this.FinalValue" to indicate the last value of the Offset property | ||
offsetAnimation.InsertExpressionKeyFrame(1.0f, "this.FinalValue"); | ||
offsetAnimation.Duration = TimeSpan.FromMilliseconds(150); | ||
|
||
// Create a new implicit animation collection and bind the offset animation | ||
var implicitAnimationCollection = compositor.CreateImplicitAnimationCollection(); | ||
implicitAnimationCollection["Offset"] = offsetAnimation; | ||
compositionVisual.ImplicitAnimations = implicitAnimationCollection; | ||
} | ||
|
||
private static void OnElementPrepared(object? sender, ItemsRepeaterElementPreparedEventArgs e) | ||
{ | ||
if ( | ||
sender is not ItemsRepeater itemsRepeater | ||
|| !GetEnableItemsArrangeAnimation(itemsRepeater) | ||
) | ||
return; | ||
|
||
CreateAnimation(itemsRepeater); | ||
} | ||
|
||
private static void OnElementIndexChanged( | ||
object? sender, | ||
ItemsRepeaterElementIndexChangedEventArgs e | ||
) | ||
{ | ||
if ( | ||
sender is not ItemsRepeater itemsRepeater | ||
|| !GetEnableItemsArrangeAnimation(itemsRepeater) | ||
) | ||
return; | ||
|
||
CreateAnimation(itemsRepeater); | ||
} | ||
|
||
/*private static void OnOpened(object sender, EventArgs e) | ||
{ | ||
if (sender is not WindowBase windowBase || !GetEnableScaleShowAnimation(windowBase)) | ||
return; | ||
// Here we explicitly animate the "Scale" property | ||
// The implementation is the same as `Offset` at the beginning, but just with the Scale property | ||
windowBase.StartWindowScaleAnimation(); | ||
}*/ | ||
|
||
public static bool GetEnableItemsArrangeAnimation(ItemsRepeater element) | ||
{ | ||
return element.GetValue(EnableItemsArrangeAnimationProperty); | ||
} | ||
|
||
public static void SetEnableItemsArrangeAnimation(ItemsRepeater element, bool value) | ||
{ | ||
element.SetValue(EnableItemsArrangeAnimationProperty, value); | ||
} | ||
} |
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
Oops, something went wrong.