Commit 7dc5d5d8 authored by Ian Hickson's avatar Ian Hickson

Merge pull request #2934 from Hixie/toStringAnimation

toStrings for Animations and Animatables
parents 2e5ae373 044ecf54
...@@ -28,6 +28,9 @@ class _AlwaysCompleteAnimation extends Animation<double> { ...@@ -28,6 +28,9 @@ class _AlwaysCompleteAnimation extends Animation<double> {
@override @override
double get value => 1.0; double get value => 1.0;
@override
String toString() => 'kAlwaysCompleteAnimation';
} }
/// An animation that is always complete. /// An animation that is always complete.
...@@ -57,6 +60,9 @@ class _AlwaysDismissedAnimation extends Animation<double> { ...@@ -57,6 +60,9 @@ class _AlwaysDismissedAnimation extends Animation<double> {
@override @override
double get value => 0.0; double get value => 0.0;
@override
String toString() => 'kAlwaysDismissedAnimation';
} }
/// An animation that is always dismissed. /// An animation that is always dismissed.
...@@ -96,6 +102,11 @@ class AlwaysStoppedAnimation<T> extends Animation<T> { ...@@ -96,6 +102,11 @@ class AlwaysStoppedAnimation<T> extends Animation<T> {
@override @override
AnimationStatus get status => AnimationStatus.forward; AnimationStatus get status => AnimationStatus.forward;
@override
String toStringDetails() {
return '${super.toStringDetails()} $value; paused';
}
} }
/// Implements most of the [Animation] interface, by deferring its behavior to a /// Implements most of the [Animation] interface, by deferring its behavior to a
...@@ -195,6 +206,13 @@ class ProxyAnimation extends Animation<double> ...@@ -195,6 +206,13 @@ class ProxyAnimation extends Animation<double>
@override @override
double get value => _parent != null ? _parent.value : _value; double get value => _parent != null ? _parent.value : _value;
@override
String toString() {
if (parent == null)
return '$runtimeType(null; ${super.toStringDetails()} ${value.toStringAsFixed(3)})';
return '$parent\u27A9$runtimeType';
}
} }
/// An animation that is the reverse of another animation. /// An animation that is the reverse of another animation.
...@@ -251,6 +269,11 @@ class ReverseAnimation extends Animation<double> ...@@ -251,6 +269,11 @@ class ReverseAnimation extends Animation<double>
case AnimationStatus.dismissed: return AnimationStatus.completed; case AnimationStatus.dismissed: return AnimationStatus.completed;
} }
} }
@override
String toString() {
return '$parent\u27AA$runtimeType';
}
} }
/// An animation that applies a curve to another animation. /// An animation that applies a curve to another animation.
...@@ -317,10 +340,13 @@ class CurvedAnimation extends Animation<double> with AnimationWithParentMixin<do ...@@ -317,10 +340,13 @@ class CurvedAnimation extends Animation<double> with AnimationWithParentMixin<do
} }
} }
bool get _useForwardCurve {
return reverseCurve == null || (_curveDirection ?? parent.status) != AnimationStatus.reverse;
}
@override @override
double get value { double get value {
final bool useForwardCurve = reverseCurve == null || (_curveDirection ?? parent.status) != AnimationStatus.reverse; Curve activeCurve = _useForwardCurve ? curve : reverseCurve;
Curve activeCurve = useForwardCurve ? curve : reverseCurve;
double t = parent.value; double t = parent.value;
if (activeCurve == null) if (activeCurve == null)
...@@ -331,6 +357,15 @@ class CurvedAnimation extends Animation<double> with AnimationWithParentMixin<do ...@@ -331,6 +357,15 @@ class CurvedAnimation extends Animation<double> with AnimationWithParentMixin<do
} }
return activeCurve.transform(t); return activeCurve.transform(t);
} }
@override
String toString() {
if (reverseCurve == null)
return '$parent\u27A9$curve';
if (_useForwardCurve)
return '$parent\u27A9$curve\u2092\u2099/$reverseCurve';
return '$parent\u27A9$curve/$reverseCurve\u2092\u2099';
}
} }
enum _TrainHoppingMode { minimize, maximize } enum _TrainHoppingMode { minimize, maximize }
...@@ -439,4 +474,11 @@ class TrainHoppingAnimation extends Animation<double> ...@@ -439,4 +474,11 @@ class TrainHoppingAnimation extends Animation<double>
_nextTrain = null; _nextTrain = null;
} }
} }
@override
String toString() {
if (_nextTrain != null)
return '$currentTrain\u27A9$runtimeType(next: $_nextTrain)';
return '$currentTrain\u27A9$runtimeType(no next)';
}
} }
...@@ -28,6 +28,11 @@ abstract class Curve { ...@@ -28,6 +28,11 @@ abstract class Curve {
/// Returns a new curve that is the reversed inversion of this one. /// Returns a new curve that is the reversed inversion of this one.
/// This is often useful as the reverseCurve of an [Animation]. /// This is often useful as the reverseCurve of an [Animation].
Curve get flipped => new FlippedCurve(this); Curve get flipped => new FlippedCurve(this);
@override
String toString() {
return '$runtimeType';
}
} }
/// The identity map over the unit interval. /// The identity map over the unit interval.
...@@ -49,6 +54,11 @@ class SawTooth extends Curve { ...@@ -49,6 +54,11 @@ class SawTooth extends Curve {
t *= count; t *= count;
return t - t.truncateToDouble(); return t - t.truncateToDouble();
} }
@override
String toString() {
return '$runtimeType($count)';
}
} }
/// A curve that is 0.0 until start, then curved from 0.0 to 1.0 at end, then 1.0. /// A curve that is 0.0 until start, then curved from 0.0 to 1.0 at end, then 1.0.
...@@ -76,6 +86,13 @@ class Interval extends Curve { ...@@ -76,6 +86,13 @@ class Interval extends Curve {
return t; return t;
return curve.transform(t); return curve.transform(t);
} }
@override
String toString() {
if (curve is! Linear)
return '$runtimeType($start\u22EF$end)\u27A9$curve';
return '$runtimeType($start\u22EF$end)';
}
} }
/// A cubic polynomial mapping of the unit interval. /// A cubic polynomial mapping of the unit interval.
...@@ -102,6 +119,11 @@ class Cubic extends Curve { ...@@ -102,6 +119,11 @@ class Cubic extends Curve {
end = midpoint; end = midpoint;
} }
} }
@override
String toString() {
return '$runtimeType(${a.toStringAsFixed(2)}, ${b.toStringAsFixed(2)}, ${c.toStringAsFixed(2)}, ${d.toStringAsFixed(2)})';
}
} }
double _bounce(double t) { double _bounce(double t) {
...@@ -126,6 +148,11 @@ class FlippedCurve extends Curve { ...@@ -126,6 +148,11 @@ class FlippedCurve extends Curve {
@override @override
double transform(double t) => 1.0 - curve.transform(1.0 - t); double transform(double t) => 1.0 - curve.transform(1.0 - t);
@override
String toString() {
return '$runtimeType($curve)';
}
} }
/// An oscillating curve that grows in magnitude. /// An oscillating curve that grows in magnitude.
...@@ -173,6 +200,11 @@ class ElasticInCurve extends Curve { ...@@ -173,6 +200,11 @@ class ElasticInCurve extends Curve {
t = t - 1.0; t = t - 1.0;
return -math.pow(2.0, 10.0 * t) * math.sin((t - s) * (math.PI * 2.0) / period); return -math.pow(2.0, 10.0 * t) * math.sin((t - s) * (math.PI * 2.0) / period);
} }
@override
String toString() {
return '$runtimeType($period)';
}
} }
/// An oscillating curve that shrinks in magnitude while overshooting its bounds. /// An oscillating curve that shrinks in magnitude while overshooting its bounds.
...@@ -186,6 +218,11 @@ class ElasticOutCurve extends Curve { ...@@ -186,6 +218,11 @@ class ElasticOutCurve extends Curve {
double s = period / 4.0; double s = period / 4.0;
return math.pow(2.0, -10 * t) * math.sin((t - s) * (math.PI * 2.0) / period) + 1.0; return math.pow(2.0, -10 * t) * math.sin((t - s) * (math.PI * 2.0) / period) + 1.0;
} }
@override
String toString() {
return '$runtimeType($period)';
}
} }
/// An oscillating curve that grows and then shrinks in magnitude while overshooting its bounds. /// An oscillating curve that grows and then shrinks in magnitude while overshooting its bounds.
...@@ -203,6 +240,11 @@ class ElasticInOutCurve extends Curve { ...@@ -203,6 +240,11 @@ class ElasticInOutCurve extends Curve {
else else
return math.pow(2.0, -10.0 * t) * math.sin((t - s) * (math.PI * 2.0) / period) * 0.5 + 1.0; return math.pow(2.0, -10.0 * t) * math.sin((t - s) * (math.PI * 2.0) / period) * 0.5 + 1.0;
} }
@override
String toString() {
return '$runtimeType($period)';
}
} }
/// A collection of common animation curves. /// A collection of common animation curves.
......
...@@ -33,7 +33,6 @@ abstract class Animatable<T> { ...@@ -33,7 +33,6 @@ abstract class Animatable<T> {
class _AnimatedEvaluation<T> extends Animation<T> with AnimationWithParentMixin<double> { class _AnimatedEvaluation<T> extends Animation<T> with AnimationWithParentMixin<double> {
_AnimatedEvaluation(this.parent, this._evaluatable); _AnimatedEvaluation(this.parent, this._evaluatable);
/// The animation from which this value is derived.
@override @override
final Animation<double> parent; final Animation<double> parent;
...@@ -41,6 +40,16 @@ class _AnimatedEvaluation<T> extends Animation<T> with AnimationWithParentMixin< ...@@ -41,6 +40,16 @@ class _AnimatedEvaluation<T> extends Animation<T> with AnimationWithParentMixin<
@override @override
T get value => _evaluatable.evaluate(parent); T get value => _evaluatable.evaluate(parent);
@override
String toString() {
return '$parent\u27A9$_evaluatable';
}
@override
String toStringDetails() {
return '${super.toStringDetails()} $_evaluatable';
}
} }
class _ChainedEvaluation<T> extends Animatable<T> { class _ChainedEvaluation<T> extends Animatable<T> {
...@@ -54,6 +63,11 @@ class _ChainedEvaluation<T> extends Animatable<T> { ...@@ -54,6 +63,11 @@ class _ChainedEvaluation<T> extends Animatable<T> {
double value = _parent.evaluate(animation); double value = _parent.evaluate(animation);
return _evaluatable.evaluate(new AlwaysStoppedAnimation<double>(value)); return _evaluatable.evaluate(new AlwaysStoppedAnimation<double>(value));
} }
@override
String toString() {
return '$_parent\u27A9$_evaluatable';
}
} }
/// A linear interpolation between a beginning and ending value. /// A linear interpolation between a beginning and ending value.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment