From e3620c31395a29d8568f5b5d3803efb5fe1d7935 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 22 Aug 2015 21:05:33 +0200 Subject: [PATCH] Use interfaces in page transitions. --- Perspex.Animation/Animate.cs | 4 +- Perspex.Base/IObservablePropertyBag.cs | 23 +++++++++ Perspex.Base/IPropertyBag.cs | 17 +++++++ Perspex.SceneGraph/Animation/CrossFade.cs | 48 +++++++++++++++++-- .../Animation/IPageTransition.cs | 20 +++++++- Perspex.SceneGraph/Animation/PageSlide.cs | 2 +- Perspex.SceneGraph/IVisual.cs | 22 ++++----- .../SelectorTests_Child.cs | 20 ++++++++ .../SelectorTests_Descendent.cs | 20 ++++++++ .../TestControlBase.cs | 20 ++++++++ .../TestTemplatedControl.cs | 15 ++++++ 11 files changed, 193 insertions(+), 18 deletions(-) diff --git a/Perspex.Animation/Animate.cs b/Perspex.Animation/Animate.cs index 98daa45e46..d3e2e76463 100644 --- a/Perspex.Animation/Animate.cs +++ b/Perspex.Animation/Animate.cs @@ -103,7 +103,7 @@ namespace Perspex.Animation /// The duration of the animation. /// An that can be used to track or stop the animation. public static Animation Property( - PerspexObject target, + IObservablePropertyBag target, PerspexProperty property, object start, object finish, @@ -126,7 +126,7 @@ namespace Perspex.Animation /// The duration of the animation. /// An that can be used to track or stop the animation. public static Animation Property( - PerspexObject target, + IObservablePropertyBag target, PerspexProperty property, T start, T finish, diff --git a/Perspex.Base/IObservablePropertyBag.cs b/Perspex.Base/IObservablePropertyBag.cs index 868f78ba8d..f33122da85 100644 --- a/Perspex.Base/IObservablePropertyBag.cs +++ b/Perspex.Base/IObservablePropertyBag.cs @@ -27,11 +27,34 @@ namespace Perspex IObservable source, BindingPriority priority = BindingPriority.LocalValue); + /// + /// Binds a to an observable. + /// + /// The type of the property. + /// The property. + /// The observable. + /// The priority of the binding. + /// + /// A disposable which can be used to terminate the binding. + /// + IDisposable Bind( + PerspexProperty property, + IObservable source, + BindingPriority priority = BindingPriority.LocalValue); + /// /// Gets an observable for a . /// /// The property. /// An observable. IObservable GetObservable(PerspexProperty property); + + /// + /// Gets an observable for a . + /// + /// The type of the property. + /// The property. + /// An observable. + IObservable GetObservable(PerspexProperty property); } } \ No newline at end of file diff --git a/Perspex.Base/IPropertyBag.cs b/Perspex.Base/IPropertyBag.cs index 131a0800e9..73ca460ca3 100644 --- a/Perspex.Base/IPropertyBag.cs +++ b/Perspex.Base/IPropertyBag.cs @@ -24,6 +24,14 @@ namespace Perspex /// The value. object GetValue(PerspexProperty property); + /// + /// Gets a value. + /// + /// The type of the property. + /// The property. + /// The value. + T GetValue(PerspexProperty property); + /// /// Checks whether a is registered on this object. /// @@ -45,5 +53,14 @@ namespace Perspex /// The value. /// The priority of the value. void SetValue(PerspexProperty property, object value, BindingPriority priority = BindingPriority.LocalValue); + + /// + /// Sets a value. + /// + /// The type of the property. + /// The property. + /// The value. + /// The priority of the value. + void SetValue(PerspexProperty property, T value, BindingPriority priority = BindingPriority.LocalValue); } } \ No newline at end of file diff --git a/Perspex.SceneGraph/Animation/CrossFade.cs b/Perspex.SceneGraph/Animation/CrossFade.cs index b2b62c0295..b353bafbd2 100644 --- a/Perspex.SceneGraph/Animation/CrossFade.cs +++ b/Perspex.SceneGraph/Animation/CrossFade.cs @@ -11,16 +11,38 @@ namespace Perspex.Animation using System.Reactive.Threading.Tasks; using System.Threading.Tasks; + /// + /// Defines a cross-fade animation between two s. + /// public class CrossFade : IPageTransition { + /// + /// Initializes a new instance of the class. + /// + /// The duration of the animation. public CrossFade(TimeSpan duration) { this.Duration = duration; } + /// + /// Gets the duration of the animation. + /// public TimeSpan Duration { get; } - public async Task Start(Visual from, Visual to, bool forward) + /// + /// Starts the animation. + /// + /// + /// The control that is being transitioned away from. May be null. + /// + /// + /// The control that is being transitioned to. May be null. + /// + /// + /// A that tracks the progress of the animation. + /// + public async Task Start(IVisual from, IVisual to) { var tasks = new List(); @@ -32,7 +54,7 @@ namespace Perspex.Animation if (from != null) { tasks.Add(Animate.Property( - from, + (IObservablePropertyBag)from, Visual.OpacityProperty, from.Opacity, 0, @@ -46,7 +68,7 @@ namespace Perspex.Animation to.IsVisible = true; tasks.Add(Animate.Property( - to, + (IObservablePropertyBag)to, Visual.OpacityProperty, 0, 1, @@ -64,5 +86,25 @@ namespace Perspex.Animation to.Opacity = 1; } + + /// + /// Starts the animation. + /// + /// + /// The control that is being transitioned away from. May be null. + /// + /// + /// The control that is being transitioned to. May be null. + /// + /// + /// Unused for cross-fades. + /// + /// + /// A that tracks the progress of the animation. + /// + Task IPageTransition.Start(IVisual from, IVisual to, bool forward) + { + return this.Start(from, to); + } } } diff --git a/Perspex.SceneGraph/Animation/IPageTransition.cs b/Perspex.SceneGraph/Animation/IPageTransition.cs index 7a3239bcd2..b57cebba43 100644 --- a/Perspex.SceneGraph/Animation/IPageTransition.cs +++ b/Perspex.SceneGraph/Animation/IPageTransition.cs @@ -8,8 +8,26 @@ namespace Perspex.Animation { using System.Threading.Tasks; + /// + /// Interface for animations that transition between two pages. + /// public interface IPageTransition { - Task Start(Visual from, Visual to, bool forward); + /// + /// Starts the animation. + /// + /// + /// The control that is being transitioned away from. May be null. + /// + /// + /// The control that is being transitioned to. May be null. + /// + /// + /// If the animation is bidirectional, controls the direction of the animation. + /// + /// + /// A that tracks the progress of the animation. + /// + Task Start(IVisual from, IVisual to, bool forward); } } diff --git a/Perspex.SceneGraph/Animation/PageSlide.cs b/Perspex.SceneGraph/Animation/PageSlide.cs index 2c16eee32d..6eccaeb296 100644 --- a/Perspex.SceneGraph/Animation/PageSlide.cs +++ b/Perspex.SceneGraph/Animation/PageSlide.cs @@ -22,7 +22,7 @@ namespace Perspex.Animation public TimeSpan Duration { get; } - public async Task Start(Visual from, Visual to, bool forward) + public async Task Start(IVisual from, IVisual to, bool forward) { var tasks = new List(); var parent = GetVisualParent(from, to); diff --git a/Perspex.SceneGraph/IVisual.cs b/Perspex.SceneGraph/IVisual.cs index f626d97b70..0f822d5c99 100644 --- a/Perspex.SceneGraph/IVisual.cs +++ b/Perspex.SceneGraph/IVisual.cs @@ -31,7 +31,7 @@ namespace Perspex /// /// Gets a value indicating whether the scene graph node should be clipped to its bounds. /// - bool ClipToBounds { get; } + bool ClipToBounds { get; set; } /// /// Gets a value indicating whether this scene graph node is attached to a visual root. @@ -44,24 +44,24 @@ namespace Perspex bool IsEffectivelyVisible { get; } /// - /// Gets a value indicating whether this scene graph node is visible. + /// Gets or sets a value indicating whether this scene graph node is visible. /// - bool IsVisible { get; } + bool IsVisible { get; set; } /// - /// Gets the opacity of the scene graph node. + /// Gets or sets the opacity of the scene graph node. /// - double Opacity { get; } + double Opacity { get; set; } /// - /// Gets the render transform of the scene graph node. + /// Gets or sets the render transform of the scene graph node. /// - Transform RenderTransform { get; } + Transform RenderTransform { get; set; } /// - /// Gets the transform origin of the scene graph node. + /// Gets or sets the transform origin of the scene graph node. /// - Origin TransformOrigin { get; } + Origin TransformOrigin { get; set; } /// /// Gets the scene graph node's child nodes. @@ -74,9 +74,9 @@ namespace Perspex IVisual VisualParent { get; } /// - /// Gets the Z index of the node. + /// Gets or sets the Z index of the node. /// - int ZIndex { get; } + int ZIndex { get; set; } /// /// Renders the scene graph node to a . diff --git a/Tests/Perspex.Styling.UnitTests/SelectorTests_Child.cs b/Tests/Perspex.Styling.UnitTests/SelectorTests_Child.cs index 6794b8b41e..10f2bb5674 100644 --- a/Tests/Perspex.Styling.UnitTests/SelectorTests_Child.cs +++ b/Tests/Perspex.Styling.UnitTests/SelectorTests_Child.cs @@ -124,6 +124,26 @@ namespace Perspex.Styling.UnitTests { throw new NotImplementedException(); } + + public IDisposable Bind(PerspexProperty property, IObservable source, BindingPriority priority = BindingPriority.LocalValue) + { + throw new NotImplementedException(); + } + + public IObservable GetObservable(PerspexProperty property) + { + throw new NotImplementedException(); + } + + public T GetValue(PerspexProperty property) + { + throw new NotImplementedException(); + } + + public void SetValue(PerspexProperty property, T value, BindingPriority priority = BindingPriority.LocalValue) + { + throw new NotImplementedException(); + } } public class TestLogical1 : TestLogical diff --git a/Tests/Perspex.Styling.UnitTests/SelectorTests_Descendent.cs b/Tests/Perspex.Styling.UnitTests/SelectorTests_Descendent.cs index 5de13f4aef..05a9da8d89 100644 --- a/Tests/Perspex.Styling.UnitTests/SelectorTests_Descendent.cs +++ b/Tests/Perspex.Styling.UnitTests/SelectorTests_Descendent.cs @@ -156,6 +156,26 @@ namespace Perspex.Styling.UnitTests { throw new NotImplementedException(); } + + public IDisposable Bind(PerspexProperty property, IObservable source, BindingPriority priority = BindingPriority.LocalValue) + { + throw new NotImplementedException(); + } + + public IObservable GetObservable(PerspexProperty property) + { + throw new NotImplementedException(); + } + + public T GetValue(PerspexProperty property) + { + throw new NotImplementedException(); + } + + public void SetValue(PerspexProperty property, T value, BindingPriority priority = BindingPriority.LocalValue) + { + throw new NotImplementedException(); + } } public class TestLogical1 : TestLogical diff --git a/Tests/Perspex.Styling.UnitTests/TestControlBase.cs b/Tests/Perspex.Styling.UnitTests/TestControlBase.cs index 5bec5bb5c0..3b0c61d42d 100644 --- a/Tests/Perspex.Styling.UnitTests/TestControlBase.cs +++ b/Tests/Perspex.Styling.UnitTests/TestControlBase.cs @@ -68,5 +68,25 @@ namespace Perspex.Styling.UnitTests { throw new NotImplementedException(); } + + public IDisposable Bind(PerspexProperty property, IObservable source, BindingPriority priority = BindingPriority.LocalValue) + { + throw new NotImplementedException(); + } + + public IObservable GetObservable(PerspexProperty property) + { + throw new NotImplementedException(); + } + + public T GetValue(PerspexProperty property) + { + throw new NotImplementedException(); + } + + public void SetValue(PerspexProperty property, T value, BindingPriority priority = BindingPriority.LocalValue) + { + throw new NotImplementedException(); + } } } diff --git a/Tests/Perspex.Styling.UnitTests/TestTemplatedControl.cs b/Tests/Perspex.Styling.UnitTests/TestTemplatedControl.cs index a8b6d8c7c5..5337e80621 100644 --- a/Tests/Perspex.Styling.UnitTests/TestTemplatedControl.cs +++ b/Tests/Perspex.Styling.UnitTests/TestTemplatedControl.cs @@ -76,5 +76,20 @@ namespace Perspex.Styling.UnitTests { throw new NotImplementedException(); } + + public IDisposable Bind(PerspexProperty property, IObservable source, BindingPriority priority = BindingPriority.LocalValue) + { + throw new NotImplementedException(); + } + + public T GetValue(PerspexProperty property) + { + throw new NotImplementedException(); + } + + public void SetValue(PerspexProperty property, T value, BindingPriority priority = BindingPriority.LocalValue) + { + throw new NotImplementedException(); + } } }