Skip to content

Commit

Permalink
Merge pull request #17 from Sergio0694/dev
Browse files Browse the repository at this point in the history
New annotations, added To<T> extension
  • Loading branch information
Sergio0694 committed Jun 13, 2019
2 parents 12250e3 + 4ceb64a commit e8d5e13
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ It is also possible to set an initial delay, and to wait for the animation to be
```C#
await MyControl.Animation(FrameworkLayer.Xaml)
.Opacity(0, 1, Easing.CircleEaseOut)
.Scale(1.2, 1, Easing.QuadratincEaseInOut)
.Scale(1.2, 1, Easing.QuadraticEaseInOut)
.Duration(500)
.Delay(250)
.StartAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ internal abstract class AnimationBuilderBase<T> : IAnimationBuilder
/// <param name="to">The target position</param>
/// <param name="ease">The easing function to use for the translation animation</param>
[MustUseReturnValue, NotNull]
protected abstract IAnimationBuilder OnTranslation(Vector2? from, Vector2 to, Easing ease = Easing.Linear);
protected abstract IAnimationBuilder OnTranslation(Vector2? from, Vector2 to, Easing ease);

/// <inheritdoc/>
public IAnimationBuilder Offset(Axis axis, double to, Easing ease = Easing.Linear) => OnOffset(axis, null, to, ease);
Expand Down Expand Up @@ -119,7 +119,7 @@ internal abstract class AnimationBuilderBase<T> : IAnimationBuilder
/// <param name="to">The target position</param>
/// <param name="ease">The easing function to use for the offset animation</param>
[MustUseReturnValue, NotNull]
protected abstract IAnimationBuilder OnOffset(Vector2? from, Vector2 to, Easing ease = Easing.Linear);
protected abstract IAnimationBuilder OnOffset(Vector2? from, Vector2 to, Easing ease);

/// <inheritdoc/>
public IAnimationBuilder Scale(double to, Easing ease = Easing.Linear) => OnScale(null, to, ease);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public CompositionAnimationBuilder([NotNull] UIElement target) : base(target)
protected override IAnimationBuilder OnTranslation(Axis axis, double? from, double to, Easing ease) => OnScalarAnimation($"Translation.{axis}", from, to, ease);

/// <inheritdoc/>
protected override IAnimationBuilder OnTranslation(Vector2? from, Vector2 to, Easing ease = Easing.Linear) => OnVector3Animation("Translation", from, to, ease);
protected override IAnimationBuilder OnTranslation(Vector2? from, Vector2 to, Easing ease) => OnVector3Animation("Translation", from, to, ease);

/// <inheritdoc/>
protected override IAnimationBuilder OnOffset(Axis axis, double? from, double to, Easing ease) => OnScalarAnimation($"{nameof(Visual.Offset)}.{axis}", from, to, ease);

/// <inheritdoc/>
protected override IAnimationBuilder OnOffset(Vector2? from, Vector2 to, Easing ease = Easing.Linear) => OnVector3Animation(nameof(Visual.Offset), from, to, ease);
protected override IAnimationBuilder OnOffset(Vector2? from, Vector2 to, Easing ease) => OnVector3Animation(nameof(Visual.Offset), from, to, ease);

/// <inheritdoc/>
protected override IAnimationBuilder OnScale(double? from, double to, Easing ease)
Expand Down
4 changes: 2 additions & 2 deletions UICompositionAnimations/Animations/XamlAnimationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected override IAnimationBuilder OnTranslation(Axis axis, double? from, doub
}

/// <inheritdoc/>
protected override IAnimationBuilder OnTranslation(Vector2? from, Vector2 to, Easing ease = Easing.Linear)
protected override IAnimationBuilder OnTranslation(Vector2? from, Vector2 to, Easing ease)
{
AnimationFactories.Add(duration => TargetTransform.CreateDoubleAnimation(nameof(CompositeTransform.TranslateX), from?.X, to.X, duration, ease));
AnimationFactories.Add(duration => TargetTransform.CreateDoubleAnimation(nameof(CompositeTransform.TranslateY), from?.Y, to.Y, duration, ease));
Expand All @@ -57,7 +57,7 @@ protected override IAnimationBuilder OnTranslation(Vector2? from, Vector2 to, Ea

protected override IAnimationBuilder OnOffset(Axis axis, double? from, double to, Easing ease) => throw new NotSupportedException("Can't animate the offset property from XAML");

protected override IAnimationBuilder OnOffset(Vector2? from, Vector2 to, Easing ease = Easing.Linear) => throw new NotSupportedException("Can't animate the offset property from XAML");
protected override IAnimationBuilder OnOffset(Vector2? from, Vector2 to, Easing ease) => throw new NotSupportedException("Can't animate the offset property from XAML");

/// <inheritdoc/>
protected override IAnimationBuilder OnScale(double? from, double to, Easing ease)
Expand Down
2 changes: 2 additions & 0 deletions UICompositionAnimations/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Windows.UI.Xaml.Media.Animation;
using JetBrains.Annotations;
using UICompositionAnimations.Enums;

namespace UICompositionAnimations.Extensions
Expand All @@ -13,6 +14,7 @@ internal static class EnumExtensions
/// Converts an easing value to the right easing function
/// </summary>
/// <param name="ease">The desired easing function</param>
[Pure, CanBeNull]
public static EasingFunctionBase ToEasingFunction(this Easing ease)
{
switch (ease)
Expand Down
13 changes: 13 additions & 0 deletions UICompositionAnimations/Extensions/System/BaseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,23 @@ public static class BaseExtensions
/// <summary>
/// Performs a direct cast on the given <see cref="object"/>
/// </summary>
/// <typeparam name="T">The target type to return</typeparam>
/// <param name="o">The input <see cref="object"/> to cast</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Pure]
[ContractAnnotation("null => null; notnull => notnull")]
public static T To<T>(this object o) => (T)o;

/// <summary>
/// Performs a safe cast to the specified type
/// </summary>
/// <typeparam name="TTo">The target type to return, if possible</typeparam>
/// <param name="o">The input <see cref="object"/> to try to convert</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Pure]
[ContractAnnotation("null => null; notnull => canbenull")]
public static TTo As<TTo>([CanBeNull] this object o) where TTo : class => o as TTo;

/// <summary>
/// Converts an angle in radians to degrees
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public static void BindSize([NotNull] this CompositionObject source, [NotNull] U
/// <param name="source">The source <see cref="CompositionObject"/> instance</param>
/// <param name="dispatcher">The resulting <see cref="CoreDispatcher"/>, if existing</param>
[MustUseReturnValue]
[ContractAnnotation("=> true, dispatcher: notnull; => false, dispatcher: null")]
public static bool TryGetDispatcher([NotNull] this CompositionObject source, out CoreDispatcher dispatcher)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public static class DependencyObjectExtensions
From = from,
To = to,
Duration = duration,
EnableDependentAnimation = enableDependecyAnimations
EnableDependentAnimation = enableDependecyAnimations,
EasingFunction = easing.ToEasingFunction()
};
if (easing != Easing.Linear) animation.EasingFunction = easing.ToEasingFunction();
Storyboard.SetTarget(animation, target);
Storyboard.SetTargetProperty(animation, property);
return animation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static void SetVisualCenterPoint([NotNull] this FrameworkElement element,
/// <param name="blurRadius">The optional explicit <see cref="DropShadow"/> blur radius</param>
/// <param name="maskElement">The optional <see cref="UIElement"/> to use to create an alpha mask for the <see cref="DropShadow"/></param>
/// <returns>The <see cref="SpriteVisual"/> that hosts the <see cref="DropShadow"/></returns>
[NotNull]
public static SpriteVisual AttachVisualShadow(
[NotNull] this FrameworkElement element, [NotNull] UIElement target,
bool apply,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static class UIElementExtensions
/// Returns the Visual object for a given UIElement
/// </summary>
/// <param name="element">The source UIElement</param>
[Pure, NotNull]
public static Visual GetVisual([NotNull] this UIElement element) => ElementCompositionPreview.GetElementVisual(element);

#region Animations
Expand Down Expand Up @@ -110,8 +111,8 @@ public static IAnimationBuilder Animation([NotNull] this UIElement target, Frame
/// <typeparam name="T">The desired <see cref="Transform"/> type</typeparam>
/// <param name="element">The target <see cref="UIElement"/> to modify</param>
/// <param name="reset">If <see langword="true"/>, a new <see cref="Transform"/> instance will always be created and assigned to the <see cref="UIElement"/></param>
/// <returns></returns>
public static T GetTransform<T>(this UIElement element, bool reset = true) where T : Transform, new()
[MustUseReturnValue, NotNull]
public static T GetTransform<T>([NotNull] this UIElement element, bool reset = true) where T : Transform, new()
{
// Return the existing transform object, if it exists
if (element.RenderTransform is T && !reset) return element.RenderTransform.To<T>();
Expand Down
6 changes: 3 additions & 3 deletions UICompositionAnimations/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.0.2.0")]
[assembly: AssemblyFileVersion("4.0.2.0")]
[assembly: AssemblyInformationalVersion("4.0.2")]
[assembly: AssemblyVersion("4.0.3.0")]
[assembly: AssemblyFileVersion("4.0.3.0")]
[assembly: AssemblyInformationalVersion("4.0.3")]
[assembly: ComVisible(false)]

4 changes: 2 additions & 2 deletions UICompositionAnimations/UICompositionAnimations.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<package>
<metadata>
<id>UICompositionAnimations</id>
<version>4.0.2</version>
<version>4.0.3</version>
<title>UICompositionAnimations</title>
<description>A wrapper UWP PCL to work with Windows.UI.Composition and XAML animations, and Win2D effects</description>
<authors>Sergio Pedri</authors>
<owners>Sergio Pedri</owners>
<projectUrl>https://github.com/Sergio0694/UICompositionAnimations</projectUrl>
<license type="expression">GPL-3.0-only</license>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<releaseNotes>New size animation APIs, minor fixes</releaseNotes>
<releaseNotes>New extension APIs, more annotations</releaseNotes>
<copyright>Copyright © 2019</copyright>
<tags>uwp composition animations xaml csharp windows winrt universal app ui win2d graphics</tags>
<dependencies>
Expand Down

0 comments on commit e8d5e13

Please sign in to comment.