Commit a9f0044e authored by Adam Barth's avatar Adam Barth

Merge pull request #854 from floitschG/nitpicking

Minor modifs.
parents 43d97668 b5aba601
...@@ -6,12 +6,12 @@ import 'dart:ui' show Color, Size, Rect; ...@@ -6,12 +6,12 @@ import 'dart:ui' show Color, Size, Rect;
import 'curves.dart'; import 'curves.dart';
/// The direction in which an animation is running /// The direction in which an animation is running.
enum AnimationDirection { enum AnimationDirection {
/// The animation is running from beginning to end /// The animation is running from beginning to end.
forward, forward,
/// The animation is running backwards, from end to beginning /// The animation is running backwards, from end to beginning.
reverse reverse
} }
...@@ -43,12 +43,12 @@ class AnimatedValue<T extends dynamic> implements Animatable { ...@@ -43,12 +43,12 @@ class AnimatedValue<T extends dynamic> implements Animatable {
/// Returns the value this variable has at the given animation clock value. /// Returns the value this variable has at the given animation clock value.
T lerp(double t) => begin + (end - begin) * t; T lerp(double t) => begin + (end - begin) * t;
/// The curve to use in the forward direction /// The curve to use in the forward direction.
Curve curve; Curve curve;
/// The curve to use in the reverse direction /// The curve to use in the reverse direction.
/// ///
/// If this field is null, use [curve] in both directions. /// If this field is null, uses [curve] in both directions.
Curve reverseCurve; Curve reverseCurve;
Curve _getActiveCurve(AnimationDirection direction) { Curve _getActiveCurve(AnimationDirection direction) {
...@@ -57,7 +57,6 @@ class AnimatedValue<T extends dynamic> implements Animatable { ...@@ -57,7 +57,6 @@ class AnimatedValue<T extends dynamic> implements Animatable {
return reverseCurve; return reverseCurve;
} }
/// Applies this timing to the given animation clock value in the given direction
double transform(double t, AnimationDirection direction) { double transform(double t, AnimationDirection direction) {
Curve activeCurve = _getActiveCurve(direction); Curve activeCurve = _getActiveCurve(direction);
if (activeCurve == null) if (activeCurve == null)
...@@ -120,13 +119,11 @@ class AnimatedRectValue extends AnimatedValue<Rect> { ...@@ -120,13 +119,11 @@ class AnimatedRectValue extends AnimatedValue<Rect> {
} }
/// An animated variable containing a int. /// An animated variable containing a int.
///
/// The inherited lerp() function doesn't work with ints because it multiplies
/// the begin and end types by a double, and int * double returns a double.
/// This class overrides the lerp() function to round off the result to an int.
class AnimatedIntValue extends AnimatedValue<int> { class AnimatedIntValue extends AnimatedValue<int> {
AnimatedIntValue(int begin, { int end, Curve curve, Curve reverseCurve }) AnimatedIntValue(int begin, { int end, Curve curve, Curve reverseCurve })
: super(begin, end: end, curve: curve, reverseCurve: reverseCurve); : super(begin, end: end, curve: curve, reverseCurve: reverseCurve);
// The inherited lerp() function doesn't work with ints because it multiplies
// the begin and end types by a double, and int * double returns a double.
int lerp(double t) => (begin + (end - begin) * t).round(); int lerp(double t) => (begin + (end - begin) * t).round();
} }
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
import 'dart:math' as math; import 'dart:math' as math;
double _evaluateCubic(double a, double b, double m) { double _evaluateCubic(double a, double b, double m) {
// TODO(abarth): Would Math.pow be faster?
return 3 * a * (1 - m) * (1 - m) * m + 3 * b * (1 - m) * m * m + m * m * m; return 3 * a * (1 - m) * (1 - m) * m + 3 * b * (1 - m) * m * m + m * m * m;
} }
...@@ -15,29 +14,29 @@ const double _kCubicErrorBound = 0.001; ...@@ -15,29 +14,29 @@ const double _kCubicErrorBound = 0.001;
/// ///
/// A curve must map 0.0 to 0.0 and 1.0 to 1.0. /// A curve must map 0.0 to 0.0 and 1.0 to 1.0.
abstract class Curve { abstract class Curve {
/// Return the value of the curve at point t /// Returns the value of the curve at point [t].
/// ///
/// The value of t must be between 0.0 and 1.0, inclusive. /// The value of [t] must be between 0.0 and 1.0, inclusive.
double transform(double t); double transform(double t);
} }
/// The identity map over the unit interval /// The identity map over the unit interval.
class Linear implements Curve { class Linear implements Curve {
const Linear(); const Linear();
double transform(double t) => t; double transform(double t) => t;
} }
/// 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.
class Interval implements Curve { class Interval implements Curve {
const Interval(this.start, this.end, { this.curve: Curves.linear }); const Interval(this.start, this.end, { this.curve: Curves.linear });
/// The smallest value for which this interval is 0.0 /// The smallest value for which this interval is 0.0.
final double start; final double start;
/// The smallest value for which this interval is 1.0 /// The smallest value for which this interval is 1.0.
final double end; final double end;
/// The curve to apply between [start] and [end] /// The curve to apply between [start] and [end].
final Curve curve; final Curve curve;
double transform(double t) { double transform(double t) {
...@@ -53,7 +52,7 @@ class Interval implements Curve { ...@@ -53,7 +52,7 @@ class Interval implements Curve {
} }
} }
/// A cubic polynomial mapping of the unit interval /// A cubic polynomial mapping of the unit interval.
class Cubic implements Curve { class Cubic implements Curve {
const Cubic(this.a, this.b, this.c, this.d); const Cubic(this.a, this.b, this.c, this.d);
...@@ -92,7 +91,7 @@ double _bounce(double t) { ...@@ -92,7 +91,7 @@ double _bounce(double t) {
return 7.5625 * t * t + 0.984375; return 7.5625 * t * t + 0.984375;
} }
/// An oscillating curve that grows in magnitude /// An oscillating curve that grows in magnitude.
class BounceInCurve implements Curve { class BounceInCurve implements Curve {
const BounceInCurve(); const BounceInCurve();
double transform(double t) { double transform(double t) {
...@@ -100,7 +99,7 @@ class BounceInCurve implements Curve { ...@@ -100,7 +99,7 @@ class BounceInCurve implements Curve {
} }
} }
/// An oscillating curve that shrink in magnitude /// An oscillating curve that shrink in magnitude.
class BounceOutCurve implements Curve { class BounceOutCurve implements Curve {
const BounceOutCurve(); const BounceOutCurve();
double transform(double t) { double transform(double t) {
...@@ -108,7 +107,7 @@ class BounceOutCurve implements Curve { ...@@ -108,7 +107,7 @@ class BounceOutCurve implements Curve {
} }
} }
/// An oscillating curve that first grows and then shrink in magnitude /// An oscillating curve that first grows and then shrink in magnitude.
class BounceInOutCurve implements Curve { class BounceInOutCurve implements Curve {
const BounceInOutCurve(); const BounceInOutCurve();
double transform(double t) { double transform(double t) {
...@@ -119,7 +118,7 @@ class BounceInOutCurve implements Curve { ...@@ -119,7 +118,7 @@ class BounceInOutCurve implements Curve {
} }
} }
/// An oscillating curve that grows in magnitude while overshootings its bounds /// An oscillating curve that grows in magnitude while overshooting its bounds.
class ElasticInCurve implements Curve { class ElasticInCurve implements Curve {
const ElasticInCurve([this.period = 0.4]); const ElasticInCurve([this.period = 0.4]);
final double period; final double period;
...@@ -130,7 +129,7 @@ class ElasticInCurve implements Curve { ...@@ -130,7 +129,7 @@ class ElasticInCurve implements Curve {
} }
} }
/// An oscillating curve that shrinks in magnitude while overshootings its bounds /// An oscillating curve that shrinks in magnitude while overshooting its bounds.
class ElasticOutCurve implements Curve { class ElasticOutCurve implements Curve {
const ElasticOutCurve([this.period = 0.4]); const ElasticOutCurve([this.period = 0.4]);
final double period; final double period;
...@@ -140,7 +139,7 @@ class ElasticOutCurve implements Curve { ...@@ -140,7 +139,7 @@ class ElasticOutCurve implements Curve {
} }
} }
/// An oscillating curve that grows and then shrinks in magnitude while overshootings its bounds /// An oscillating curve that grows and then shrinks in magnitude while overshooting its bounds.
class ElasticInOutCurve implements Curve { class ElasticInOutCurve implements Curve {
const ElasticInOutCurve([this.period = 0.4]); const ElasticInOutCurve([this.period = 0.4]);
final double period; final double period;
...@@ -161,36 +160,40 @@ class Curves { ...@@ -161,36 +160,40 @@ class Curves {
/// A linear animation curve /// A linear animation curve
static const Linear linear = const Linear(); static const Linear linear = const Linear();
/// A cubic animation curve that speeds up quickly and ends slowly /// A cubic animation curve that speeds up quickly and ends slowly.
static const Cubic ease = const Cubic(0.25, 0.1, 0.25, 1.0); static const Cubic ease = const Cubic(0.25, 0.1, 0.25, 1.0);
/// A cubic animation curve that starts slowly and ends quickly /// A cubic animation curve that starts slowly and ends quickly.
static const Cubic easeIn = const Cubic(0.42, 0.0, 1.0, 1.0); static const Cubic easeIn = const Cubic(0.42, 0.0, 1.0, 1.0);
/// A cubic animation curve that starts quickly and ends slowly /// A cubic animation curve that starts quickly and ends slowly.
static const Cubic easeOut = const Cubic(0.0, 0.0, 0.58, 1.0); static const Cubic easeOut = const Cubic(0.0, 0.0, 0.58, 1.0);
/// A cubic animation curve that starts slowly, speeds up, and then and ends slowly /// A cubic animation curve that starts slowly, speeds up, and then and ends slowly.
static const Cubic easeInOut = const Cubic(0.42, 0.0, 0.58, 1.0); static const Cubic easeInOut = const Cubic(0.42, 0.0, 0.58, 1.0);
/// An oscillating curve that grows in magnitude /// An oscillating curve that grows in magnitude.
static const BounceInCurve bounceIn = const BounceInCurve(); static const BounceInCurve bounceIn = const BounceInCurve();
/// An oscillating curve that first grows and then shrink in magnitude /// An oscillating curve that first grows and then shrink in magnitude.
static const BounceOutCurve bounceOut = const BounceOutCurve(); static const BounceOutCurve bounceOut = const BounceOutCurve();
/// An oscillating curve that first grows and then shrink in magnitude /// An oscillating curve that first grows and then shrink in magnitude.
static const BounceInOutCurve bounceInOut = const BounceInOutCurve(); static const BounceInOutCurve bounceInOut = const BounceInOutCurve();
/// An oscillating curve that grows in magnitude while overshootings its bounds /// An oscillating curve that grows in magnitude while overshootings its bounds.
static const ElasticInCurve elasticIn = const ElasticInCurve(); static const ElasticInCurve elasticIn = const ElasticInCurve();
/// An oscillating curve that shrinks in magnitude while overshootings its bounds /// An oscillating curve that shrinks in magnitude while overshootings its bounds.
static const ElasticOutCurve elasticOut = const ElasticOutCurve(); static const ElasticOutCurve elasticOut = const ElasticOutCurve();
/// An oscillating curve that grows and then shrinks in magnitude while overshootings its bounds /// An oscillating curve that grows and then shrinks in magnitude while overshootings its bounds.
static const ElasticInOutCurve elasticInOut = const ElasticInOutCurve(); static const ElasticInOutCurve elasticInOut = const ElasticInOutCurve();
/// A curve that starts quickly and eases into its final position. Over the course of the animation, the object spends more time near its final destination. As a result, the user isn’t left waiting for the animation to finish, and the negative effects of motion are minimized. /// A curve that starts quickly and eases into its final position.
///
/// Over the course of the animation, the object spends more time near its
/// final destination. As a result, the user isn’t left waiting for the
/// animation to finish, and the negative effects of motion are minimized.
static const Curve fastOutSlowIn = const Cubic(0.4, 0.0, 0.2, 1.0); static const Curve fastOutSlowIn = const Cubic(0.4, 0.0, 0.2, 1.0);
} }
...@@ -4,27 +4,27 @@ ...@@ -4,27 +4,27 @@
import 'package:newton/newton.dart'; import 'package:newton/newton.dart';
/// A factory for simulations /// A factory for simulations.
abstract class Force { abstract class Force {
const Force(); const Force();
Simulation release(double position, double velocity); Simulation release(double position, double velocity);
} }
/// A factory for spring-based physics simulations /// A factory for spring-based physics simulations.
class SpringForce extends Force { class SpringForce extends Force {
const SpringForce(this.spring, { this.left: 0.0, this.right: 1.0 }); const SpringForce(this.spring, { this.left: 0.0, this.right: 1.0 });
/// The description of the spring to be used in the created simulations /// The description of the spring to be used in the created simulations.
final SpringDescription spring; final SpringDescription spring;
/// Where to put the spring's resting point when releasing left /// Where to put the spring's resting point when releasing left.
final double left; final double left;
/// Where to put the spring's resting point when releasing right /// Where to put the spring's resting point when releasing right.
final double right; final double right;
/// How pricely to terminate the simulation /// How pricely to terminate the simulation.
/// ///
/// We overshoot the target by this distance, but stop the simulation when /// We overshoot the target by this distance, but stop the simulation when
/// the spring gets within this distance (regardless of how fast it's moving). /// the spring gets within this distance (regardless of how fast it's moving).
...@@ -48,5 +48,5 @@ final SpringDescription _kDefaultSpringDesc = new SpringDescription.withDampingR ...@@ -48,5 +48,5 @@ final SpringDescription _kDefaultSpringDesc = new SpringDescription.withDampingR
ratio: 1.0 ratio: 1.0
); );
/// A spring force with reasonable default values /// A spring force with reasonable default values.
final SpringForce kDefaultSpringForce = new SpringForce(_kDefaultSpringDesc); final SpringForce kDefaultSpringForce = new SpringForce(_kDefaultSpringDesc);
...@@ -13,22 +13,25 @@ import 'forces.dart'; ...@@ -13,22 +13,25 @@ import 'forces.dart';
import 'listener_helpers.dart'; import 'listener_helpers.dart';
import 'simulation_stepper.dart'; import 'simulation_stepper.dart';
/// An interface that is implemented by [Performance] that exposes a /// A read-only view of a [Performance].
/// read-only view of the underlying performance. This is used by classes that ///
/// This interface is implemented by [Performance].
///
/// Read-only access to [Performance] is used by classes that
/// want to watch a performance but should not be able to change the /// want to watch a performance but should not be able to change the
/// performance's state. /// performance's state.
abstract class PerformanceView { abstract class PerformanceView {
const PerformanceView(); const PerformanceView();
/// Update the given variable according to the current progress of the performance /// Update the given variable according to the current progress of the performance.
void updateVariable(Animatable variable); void updateVariable(Animatable variable);
/// Calls the listener every time the progress of the performance changes /// Calls the listener every time the progress of the performance changes.
void addListener(VoidCallback listener); void addListener(VoidCallback listener);
/// Stop calling the listener every time the progress of the performance changes /// Stop calling the listener every time the progress of the performance changes.
void removeListener(VoidCallback listener); void removeListener(VoidCallback listener);
/// Calls listener every time the status of the performance changes /// Calls listener every time the status of the performance changes.
void addStatusListener(PerformanceStatusListener listener); void addStatusListener(PerformanceStatusListener listener);
/// Stops calling the listener every time the status of the performance changes /// Stops calling the listener every time the status of the performance changes.
void removeStatusListener(PerformanceStatusListener listener); void removeStatusListener(PerformanceStatusListener listener);
/// The current status of this animation. /// The current status of this animation.
...@@ -45,13 +48,15 @@ abstract class PerformanceView { ...@@ -45,13 +48,15 @@ abstract class PerformanceView {
AnimationDirection get curveDirection; AnimationDirection get curveDirection;
/// The current progress of this animation (a value from 0.0 to 1.0). /// The current progress of this animation (a value from 0.0 to 1.0).
/// This is the value that is used to update any variables when using updateVariable(). ///
/// This is the value that is used to update any variables when using
/// [updateVariable].
double get progress; double get progress;
/// Whether this animation is stopped at the beginning /// Whether this animation is stopped at the beginning.
bool get isDismissed => status == PerformanceStatus.dismissed; bool get isDismissed => status == PerformanceStatus.dismissed;
/// Whether this animation is stopped at the end /// Whether this animation is stopped at the end.
bool get isCompleted => status == PerformanceStatus.completed; bool get isCompleted => status == PerformanceStatus.completed;
String toString() { String toString() {
...@@ -556,7 +561,7 @@ class Performance extends PerformanceView ...@@ -556,7 +561,7 @@ class Performance extends PerformanceView
_timeline.value = progress.clamp(0.0, 1.0); _timeline.value = progress.clamp(0.0, 1.0);
} }
/// A label that is used in the toString() output. Intended to aid with /// A label that is used in the [toString] output. Intended to aid with
/// identifying performance instances in debug output. /// identifying performance instances in debug output.
final String debugLabel; final String debugLabel;
...@@ -565,7 +570,7 @@ class Performance extends PerformanceView ...@@ -565,7 +570,7 @@ class Performance extends PerformanceView
/// allowing users of that pointer to mutate the Performance state. /// allowing users of that pointer to mutate the Performance state.
PerformanceView get view => this; PerformanceView get view => this;
/// The length of time this performance should last /// The length of time this performance should last.
Duration duration; Duration duration;
SimulationStepper _timeline; SimulationStepper _timeline;
...@@ -574,7 +579,7 @@ class Performance extends PerformanceView ...@@ -574,7 +579,7 @@ class Performance extends PerformanceView
AnimationDirection get curveDirection => _curveDirection; AnimationDirection get curveDirection => _curveDirection;
AnimationDirection _curveDirection = AnimationDirection.forward; AnimationDirection _curveDirection = AnimationDirection.forward;
/// The progress of this performance along the timeline /// The progress of this performance along the timeline.
/// ///
/// Note: Setting this value stops the current animation. /// Note: Setting this value stops the current animation.
double get progress => _timeline.value.clamp(0.0, 1.0); double get progress => _timeline.value.clamp(0.0, 1.0);
...@@ -584,7 +589,7 @@ class Performance extends PerformanceView ...@@ -584,7 +589,7 @@ class Performance extends PerformanceView
_checkStatusChanged(); _checkStatusChanged();
} }
/// Whether this animation is currently animating in either the forward or reverse direction /// Whether this animation is currently animating in either the forward or reverse direction.
bool get isAnimating => _timeline.isAnimating; bool get isAnimating => _timeline.isAnimating;
PerformanceStatus get status { PerformanceStatus get status {
...@@ -597,55 +602,52 @@ class Performance extends PerformanceView ...@@ -597,55 +602,52 @@ class Performance extends PerformanceView
PerformanceStatus.reverse; PerformanceStatus.reverse;
} }
/// Update the given varaible according to the current progress of this performance /// Updates the given variable according to the current progress of this performance.
void updateVariable(Animatable variable) { void updateVariable(Animatable variable) {
variable.setProgress(progress, _curveDirection); variable.setProgress(progress, _curveDirection);
} }
/// Start running this animation forwards (towards the end) /// Starts running this animation forwards (towards the end).
Future forward() => play(AnimationDirection.forward); Future forward() => play(AnimationDirection.forward);
/// Start running this animation in reverse (towards the beginning) /// Starts running this animation in reverse (towards the beginning).
Future reverse() => play(AnimationDirection.reverse); Future reverse() => play(AnimationDirection.reverse);
/// Start running this animation in the given direction /// Starts running this animation in the given direction.
Future play([AnimationDirection direction = AnimationDirection.forward]) { Future play([AnimationDirection direction = AnimationDirection.forward]) {
_direction = direction; _direction = direction;
return resume(); return resume();
} }
/// Start running this animation in the most recent direction /// Resumes this animation in the most recent direction.
Future resume() { Future resume() {
return _animateTo(_direction == AnimationDirection.forward ? 1.0 : 0.0); return _animateTo(_direction == AnimationDirection.forward ? 1.0 : 0.0);
} }
/// Stop running this animation. /// Stops running this animation.
void stop() { void stop() {
_timeline.stop(); _timeline.stop();
} }
/// Release any resources used by this object. /// Releases any resources used by this object.
/// ///
/// Same as stop(). /// Same as stop().
void dispose() { void dispose() {
stop(); stop();
} }
/// Start running this animation according to the given physical parameters
/// ///
/// Flings the timeline with an optional force (defaults to a critically /// Flings the timeline with an optional force (defaults to a critically
/// damped spring) and initial velocity. If velocity is positive, the /// damped spring) and initial velocity. If velocity is positive, the
/// animation will complete, otherwise it will dismiss. /// animation will complete, otherwise it will dismiss.
Future fling({double velocity: 1.0, Force force}) { Future fling({double velocity: 1.0, Force force}) {
if (force == null) force ??= kDefaultSpringForce;
force = kDefaultSpringForce;
_direction = velocity < 0.0 ? AnimationDirection.reverse : AnimationDirection.forward; _direction = velocity < 0.0 ? AnimationDirection.reverse : AnimationDirection.forward;
return _timeline.animateWith(force.release(progress, velocity)); return _timeline.animateWith(force.release(progress, velocity));
} }
Future repeat({ double min: 0.0, double max: 1.0, Duration period }) { Future repeat({ double min: 0.0, double max: 1.0, Duration period }) {
if (period == null) period ??= duration;
period = duration;
return _timeline.animateWith(new _RepeatingSimulation(min, max, period)); return _timeline.animateWith(new _RepeatingSimulation(min, max, period));
} }
...@@ -690,7 +692,7 @@ class Performance extends PerformanceView ...@@ -690,7 +692,7 @@ class Performance extends PerformanceView
} }
} }
/// An animation performance with an animated variable with a concrete type /// An animation performance with an animated variable with a concrete type.
class ValuePerformance<T> extends Performance { class ValuePerformance<T> extends Performance {
ValuePerformance({ this.variable, Duration duration, double progress }) : ValuePerformance({ this.variable, Duration duration, double progress }) :
super(duration: duration, progress: progress); super(duration: duration, progress: progress);
...@@ -707,7 +709,7 @@ class ValuePerformance<T> extends Performance { ...@@ -707,7 +709,7 @@ class ValuePerformance<T> extends Performance {
class _RepeatingSimulation extends Simulation { class _RepeatingSimulation extends Simulation {
_RepeatingSimulation(this.min, this.max, Duration period) _RepeatingSimulation(this.min, this.max, Duration period)
: _periodInSeconds = period.inMicroseconds.toDouble() / Duration.MICROSECONDS_PER_SECOND { : _periodInSeconds = period.inMicroseconds / Duration.MICROSECONDS_PER_SECOND {
assert(_periodInSeconds > 0.0); assert(_periodInSeconds > 0.0);
} }
......
...@@ -11,15 +11,18 @@ const double _kScrollDrag = 0.025; ...@@ -11,15 +11,18 @@ const double _kScrollDrag = 0.025;
/// An interface for controlling the behavior of scrollable widgets. /// An interface for controlling the behavior of scrollable widgets.
abstract class ScrollBehavior { abstract class ScrollBehavior {
/// Called when a drag gesture ends. Returns a simulation that /// Returns a simulation that propels the scrollOffset.
/// propels the scrollOffset. ///
/// This function is called when a drag gesture ends.
Simulation createFlingScrollSimulation(double position, double velocity) => null; Simulation createFlingScrollSimulation(double position, double velocity) => null;
/// Called when a drag gesture ends and toSnapOffset is specified.
/// Returns an animation that ends at the snap offset. /// Returns an animation that ends at the snap offset.
///
/// This function is called when a drag gesture ends and toSnapOffset is specified.
Simulation createSnapScrollSimulation(double startOffset, double endOffset, double startVelocity, double endVelocity) => null; Simulation createSnapScrollSimulation(double startOffset, double endOffset, double startVelocity, double endVelocity) => null;
/// Return the scroll offset to use when the user attempts to scroll
/// Returns the scroll offset to use when the user attempts to scroll
/// from the given offset by the given delta. /// from the given offset by the given delta.
double applyCurve(double scrollOffset, double scrollDelta); double applyCurve(double scrollOffset, double scrollDelta);
...@@ -27,7 +30,7 @@ abstract class ScrollBehavior { ...@@ -27,7 +30,7 @@ abstract class ScrollBehavior {
bool get isScrollable => true; bool get isScrollable => true;
} }
/// A scroll behavior for a scrollable widget with linear extent /// A scroll behavior for a scrollable widget with linear extent.
abstract class ExtentScrollBehavior extends ScrollBehavior { abstract class ExtentScrollBehavior extends ScrollBehavior {
ExtentScrollBehavior({ double contentExtent: 0.0, double containerExtent: 0.0 }) ExtentScrollBehavior({ double contentExtent: 0.0, double containerExtent: 0.0 })
: _contentExtent = contentExtent, _containerExtent = containerExtent; : _contentExtent = contentExtent, _containerExtent = containerExtent;
...@@ -40,10 +43,11 @@ abstract class ExtentScrollBehavior extends ScrollBehavior { ...@@ -40,10 +43,11 @@ abstract class ExtentScrollBehavior extends ScrollBehavior {
double get containerExtent => _containerExtent; double get containerExtent => _containerExtent;
double _containerExtent; double _containerExtent;
/// Update either content or container extent (or both) /// Updates either content or container extent (or both)
///
/// Returns the new scroll offset of the widget after the change in extent.
/// ///
/// The scrollOffset parameter is the scroll offset of the widget before the /// The [scrollOffset] parameter is the scroll offset of the widget before the
/// change in extent. Returns the new scroll offset of the widget after the
/// change in extent. /// change in extent.
double updateExtents({ double updateExtents({
double contentExtent, double contentExtent,
...@@ -64,7 +68,7 @@ abstract class ExtentScrollBehavior extends ScrollBehavior { ...@@ -64,7 +68,7 @@ abstract class ExtentScrollBehavior extends ScrollBehavior {
double get maxScrollOffset; double get maxScrollOffset;
} }
/// A scroll behavior that prevents the user from exeeding scroll bounds. /// A scroll behavior that prevents the user from exceeding scroll bounds.
class BoundedBehavior extends ExtentScrollBehavior { class BoundedBehavior extends ExtentScrollBehavior {
BoundedBehavior({ double contentExtent: 0.0, double containerExtent: 0.0 }) BoundedBehavior({ double contentExtent: 0.0, double containerExtent: 0.0 })
: super(contentExtent: contentExtent, containerExtent: containerExtent); : super(contentExtent: contentExtent, containerExtent: containerExtent);
......
...@@ -9,13 +9,13 @@ import 'animated_value.dart'; ...@@ -9,13 +9,13 @@ import 'animated_value.dart';
import 'curves.dart'; import 'curves.dart';
import 'ticker.dart'; import 'ticker.dart';
/// A simulation that varies from [begin] to [end] over [duration] using [curve] /// A simulation that varies from [begin] to [end] over [duration] using [curve].
/// ///
/// This class is an adaptor between the Simulation interface and the /// This class is an adaptor between the Simulation interface and the
/// AnimatedValue interface. /// AnimatedValue interface.
class _TweenSimulation extends Simulation { class _TweenSimulation extends Simulation {
_TweenSimulation(double begin, double end, Duration duration, Curve curve) _TweenSimulation(double begin, double end, Duration duration, Curve curve)
: _durationInSeconds = duration.inMicroseconds.toDouble() / Duration.MICROSECONDS_PER_SECOND, : _durationInSeconds = duration.inMicroseconds / Duration.MICROSECONDS_PER_SECOND,
_tween = new AnimatedValue<double>(begin, end: end, curve: curve) { _tween = new AnimatedValue<double>(begin, end: end, curve: curve) {
assert(_durationInSeconds > 0.0); assert(_durationInSeconds > 0.0);
assert(begin != null); assert(begin != null);
...@@ -49,7 +49,7 @@ class SimulationStepper { ...@@ -49,7 +49,7 @@ class SimulationStepper {
Ticker _ticker; Ticker _ticker;
Simulation _simulation; Simulation _simulation;
/// The current value of the timeline /// The current value of the timeline.
double get value => _value; double get value => _value;
double _value = 0.0; double _value = 0.0;
void set value(double newValue) { void set value(double newValue) {
...@@ -59,10 +59,10 @@ class SimulationStepper { ...@@ -59,10 +59,10 @@ class SimulationStepper {
_onTick(_value); _onTick(_value);
} }
/// Whether the timeline is currently animating /// Whether the timeline is currently animating.
bool get isAnimating => _ticker.isTicking; bool get isAnimating => _ticker.isTicking;
/// Animate value of the timeline to the given target over the given duration /// Animates value of the timeline to the given target over the given duration.
/// ///
/// Returns a future that resolves when the timeline stops animating, /// Returns a future that resolves when the timeline stops animating,
/// typically when the timeline arives at the target value. /// typically when the timeline arives at the target value.
...@@ -72,13 +72,13 @@ class SimulationStepper { ...@@ -72,13 +72,13 @@ class SimulationStepper {
return _start(new _TweenSimulation(value, target, duration, curve)); return _start(new _TweenSimulation(value, target, duration, curve));
} }
/// Gives the given simulation control over the timeline /// Gives the given simulation control over the timeline.
Future animateWith(Simulation simulation) { Future animateWith(Simulation simulation) {
stop(); stop();
return _start(simulation); return _start(simulation);
} }
/// Start ticking the given simulation once per frame /// Starts ticking the given simulation once per frame.
/// ///
/// Returns a future that resolves when the simulation stops ticking. /// Returns a future that resolves when the simulation stops ticking.
Future _start(Simulation simulation) { Future _start(Simulation simulation) {
...@@ -89,7 +89,7 @@ class SimulationStepper { ...@@ -89,7 +89,7 @@ class SimulationStepper {
return _ticker.start(); return _ticker.start();
} }
/// Stop animating the timeline /// Stops animating the timeline.
void stop() { void stop() {
_simulation = null; _simulation = null;
_ticker.stop(); _ticker.stop();
......
...@@ -8,7 +8,7 @@ import 'scheduler.dart'; ...@@ -8,7 +8,7 @@ import 'scheduler.dart';
typedef TickerCallback(Duration elapsed); typedef TickerCallback(Duration elapsed);
/// Calls its callback once per animation frame /// Calls its callback once per animation frame.
class Ticker { class Ticker {
/// Constructs a ticker that will call onTick once per frame while running /// Constructs a ticker that will call onTick once per frame while running
Ticker(TickerCallback onTick) : _onTick = onTick; Ticker(TickerCallback onTick) : _onTick = onTick;
...@@ -19,7 +19,7 @@ class Ticker { ...@@ -19,7 +19,7 @@ class Ticker {
int _animationId; int _animationId;
Duration _startTime; Duration _startTime;
/// Start calling onTick once per animation frame /// Starts calling onTick once per animation frame.
/// ///
/// The returned future resolves once the ticker stops ticking. /// The returned future resolves once the ticker stops ticking.
Future start() { Future start() {
...@@ -30,7 +30,7 @@ class Ticker { ...@@ -30,7 +30,7 @@ class Ticker {
return _completer.future; return _completer.future;
} }
/// Stop calling onTick /// Stops calling onTick.
/// ///
/// Causes the future returned by [start] to resolve. /// Causes the future returned by [start] to resolve.
void stop() { void stop() {
......
...@@ -23,7 +23,7 @@ abstract class GestureArenaMember { ...@@ -23,7 +23,7 @@ abstract class GestureArenaMember {
void rejectGesture(Object key); void rejectGesture(Object key);
} }
/// An interface to information to an arena /// An interface to information to an arena.
/// ///
/// A given [GestureArenaMember] can have multiple entries in multiple arenas /// A given [GestureArenaMember] can have multiple entries in multiple arenas
/// with different keys. /// with different keys.
...@@ -80,7 +80,7 @@ class GestureArena { ...@@ -80,7 +80,7 @@ class GestureArena {
_tryToResolveArena(key, state); _tryToResolveArena(key, state);
} }
/// Force resolution on this arena, giving the win to the first member /// Forces resolution on this arena, giving the win to the first member.
void sweep(Object key) { void sweep(Object key) {
_GestureArenaState state = _arenas[key]; _GestureArenaState state = _arenas[key];
if (state == null) if (state == null)
...@@ -100,7 +100,7 @@ class GestureArena { ...@@ -100,7 +100,7 @@ class GestureArena {
} }
} }
/// Prevent the arena from being swept /// Prevents the arena from being swept.
void hold(Object key) { void hold(Object key) {
_GestureArenaState state = _arenas[key]; _GestureArenaState state = _arenas[key];
if (state == null) if (state == null)
...@@ -108,9 +108,10 @@ class GestureArena { ...@@ -108,9 +108,10 @@ class GestureArena {
state.isHeld = true; state.isHeld = true;
} }
/// Release a hold, allowing the arena to be swept /// Releases a hold, allowing the arena to be swept.
///
/// If a sweep was attempted on a held arena, the sweep will be done /// If a sweep was attempted on a held arena, the sweep will be done
/// on release /// on release.
void release(Object key) { void release(Object key) {
_GestureArenaState state = _arenas[key]; _GestureArenaState state = _arenas[key];
if (state == null) if (state == null)
......
...@@ -101,12 +101,12 @@ class LeastSquaresSolver { ...@@ -101,12 +101,12 @@ class LeastSquaresSolver {
final List<double> w; final List<double> w;
PolynomialFit solve(int degree) { PolynomialFit solve(int degree) {
if (degree > x.length) // not enough data to fit a curve if (degree > x.length) // Not enough data to fit a curve.
return null; return null;
PolynomialFit result = new PolynomialFit(degree); PolynomialFit result = new PolynomialFit(degree);
// Shorthands for the purpose of notation equivalence to original C++ code // Shorthands for the purpose of notation equivalence to original C++ code.
final int m = x.length; final int m = x.length;
final int n = degree + 1; final int n = degree + 1;
...@@ -135,7 +135,7 @@ class LeastSquaresSolver { ...@@ -135,7 +135,7 @@ class LeastSquaresSolver {
double norm = q.getRow(j).norm(); double norm = q.getRow(j).norm();
if (norm < 0.000001) { if (norm < 0.000001) {
// vectors are linearly dependent or zero so no solution // Vectors are linearly dependent or zero so no solution.
return null; return null;
} }
......
...@@ -91,7 +91,7 @@ class DoubleTapGestureRecognizer extends GestureRecognizer { ...@@ -91,7 +91,7 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
final Map<int, _TapTracker> _trackers = new Map<int, _TapTracker>(); final Map<int, _TapTracker> _trackers = new Map<int, _TapTracker>();
void addPointer(PointerEvent event) { void addPointer(PointerEvent event) {
// Ignore out-of-bounds second taps // Ignore out-of-bounds second taps.
if (_firstTap != null && if (_firstTap != null &&
!_firstTap.isWithinTolerance(event, kDoubleTapSlop)) !_firstTap.isWithinTolerance(event, kDoubleTapSlop))
return; return;
...@@ -155,7 +155,7 @@ class DoubleTapGestureRecognizer extends GestureRecognizer { ...@@ -155,7 +155,7 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
_stopDoubleTapTimer(); _stopDoubleTapTimer();
if (_firstTap != null) { if (_firstTap != null) {
// Note, order is important below in order for the resolve -> reject logic // Note, order is important below in order for the resolve -> reject logic
// to work properly // to work properly.
_TapTracker tracker = _firstTap; _TapTracker tracker = _firstTap;
_firstTap = null; _firstTap = null;
_reject(tracker); _reject(tracker);
......
...@@ -34,7 +34,7 @@ class PointerRouter { ...@@ -34,7 +34,7 @@ class PointerRouter {
_routeMap.remove(pointer); _routeMap.remove(pointer);
} }
/// Call the routes registed for this pointer event. /// Calls the routes registed for this pointer event.
/// ///
/// Calls the routes in the order in which they were added to the route. /// Calls the routes in the order in which they were added to the route.
void route(PointerEvent event) { void route(PointerEvent event) {
......
...@@ -14,15 +14,17 @@ export 'pointer_router.dart' show PointerRouter; ...@@ -14,15 +14,17 @@ export 'pointer_router.dart' show PointerRouter;
abstract class GestureRecognizer extends GestureArenaMember { abstract class GestureRecognizer extends GestureArenaMember {
/// Call this with the pointerdown event of each pointer that should be /// Calls this with the pointerdown event of each pointer that should be
/// considered for this gesture. (It's the GestureRecognizer's responsibility /// considered for this gesture.
/// to then add itself to the global pointer router to receive subsequent ///
/// events for this pointer.) /// It's the GestureRecognizer's responsibility to then add itself to the
/// global pointer router to receive subsequent events for this pointer.
void addPointer(PointerDownEvent event); void addPointer(PointerDownEvent event);
/// Release any resources used by the object. Called when the object is no /// Releases any resources used by the object.
/// longer needed (e.g. a gesture recogniser is being unregistered from a ///
/// [GestureDetector]). /// This method is called when the object is no longer needed (e.g. a gesture
/// recogniser is being unregistered from a [GestureDetector]).
void dispose() { } void dispose() { }
} }
...@@ -123,7 +125,7 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni ...@@ -123,7 +125,7 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
/// Override to provide behavior for the primary pointer when the gesture is still possible. /// Override to provide behavior for the primary pointer when the gesture is still possible.
void handlePrimaryPointer(PointerEvent event); void handlePrimaryPointer(PointerEvent event);
/// Override to be notified with [deadline] is exceeded. /// Override to be notified when [deadline] is exceeded.
/// ///
/// You must override this function if you supply a [deadline]. /// You must override this function if you supply a [deadline].
void didExceedDeadline() { void didExceedDeadline() {
......
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
// for details. All rights reserved. Use of this source code is governed by a // for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file. // BSD-style license that can be found in the LICENSE file.
/// A [Future]-based library for making HTTP requests. It's based on /// A [Future]-based library for making HTTP requests.
/// Dart's `http` package, but we've removed the dependency on mirrors ///
/// and added a `mojo`-based HTTP client. /// Let library is based on Dart's `http` package, but we have removed the
/// dependency on mirrors and added a `mojo`-based HTTP client.
library http; library http;
import 'dart:async'; import 'dart:async';
......
...@@ -16,7 +16,7 @@ import 'package:mojo/mojo/http_header.mojom.dart' as mojo; ...@@ -16,7 +16,7 @@ import 'package:mojo/mojo/http_header.mojom.dart' as mojo;
import 'response.dart'; import 'response.dart';
/// A `mojo`-based HTTP client /// A `mojo`-based HTTP client.
class MojoClient { class MojoClient {
Future<Response> head(url, {Map<String, String> headers}) => Future<Response> head(url, {Map<String, String> headers}) =>
......
...@@ -8,7 +8,7 @@ import 'dart:ui' as ui; ...@@ -8,7 +8,7 @@ import 'dart:ui' as ui;
class ShadowDrawLooperBuilder { class ShadowDrawLooperBuilder {
ui.LayerDrawLooperBuilder _builder = new ui.LayerDrawLooperBuilder(); ui.LayerDrawLooperBuilder _builder = new ui.LayerDrawLooperBuilder();
/// Add a shadow with the given parameters /// Adds a shadow with the given parameters.
void addShadow(ui.Offset offset, ui.Color color, double blur) { void addShadow(ui.Offset offset, ui.Color color, double blur) {
_builder.addLayerOnTop( _builder.addLayerOnTop(
new ui.DrawLooperLayerInfo() new ui.DrawLooperLayerInfo()
......
...@@ -7,21 +7,21 @@ import 'dart:ui' as ui; ...@@ -7,21 +7,21 @@ import 'dart:ui' as ui;
import 'basic_types.dart'; import 'basic_types.dart';
import 'text_style.dart'; import 'text_style.dart';
/// An immutable span of text /// An immutable span of text.
abstract class TextSpan { abstract class TextSpan {
// This class must be immutable, because we won't notice when it changes // This class must be immutable, because we won't notice when it changes.
String toString([String prefix = '']); String toString([String prefix = '']);
void build(ui.ParagraphBuilder builder); void build(ui.ParagraphBuilder builder);
ui.ParagraphStyle get paragraphStyle => null; ui.ParagraphStyle get paragraphStyle => null;
} }
/// An immutable span of unstyled text /// An immutable span of unstyled text.
class PlainTextSpan extends TextSpan { class PlainTextSpan extends TextSpan {
PlainTextSpan(this.text) { PlainTextSpan(this.text) {
assert(text != null); assert(text != null);
} }
/// The text contained in the span /// The text contained in the span.
final String text; final String text;
void build(ui.ParagraphBuilder builder) { void build(ui.ParagraphBuilder builder) {
...@@ -40,17 +40,17 @@ class PlainTextSpan extends TextSpan { ...@@ -40,17 +40,17 @@ class PlainTextSpan extends TextSpan {
String toString([String prefix = '']) => '$prefix$runtimeType: "$text"'; String toString([String prefix = '']) => '$prefix$runtimeType: "$text"';
} }
/// An immutable text span that applies a style to a list of children /// An immutable text span that applies a style to a list of children.
class StyledTextSpan extends TextSpan { class StyledTextSpan extends TextSpan {
StyledTextSpan(this.style, this.children) { StyledTextSpan(this.style, this.children) {
assert(style != null); assert(style != null);
assert(children != null); assert(children != null);
} }
/// The style to apply to the children /// The style to apply to the children.
final TextStyle style; final TextStyle style;
/// The children to which the style is applied /// The children to which the style is applied.
final List<TextSpan> children; final List<TextSpan> children;
void build(ui.ParagraphBuilder builder) { void build(ui.ParagraphBuilder builder) {
...@@ -97,7 +97,7 @@ class StyledTextSpan extends TextSpan { ...@@ -97,7 +97,7 @@ class StyledTextSpan extends TextSpan {
} }
} }
/// An object that paints a [TextSpan] into a canvas /// An object that paints a [TextSpan] into a canvas.
class TextPainter { class TextPainter {
TextPainter(TextSpan text) { TextPainter(TextSpan text) {
this.text = text; this.text = text;
...@@ -107,7 +107,7 @@ class TextPainter { ...@@ -107,7 +107,7 @@ class TextPainter {
bool _needsLayout = true; bool _needsLayout = true;
TextSpan _text; TextSpan _text;
/// The (potentially styled) text to paint /// The (potentially styled) text to paint.
TextSpan get text => _text; TextSpan get text => _text;
void set text(TextSpan value) { void set text(TextSpan value) {
if (_text == value) if (_text == value)
...@@ -119,7 +119,7 @@ class TextPainter { ...@@ -119,7 +119,7 @@ class TextPainter {
_needsLayout = true; _needsLayout = true;
} }
/// The minimum width at which to layout the text /// The minimum width at which to layout the text.
double get minWidth => _paragraph.minWidth; double get minWidth => _paragraph.minWidth;
void set minWidth(value) { void set minWidth(value) {
if (_paragraph.minWidth == value) if (_paragraph.minWidth == value)
...@@ -128,7 +128,7 @@ class TextPainter { ...@@ -128,7 +128,7 @@ class TextPainter {
_needsLayout = true; _needsLayout = true;
} }
/// The maximum width at which to layout the text /// The maximum width at which to layout the text.
double get maxWidth => _paragraph.maxWidth; double get maxWidth => _paragraph.maxWidth;
void set maxWidth(value) { void set maxWidth(value) {
if (_paragraph.maxWidth == value) if (_paragraph.maxWidth == value)
...@@ -137,7 +137,7 @@ class TextPainter { ...@@ -137,7 +137,7 @@ class TextPainter {
_needsLayout = true; _needsLayout = true;
} }
/// The minimum height at which to layout the text /// The minimum height at which to layout the text.
double get minHeight => _paragraph.minHeight; double get minHeight => _paragraph.minHeight;
void set minHeight(value) { void set minHeight(value) {
if (_paragraph.minHeight == value) if (_paragraph.minHeight == value)
...@@ -146,7 +146,7 @@ class TextPainter { ...@@ -146,7 +146,7 @@ class TextPainter {
_needsLayout = true; _needsLayout = true;
} }
/// The maximum height at which to layout the text /// The maximum height at which to layout the text.
double get maxHeight => _paragraph.maxHeight; double get maxHeight => _paragraph.maxHeight;
void set maxHeight(value) { void set maxHeight(value) {
if (_paragraph.maxHeight == value) if (_paragraph.maxHeight == value)
...@@ -165,13 +165,13 @@ class TextPainter { ...@@ -165,13 +165,13 @@ class TextPainter {
return layoutValue.ceilToDouble(); return layoutValue.ceilToDouble();
} }
/// The width at which decreasing the width of the text would prevent it from painting itself completely within its bounds /// The width at which decreasing the width of the text would prevent it from painting itself completely within its bounds.
double get minIntrinsicWidth { double get minIntrinsicWidth {
assert(!_needsLayout); assert(!_needsLayout);
return _applyFloatingPointHack(_paragraph.minIntrinsicWidth); return _applyFloatingPointHack(_paragraph.minIntrinsicWidth);
} }
/// The width at which increasing the width of the text no longer decreases the height /// The width at which increasing the width of the text no longer decreases the height.
double get maxIntrinsicWidth { double get maxIntrinsicWidth {
assert(!_needsLayout); assert(!_needsLayout);
return _applyFloatingPointHack(_paragraph.maxIntrinsicWidth); return _applyFloatingPointHack(_paragraph.maxIntrinsicWidth);
...@@ -192,7 +192,7 @@ class TextPainter { ...@@ -192,7 +192,7 @@ class TextPainter {
return new Size(width, height); return new Size(width, height);
} }
/// The distance from the top of the text to the first baseline of the given type /// Returns the distance from the top of the text to the first baseline of the given type.
double computeDistanceToActualBaseline(TextBaseline baseline) { double computeDistanceToActualBaseline(TextBaseline baseline) {
assert(!_needsLayout); assert(!_needsLayout);
switch (baseline) { switch (baseline) {
...@@ -203,7 +203,7 @@ class TextPainter { ...@@ -203,7 +203,7 @@ class TextPainter {
} }
} }
/// Compute the visual position of the glyphs for painting the text /// Computes the visual position of the glyphs for painting the text.
void layout() { void layout() {
if (!_needsLayout) if (!_needsLayout)
return; return;
...@@ -211,7 +211,7 @@ class TextPainter { ...@@ -211,7 +211,7 @@ class TextPainter {
_needsLayout = false; _needsLayout = false;
} }
/// Paint the text onto the given canvas at the given offset /// Paints the text onto the given canvas at the given offset.
void paint(ui.Canvas canvas, ui.Offset offset) { void paint(ui.Canvas canvas, ui.Offset offset) {
assert(!_needsLayout && "Please call layout() before paint() to position the text before painting it." is String); assert(!_needsLayout && "Please call layout() before paint() to position the text before painting it." is String);
_paragraph.paint(canvas, offset); _paragraph.paint(canvas, offset);
......
...@@ -6,7 +6,7 @@ import 'dart:ui' as ui; ...@@ -6,7 +6,7 @@ import 'dart:ui' as ui;
import 'basic_types.dart'; import 'basic_types.dart';
/// An immutable style in which paint text /// An immutable style in which paint text.
class TextStyle { class TextStyle {
const TextStyle({ const TextStyle({
this.inherit: true, this.inherit: true,
......
...@@ -11,13 +11,13 @@ import 'basic_types.dart'; ...@@ -11,13 +11,13 @@ import 'basic_types.dart';
class MatrixUtils { class MatrixUtils {
MatrixUtils._(); MatrixUtils._();
/// If the given transform is nothing but a 2D translation, then returns that /// Returns the given [transform] matrix as Offset, if the matrix is nothing
/// translation as an Offset. /// but a 2D translation.
/// ///
/// Otherwise, returns null. /// Returns null, otherwise.
static Offset getAsTranslation(Matrix4 transform) { static Offset getAsTranslation(Matrix4 transform) {
Float64List values = transform.storage; Float64List values = transform.storage;
// values are stored in column-major order // Values are stored in column-major order.
if (values[0] == 1.0 && if (values[0] == 1.0 &&
values[1] == 0.0 && values[1] == 0.0 &&
values[2] == 0.0 && values[2] == 0.0 &&
...@@ -37,4 +37,4 @@ class MatrixUtils { ...@@ -37,4 +37,4 @@ class MatrixUtils {
return null; return null;
} }
} }
\ No newline at end of file
...@@ -10,10 +10,10 @@ import 'object.dart'; ...@@ -10,10 +10,10 @@ import 'object.dart';
/// Hosts the edge parameters and vends useful methods to construct expressions /// Hosts the edge parameters and vends useful methods to construct expressions
/// for constraints. Also sets up and manages implicit constraints and edit /// for constraints. Also sets up and manages implicit constraints and edit
/// variables. Used as a mixin by layout containers and parent data instances /// variables. Used as a mixin by layout containers and parent data instances
/// of render boxes taking part in auto layout /// of render boxes taking part in auto layout.
abstract class _AutoLayoutParamMixin { abstract class _AutoLayoutParamMixin {
// Ideally, the edges would all be final, but then they would have to be // Ideally, the edges would all be final, but then they would have to be
// initialized before the constructor. Not sure how to do that using a Mixin // initialized before the constructor. Not sure how to do that using a Mixin.
al.Param _leftEdge; al.Param _leftEdge;
al.Param _rightEdge; al.Param _rightEdge;
al.Param _topEdge; al.Param _topEdge;
...@@ -55,9 +55,11 @@ abstract class _AutoLayoutParamMixin { ...@@ -55,9 +55,11 @@ abstract class _AutoLayoutParamMixin {
solver.suggestValueForVariable(_rightEdge.variable, size.width); solver.suggestValueForVariable(_rightEdge.variable, size.width);
} }
/// Called when the solver has updated at least one of the layout parameters /// Applies the parameter updates.
/// of this object. The object is now responsible for applying this update to ///
/// it other properties (if necessary) /// This method is called when the solver has updated at least one of the
/// layout parameters of this object. The object is now responsible for
/// applying this update to its other properties (if necessary).
void _applyAutolayoutParameterUpdates(); void _applyAutolayoutParameterUpdates();
/// Returns the set of implicit constraints that need to be applied to all /// Returns the set of implicit constraints that need to be applied to all
...@@ -139,7 +141,7 @@ class RenderAutoLayout extends RenderBox ...@@ -139,7 +141,7 @@ class RenderAutoLayout extends RenderBox
List<al.Constraint> _explicitConstraints = new List<al.Constraint>(); List<al.Constraint> _explicitConstraints = new List<al.Constraint>();
/// Adds all the given constraints to the solver. Either all constraints are /// Adds all the given constraints to the solver. Either all constraints are
/// added or none /// added or none.
al.Result addConstraints(List<al.Constraint> constraints) { al.Result addConstraints(List<al.Constraint> constraints) {
al.Result result = _solver.addConstraints(constraints); al.Result result = _solver.addConstraints(constraints);
if (result == al.Result.success) { if (result == al.Result.success) {
...@@ -149,7 +151,7 @@ class RenderAutoLayout extends RenderBox ...@@ -149,7 +151,7 @@ class RenderAutoLayout extends RenderBox
return result; return result;
} }
/// Add the given constraint to the solver. /// Adds the given constraint to the solver.
al.Result addConstraint(al.Constraint constraint) { al.Result addConstraint(al.Constraint constraint) {
al.Result result = _solver.addConstraint(constraint); al.Result result = _solver.addConstraint(constraint);
......
...@@ -22,7 +22,7 @@ typedef void MetricListener(Size size); ...@@ -22,7 +22,7 @@ typedef void MetricListener(Size size);
class _PointerState { class _PointerState {
_PointerState(this.lastPosition); _PointerState(this.lastPosition);
int get pointer => _pointer; // the identifier used in PointerEvent objects int get pointer => _pointer; // The identifier used in PointerEvent objects.
int _pointer; int _pointer;
static int _pointerCount = 0; static int _pointerCount = 0;
void startNewPointer() { void startNewPointer() {
...@@ -45,7 +45,7 @@ class _PointerState { ...@@ -45,7 +45,7 @@ class _PointerState {
} }
class _PointerEventConverter { class _PointerEventConverter {
// map from platform pointer identifiers to PointerEvent pointer identifiers // Map from platform pointer identifiers to PointerEvent pointer identifiers.
static Map<int, _PointerState> _pointers = <int, _PointerState>{}; static Map<int, _PointerState> _pointers = <int, _PointerState>{};
static Iterable<PointerEvent> expand(Iterable<Pointer> packet) sync* { static Iterable<PointerEvent> expand(Iterable<Pointer> packet) sync* {
...@@ -201,7 +201,7 @@ class BindingObserver { ...@@ -201,7 +201,7 @@ class BindingObserver {
void didChangeLocale(ui.Locale locale) { } void didChangeLocale(ui.Locale locale) { }
} }
/// The glue between the render tree and the Flutter engine /// The glue between the render tree and the Flutter engine.
class FlutterBinding extends HitTestTarget { class FlutterBinding extends HitTestTarget {
FlutterBinding({ RenderBox root: null, RenderView renderViewOverride }) { FlutterBinding({ RenderBox root: null, RenderView renderViewOverride }) {
...@@ -227,11 +227,11 @@ class FlutterBinding extends HitTestTarget { ...@@ -227,11 +227,11 @@ class FlutterBinding extends HitTestTarget {
assert(_instance == this); assert(_instance == this);
} }
/// The singleton instance of the binding /// The singleton instance of the binding.
static FlutterBinding get instance => _instance; static FlutterBinding get instance => _instance;
static FlutterBinding _instance; static FlutterBinding _instance;
/// The render tree that's attached to the output surface /// The render tree that's attached to the output surface.
RenderView get renderView => _renderView; RenderView get renderView => _renderView;
RenderView _renderView; RenderView _renderView;
...@@ -260,7 +260,7 @@ class FlutterBinding extends HitTestTarget { ...@@ -260,7 +260,7 @@ class FlutterBinding extends HitTestTarget {
beginFrame(); beginFrame();
} }
/// Pump the rendering pipeline to generate a frame for the given time stamp /// Pump the rendering pipeline to generate a frame for the given time stamp.
void beginFrame() { void beginFrame() {
RenderObject.flushLayout(); RenderObject.flushLayout();
_renderView.updateCompositingBits(); _renderView.updateCompositingBits();
...@@ -287,12 +287,13 @@ class FlutterBinding extends HitTestTarget { ...@@ -287,12 +287,13 @@ class FlutterBinding extends HitTestTarget {
_handlePointerEvent(event); _handlePointerEvent(event);
} }
/// A router that routes all pointer events received from the engine /// A router that routes all pointer events received from the engine.
final PointerRouter pointerRouter = new PointerRouter(); final PointerRouter pointerRouter = new PointerRouter();
/// State for all pointers which are currently down. /// State for all pointers which are currently down.
///
/// The state of hovering pointers is not tracked because that would require /// The state of hovering pointers is not tracked because that would require
/// hit-testing on every fram.e /// hit-testing on every frame.
Map<int, HitTestResult> _hitTests = <int, HitTestResult>{}; Map<int, HitTestResult> _hitTests = <int, HitTestResult>{};
void _handlePointerEvent(PointerEvent event) { void _handlePointerEvent(PointerEvent event) {
...@@ -312,7 +313,7 @@ class FlutterBinding extends HitTestTarget { ...@@ -312,7 +313,7 @@ class FlutterBinding extends HitTestTarget {
} }
} }
/// Determine which [HitTestTarget] objects are located at a given position /// Determine which [HitTestTarget] objects are located at a given position.
HitTestResult hitTest(Point position) { HitTestResult hitTest(Point position) {
HitTestResult result = new HitTestResult(); HitTestResult result = new HitTestResult();
_renderView.hitTest(result, position: position); _renderView.hitTest(result, position: position);
...@@ -337,12 +338,12 @@ class FlutterBinding extends HitTestTarget { ...@@ -337,12 +338,12 @@ class FlutterBinding extends HitTestTarget {
} }
} }
/// Prints a textual representation of the entire render tree /// Prints a textual representation of the entire render tree.
void debugDumpRenderTree() { void debugDumpRenderTree() {
debugPrint(FlutterBinding.instance.renderView.toStringDeep()); debugPrint(FlutterBinding.instance.renderView.toStringDeep());
} }
/// Prints a textual representation of the entire layer tree /// Prints a textual representation of the entire layer tree.
void debugDumpLayerTree() { void debugDumpLayerTree() {
debugPrint(FlutterBinding.instance.renderView.layer.toStringDeep()); debugPrint(FlutterBinding.instance.renderView.layer.toStringDeep());
} }
...@@ -9,21 +9,21 @@ import 'package:vector_math/vector_math_64.dart'; ...@@ -9,21 +9,21 @@ import 'package:vector_math/vector_math_64.dart';
import 'box.dart'; import 'box.dart';
import 'object.dart'; import 'object.dart';
/// Parent data for use with [RenderBlockBase] /// Parent data for use with [RenderBlockBase].
class BlockParentData extends ContainerBoxParentDataMixin<RenderBox> { } class BlockParentData extends ContainerBoxParentDataMixin<RenderBox> { }
/// The direction in which the block should lay out /// The direction in which the block should lay out.
enum BlockDirection { enum BlockDirection {
/// Children are arranged horizontally, from left to right /// Children are arranged horizontally, from left to right.
horizontal, horizontal,
/// Children are arranged vertically, from top to bottom /// Children are arranged vertically, from top to bottom.
vertical vertical
} }
typedef double _ChildSizingFunction(RenderBox child, BoxConstraints constraints); typedef double _ChildSizingFunction(RenderBox child, BoxConstraints constraints);
typedef double _Constrainer(double value); typedef double _Constrainer(double value);
/// Implements the block layout algorithm /// Implements the block layout algorithm.
/// ///
/// In block layout, children are arranged linearly along the main axis (either /// In block layout, children are arranged linearly along the main axis (either
/// horizontally or vertically). In the cross axis, children are stretched to /// horizontally or vertically). In the cross axis, children are stretched to
...@@ -49,7 +49,7 @@ abstract class RenderBlockBase extends RenderBox with ContainerRenderObjectMixin ...@@ -49,7 +49,7 @@ abstract class RenderBlockBase extends RenderBox with ContainerRenderObjectMixin
child.parentData = new BlockParentData(); child.parentData = new BlockParentData();
} }
/// The direction to use as the main axis /// The direction to use as the main axis.
BlockDirection get direction => _direction; BlockDirection get direction => _direction;
BlockDirection _direction; BlockDirection _direction;
void set direction (BlockDirection value) { void set direction (BlockDirection value) {
...@@ -59,7 +59,7 @@ abstract class RenderBlockBase extends RenderBox with ContainerRenderObjectMixin ...@@ -59,7 +59,7 @@ abstract class RenderBlockBase extends RenderBox with ContainerRenderObjectMixin
} }
} }
/// If non-null, forces children to be exactly this large in the main axis /// If non-null, forces children to be exactly this large in the main axis.
double get itemExtent => _itemExtent; double get itemExtent => _itemExtent;
double _itemExtent; double _itemExtent;
void set itemExtent(double value) { void set itemExtent(double value) {
...@@ -69,7 +69,7 @@ abstract class RenderBlockBase extends RenderBox with ContainerRenderObjectMixin ...@@ -69,7 +69,7 @@ abstract class RenderBlockBase extends RenderBox with ContainerRenderObjectMixin
} }
} }
/// Forces the block to be at least this large in the main-axis /// Forces the block to be at least this large in the main-axis.
double get minExtent => _minExtent; double get minExtent => _minExtent;
double _minExtent; double _minExtent;
void set minExtent(double value) { void set minExtent(double value) {
...@@ -79,7 +79,7 @@ abstract class RenderBlockBase extends RenderBox with ContainerRenderObjectMixin ...@@ -79,7 +79,7 @@ abstract class RenderBlockBase extends RenderBox with ContainerRenderObjectMixin
} }
} }
/// Whether the main axis is vertical /// Whether the main axis is vertical.
bool get isVertical => _direction == BlockDirection.vertical; bool get isVertical => _direction == BlockDirection.vertical;
BoxConstraints _getInnerConstraints(BoxConstraints constraints) { BoxConstraints _getInnerConstraints(BoxConstraints constraints) {
...@@ -124,7 +124,7 @@ abstract class RenderBlockBase extends RenderBox with ContainerRenderObjectMixin ...@@ -124,7 +124,7 @@ abstract class RenderBlockBase extends RenderBox with ContainerRenderObjectMixin
} }
} }
/// A block layout with a concrete set of children /// A block layout with a concrete set of children.
class RenderBlock extends RenderBlockBase { class RenderBlock extends RenderBlockBase {
RenderBlock({ RenderBlock({
...@@ -214,7 +214,7 @@ class RenderBlock extends RenderBlockBase { ...@@ -214,7 +214,7 @@ class RenderBlock extends RenderBlockBase {
void performLayout() { void performLayout() {
assert((isVertical ? constraints.maxHeight >= double.INFINITY : constraints.maxWidth >= double.INFINITY) && assert((isVertical ? constraints.maxHeight >= double.INFINITY : constraints.maxWidth >= double.INFINITY) &&
'RenderBlock does not clip or resize its children, so it must be placed in a parent that does not constrain ' + 'RenderBlock does not clip or resize its children, so it must be placed in a parent that does not constrain '
'the block\'s main direction. You probably want to put the RenderBlock inside a RenderViewport.' is String); 'the block\'s main direction. You probably want to put the RenderBlock inside a RenderViewport.' is String);
super.performLayout(); super.performLayout();
} }
...@@ -229,7 +229,7 @@ class RenderBlock extends RenderBlockBase { ...@@ -229,7 +229,7 @@ class RenderBlock extends RenderBlockBase {
} }
/// A block layout whose children depend on its layout /// A block layout whose children depend on its layout.
/// ///
/// This class invokes a callbacks for layout and intrinsic dimensions. The main /// This class invokes a callbacks for layout and intrinsic dimensions. The main
/// [callback] (constructor argument and property) is expected to modify the /// [callback] (constructor argument and property) is expected to modify the
...@@ -261,7 +261,7 @@ class RenderBlockViewport extends RenderBlockBase { ...@@ -261,7 +261,7 @@ class RenderBlockViewport extends RenderBlockBase {
bool _inCallback = false; bool _inCallback = false;
bool get hasLayer => true; bool get hasLayer => true;
/// Called during [layout] to determine the blocks children /// Called during [layout] to determine the blocks children.
/// ///
/// Typically the callback will mutate the child list appropriately, for /// Typically the callback will mutate the child list appropriately, for
/// example so the child list contains only visible children. /// example so the child list contains only visible children.
...@@ -275,7 +275,7 @@ class RenderBlockViewport extends RenderBlockBase { ...@@ -275,7 +275,7 @@ class RenderBlockViewport extends RenderBlockBase {
markNeedsLayout(); markNeedsLayout();
} }
/// Returns the total main-axis extent of all the children that could be included by [callback] in one go /// Returns the total main-axis extent of all the children that could be included by [callback] in one go.
ExtentCallback get totalExtentCallback => _totalExtentCallback; ExtentCallback get totalExtentCallback => _totalExtentCallback;
ExtentCallback _totalExtentCallback; ExtentCallback _totalExtentCallback;
void set totalExtentCallback(ExtentCallback value) { void set totalExtentCallback(ExtentCallback value) {
...@@ -286,7 +286,7 @@ class RenderBlockViewport extends RenderBlockBase { ...@@ -286,7 +286,7 @@ class RenderBlockViewport extends RenderBlockBase {
markNeedsLayout(); markNeedsLayout();
} }
/// Returns the minimum cross-axis extent across all the children that could be included by [callback] in one go /// Returns the minimum cross-axis extent across all the children that could be included by [callback] in one go.
ExtentCallback get minCrossAxisExtentCallback => _minCrossAxisExtentCallback; ExtentCallback get minCrossAxisExtentCallback => _minCrossAxisExtentCallback;
ExtentCallback _minCrossAxisExtentCallback; ExtentCallback _minCrossAxisExtentCallback;
void set minCrossAxisExtentCallback(ExtentCallback value) { void set minCrossAxisExtentCallback(ExtentCallback value) {
...@@ -297,7 +297,7 @@ class RenderBlockViewport extends RenderBlockBase { ...@@ -297,7 +297,7 @@ class RenderBlockViewport extends RenderBlockBase {
markNeedsLayout(); markNeedsLayout();
} }
/// Returns the maximum cross-axis extent across all the children that could be included by [callback] in one go /// Returns the maximum cross-axis extent across all the children that could be included by [callback] in one go.
ExtentCallback get maxCrossAxisExtentCallback => _maxCrossAxisExtentCallback; ExtentCallback get maxCrossAxisExtentCallback => _maxCrossAxisExtentCallback;
ExtentCallback _maxCrossAxisExtentCallback; ExtentCallback _maxCrossAxisExtentCallback;
void set maxCrossAxisExtentCallback(ExtentCallback value) { void set maxCrossAxisExtentCallback(ExtentCallback value) {
...@@ -329,7 +329,7 @@ class RenderBlockViewport extends RenderBlockBase { ...@@ -329,7 +329,7 @@ class RenderBlockViewport extends RenderBlockBase {
_overlayPainter?.detach(); _overlayPainter?.detach();
} }
/// The offset at which to paint the first child /// The offset at which to paint the first child.
/// ///
/// Note: you can modify this property from within [callback], if necessary. /// Note: you can modify this property from within [callback], if necessary.
double get startOffset => _startOffset; double get startOffset => _startOffset;
...@@ -354,10 +354,7 @@ class RenderBlockViewport extends RenderBlockBase { ...@@ -354,10 +354,7 @@ class RenderBlockViewport extends RenderBlockBase {
try { try {
_inCallback = true; _inCallback = true;
result = intrinsicCallback(constraints); result = intrinsicCallback(constraints);
if (result == null) result = constrainer(result ?? 0.0);
result = constrainer(0.0);
else
result = constrainer(result);
} finally { } finally {
_inCallback = false; _inCallback = false;
} }
......
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