Browse Source

Use interfaces in page transitions.

pull/72/merge
Steven Kirk 11 years ago
parent
commit
e3620c3139
  1. 4
      Perspex.Animation/Animate.cs
  2. 23
      Perspex.Base/IObservablePropertyBag.cs
  3. 17
      Perspex.Base/IPropertyBag.cs
  4. 48
      Perspex.SceneGraph/Animation/CrossFade.cs
  5. 20
      Perspex.SceneGraph/Animation/IPageTransition.cs
  6. 2
      Perspex.SceneGraph/Animation/PageSlide.cs
  7. 22
      Perspex.SceneGraph/IVisual.cs
  8. 20
      Tests/Perspex.Styling.UnitTests/SelectorTests_Child.cs
  9. 20
      Tests/Perspex.Styling.UnitTests/SelectorTests_Descendent.cs
  10. 20
      Tests/Perspex.Styling.UnitTests/TestControlBase.cs
  11. 15
      Tests/Perspex.Styling.UnitTests/TestTemplatedControl.cs

4
Perspex.Animation/Animate.cs

@ -103,7 +103,7 @@ namespace Perspex.Animation
/// <param name="duration">The duration of the animation.</param>
/// <returns>An <see cref="Animation"/> that can be used to track or stop the animation.</returns>
public static Animation Property(
PerspexObject target,
IObservablePropertyBag target,
PerspexProperty property,
object start,
object finish,
@ -126,7 +126,7 @@ namespace Perspex.Animation
/// <param name="duration">The duration of the animation.</param>
/// <returns>An <see cref="Animation"/> that can be used to track or stop the animation.</returns>
public static Animation<T> Property<T>(
PerspexObject target,
IObservablePropertyBag target,
PerspexProperty<T> property,
T start,
T finish,

23
Perspex.Base/IObservablePropertyBag.cs

@ -27,11 +27,34 @@ namespace Perspex
IObservable<object> source,
BindingPriority priority = BindingPriority.LocalValue);
/// <summary>
/// Binds a <see cref="PerspexProperty"/> to an observable.
/// </summary>
/// <typeparam name="T">The type of the property.</typeparam>
/// <param name="property">The property.</param>
/// <param name="source">The observable.</param>
/// <param name="priority">The priority of the binding.</param>
/// <returns>
/// A disposable which can be used to terminate the binding.
/// </returns>
IDisposable Bind<T>(
PerspexProperty<T> property,
IObservable<T> source,
BindingPriority priority = BindingPriority.LocalValue);
/// <summary>
/// Gets an observable for a <see cref="PerspexProperty"/>.
/// </summary>
/// <param name="property">The property.</param>
/// <returns>An observable.</returns>
IObservable<object> GetObservable(PerspexProperty property);
/// <summary>
/// Gets an observable for a <see cref="PerspexProperty"/>.
/// </summary>
/// <typeparam name="T">The type of the property.</typeparam>
/// <param name="property">The property.</param>
/// <returns>An observable.</returns>
IObservable<T> GetObservable<T>(PerspexProperty<T> property);
}
}

17
Perspex.Base/IPropertyBag.cs

@ -24,6 +24,14 @@ namespace Perspex
/// <returns>The value.</returns>
object GetValue(PerspexProperty property);
/// <summary>
/// Gets a <see cref="PerspexProperty"/> value.
/// </summary>
/// <typeparam name="T">The type of the property.</typeparam>
/// <param name="property">The property.</param>
/// <returns>The value.</returns>
T GetValue<T>(PerspexProperty<T> property);
/// <summary>
/// Checks whether a <see cref="PerspexProperty"/> is registered on this object.
/// </summary>
@ -45,5 +53,14 @@ namespace Perspex
/// <param name="value">The value.</param>
/// <param name="priority">The priority of the value.</param>
void SetValue(PerspexProperty property, object value, BindingPriority priority = BindingPriority.LocalValue);
/// <summary>
/// Sets a <see cref="PerspexProperty"/> value.
/// </summary>
/// <typeparam name="T">The type of the property.</typeparam>
/// <param name="property">The property.</param>
/// <param name="value">The value.</param>
/// <param name="priority">The priority of the value.</param>
void SetValue<T>(PerspexProperty<T> property, T value, BindingPriority priority = BindingPriority.LocalValue);
}
}

48
Perspex.SceneGraph/Animation/CrossFade.cs

@ -11,16 +11,38 @@ namespace Perspex.Animation
using System.Reactive.Threading.Tasks;
using System.Threading.Tasks;
/// <summary>
/// Defines a cross-fade animation between two <see cref="IVisual"/>s.
/// </summary>
public class CrossFade : IPageTransition
{
/// <summary>
/// Initializes a new instance of the <see cref="CrossFade"/> class.
/// </summary>
/// <param name="duration">The duration of the animation.</param>
public CrossFade(TimeSpan duration)
{
this.Duration = duration;
}
/// <summary>
/// Gets the duration of the animation.
/// </summary>
public TimeSpan Duration { get; }
public async Task Start(Visual from, Visual to, bool forward)
/// <summary>
/// Starts the animation.
/// </summary>
/// <param name="from">
/// The control that is being transitioned away from. May be null.
/// </param>
/// <param name="to">
/// The control that is being transitioned to. May be null.
/// </param>
/// <returns>
/// A <see cref="Task"/> that tracks the progress of the animation.
/// </returns>
public async Task Start(IVisual from, IVisual to)
{
var tasks = new List<Task>();
@ -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;
}
/// <summary>
/// Starts the animation.
/// </summary>
/// <param name="from">
/// The control that is being transitioned away from. May be null.
/// </param>
/// <param name="to">
/// The control that is being transitioned to. May be null.
/// </param>
/// <param name="forward">
/// Unused for cross-fades.
/// </param>
/// <returns>
/// A <see cref="Task"/> that tracks the progress of the animation.
/// </returns>
Task IPageTransition.Start(IVisual from, IVisual to, bool forward)
{
return this.Start(from, to);
}
}
}

20
Perspex.SceneGraph/Animation/IPageTransition.cs

@ -8,8 +8,26 @@ namespace Perspex.Animation
{
using System.Threading.Tasks;
/// <summary>
/// Interface for animations that transition between two pages.
/// </summary>
public interface IPageTransition
{
Task Start(Visual from, Visual to, bool forward);
/// <summary>
/// Starts the animation.
/// </summary>
/// <param name="from">
/// The control that is being transitioned away from. May be null.
/// </param>
/// <param name="to">
/// The control that is being transitioned to. May be null.
/// </param>
/// <param name="forward">
/// If the animation is bidirectional, controls the direction of the animation.
/// </param>
/// <returns>
/// A <see cref="Task"/> that tracks the progress of the animation.
/// </returns>
Task Start(IVisual from, IVisual to, bool forward);
}
}

2
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<Task>();
var parent = GetVisualParent(from, to);

22
Perspex.SceneGraph/IVisual.cs

@ -31,7 +31,7 @@ namespace Perspex
/// <summary>
/// Gets a value indicating whether the scene graph node should be clipped to its bounds.
/// </summary>
bool ClipToBounds { get; }
bool ClipToBounds { get; set; }
/// <summary>
/// Gets a value indicating whether this scene graph node is attached to a visual root.
@ -44,24 +44,24 @@ namespace Perspex
bool IsEffectivelyVisible { get; }
/// <summary>
/// Gets a value indicating whether this scene graph node is visible.
/// Gets or sets a value indicating whether this scene graph node is visible.
/// </summary>
bool IsVisible { get; }
bool IsVisible { get; set; }
/// <summary>
/// Gets the opacity of the scene graph node.
/// Gets or sets the opacity of the scene graph node.
/// </summary>
double Opacity { get; }
double Opacity { get; set; }
/// <summary>
/// Gets the render transform of the scene graph node.
/// Gets or sets the render transform of the scene graph node.
/// </summary>
Transform RenderTransform { get; }
Transform RenderTransform { get; set; }
/// <summary>
/// Gets the transform origin of the scene graph node.
/// Gets or sets the transform origin of the scene graph node.
/// </summary>
Origin TransformOrigin { get; }
Origin TransformOrigin { get; set; }
/// <summary>
/// Gets the scene graph node's child nodes.
@ -74,9 +74,9 @@ namespace Perspex
IVisual VisualParent { get; }
/// <summary>
/// Gets the Z index of the node.
/// Gets or sets the Z index of the node.
/// </summary>
int ZIndex { get; }
int ZIndex { get; set; }
/// <summary>
/// Renders the scene graph node to a <see cref="IDrawingContext"/>.

20
Tests/Perspex.Styling.UnitTests/SelectorTests_Child.cs

@ -124,6 +124,26 @@ namespace Perspex.Styling.UnitTests
{
throw new NotImplementedException();
}
public IDisposable Bind<T>(PerspexProperty<T> property, IObservable<T> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public IObservable<T> GetObservable<T>(PerspexProperty<T> property)
{
throw new NotImplementedException();
}
public T GetValue<T>(PerspexProperty<T> property)
{
throw new NotImplementedException();
}
public void SetValue<T>(PerspexProperty<T> property, T value, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
}
public class TestLogical1 : TestLogical

20
Tests/Perspex.Styling.UnitTests/SelectorTests_Descendent.cs

@ -156,6 +156,26 @@ namespace Perspex.Styling.UnitTests
{
throw new NotImplementedException();
}
public IDisposable Bind<T>(PerspexProperty<T> property, IObservable<T> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public IObservable<T> GetObservable<T>(PerspexProperty<T> property)
{
throw new NotImplementedException();
}
public T GetValue<T>(PerspexProperty<T> property)
{
throw new NotImplementedException();
}
public void SetValue<T>(PerspexProperty<T> property, T value, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
}
public class TestLogical1 : TestLogical

20
Tests/Perspex.Styling.UnitTests/TestControlBase.cs

@ -68,5 +68,25 @@ namespace Perspex.Styling.UnitTests
{
throw new NotImplementedException();
}
public IDisposable Bind<T>(PerspexProperty<T> property, IObservable<T> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public IObservable<T> GetObservable<T>(PerspexProperty<T> property)
{
throw new NotImplementedException();
}
public T GetValue<T>(PerspexProperty<T> property)
{
throw new NotImplementedException();
}
public void SetValue<T>(PerspexProperty<T> property, T value, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
}
}

15
Tests/Perspex.Styling.UnitTests/TestTemplatedControl.cs

@ -76,5 +76,20 @@ namespace Perspex.Styling.UnitTests
{
throw new NotImplementedException();
}
public IDisposable Bind<T>(PerspexProperty<T> property, IObservable<T> source, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
public T GetValue<T>(PerspexProperty<T> property)
{
throw new NotImplementedException();
}
public void SetValue<T>(PerspexProperty<T> property, T value, BindingPriority priority = BindingPriority.LocalValue)
{
throw new NotImplementedException();
}
}
}

Loading…
Cancel
Save