예제 #1
0
        public override Simulation createBallisticSimulation(ScrollMetrics position, double velocity)
        {
            Tolerance tolerance = this.tolerance;

            if (position.outOfRange())
            {
                double?end = null;
                if (position.pixels > position.maxScrollExtent)
                {
                    end = position.maxScrollExtent;
                }

                if (position.pixels < position.minScrollExtent)
                {
                    end = position.minScrollExtent;
                }

                D.assert(end != null);
                return(new ScrollSpringSimulation(
                           this.spring,
                           position.pixels,
                           position.maxScrollExtent,
                           Math.Min(0.0, velocity),
                           tolerance: tolerance
                           ));
            }

            if (velocity.abs() < tolerance.velocity)
            {
                return(null);
            }

            if (velocity > 0.0 && position.pixels >= position.maxScrollExtent)
            {
                return(null);
            }

            if (velocity < 0.0 && position.pixels <= position.minScrollExtent)
            {
                return(null);
            }

            return(new ClampingScrollSimulation(
                       position: position.pixels,
                       velocity: velocity,
                       tolerance: tolerance
                       ));
        }
예제 #2
0
        public override Simulation createBallisticSimulation(ScrollMetrics position, float velocity)
        {
            Tolerance tolerance = this.tolerance;

            if (velocity.abs() >= tolerance.velocity || position.outOfRange())
            {
                return(new BouncingScrollSimulation(
                           spring: this.spring,
                           position: position.pixels,
                           velocity: velocity * 0.91f,
                           leadingExtent: position.minScrollExtent,
                           trailingExtent: position.maxScrollExtent,
                           tolerance: tolerance
                           ));
            }

            return(null);
        }
예제 #3
0
        public override double applyPhysicsToUserOffset(ScrollMetrics position, double offset)
        {
            D.assert(position.minScrollExtent <= position.maxScrollExtent);

            if (!position.outOfRange())
            {
                return(offset);
            }

            double overscrollPastStart = Math.Max(position.minScrollExtent - position.pixels, 0.0);
            double overscrollPastEnd   = Math.Max(position.pixels - position.maxScrollExtent, 0.0);
            double overscrollPast      = Math.Max(overscrollPastStart, overscrollPastEnd);
            bool   easing = (overscrollPastStart > 0.0 && offset < 0.0) || (overscrollPastEnd > 0.0 && offset > 0.0);

            double friction = easing
                ? this.frictionFactor((overscrollPast - offset.abs()) / position.viewportDimension)
                : this.frictionFactor(overscrollPast / position.viewportDimension);
            double direction = offset.sign();

            return(direction * _applyFriction(overscrollPast, offset.abs(), friction));
        }
예제 #4
0
        public override float applyPhysicsToUserOffset(ScrollMetrics position, float offset)
        {
            D.assert(offset != 0.0);
            D.assert(position.minScrollExtent <= position.maxScrollExtent);

            if (!position.outOfRange())
            {
                return(offset);
            }

            var  overScrollPastStart = Math.Max(position.minScrollExtent - position.pixels, 0.0f);
            var  overScrollPastEnd   = Math.Max(position.pixels - position.maxScrollExtent, 0.0f);
            var  overScrollPast      = Mathf.Max(overScrollPastStart, overScrollPastEnd);
            bool easing = (overScrollPastStart > 0.0 && offset < 0.0) ||
                          (overScrollPastEnd > 0.0 && offset > 0.0);

            var friction = easing
                ? frictionFactor(
                (overScrollPast - offset.abs()) / position.viewportDimension)
                : frictionFactor(overScrollPast / position.viewportDimension);
            float direction = offset.sign();

            return(direction * _applyFriction(overScrollPast, offset.abs(), friction));
        }