Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: sky/framework/animation/scroll_curve.dart

Issue 1001373002: Organize sky/framework/animation (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/framework/animation/scroll_behavior.dart ('k') | sky/framework/animation/simulation.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 import 'dart:math' as math;
6 import 'mechanics.dart';
7 import 'simulation.dart';
8
9 const double _kSlope = 0.01;
10
11 abstract class ScrollCurve {
12 Simulation release(Particle particle) => null;
13
14 // Returns the new scroll offset.
15 double apply(double scrollOffset, double scrollDelta);
16 }
17
18 class BoundedScrollCurve extends ScrollCurve {
19 double minOffset;
20 double maxOffset;
21
22 BoundedScrollCurve({this.minOffset: 0.0, this.maxOffset});
23
24 double apply(double scrollOffset, double scrollDelta) {
25 double newScrollOffset = scrollOffset + scrollDelta;
26 if (minOffset != null)
27 newScrollOffset = math.max(minOffset, newScrollOffset);
28 if (maxOffset != null)
29 newScrollOffset = math.min(maxOffset, newScrollOffset);
30 return newScrollOffset;
31 }
32 }
33
34 class OverscrollCurve extends ScrollCurve {
35 Simulation release(Particle particle) {
36 if (particle.position >= 0.0)
37 return null;
38 System system = new ParticleClimbingRamp(
39 particle: particle,
40 box: new Box(max: 0.0),
41 slope: _kSlope,
42 targetPosition: 0.0);
43 return new Simulation(system,
44 terminationCondition: () => particle.position == 0.0);
45 }
46
47 double apply(double scrollOffset, double scrollDelta) {
48 double newScrollOffset = scrollOffset + scrollDelta;
49 if (newScrollOffset < 0.0) {
50 // If we're overscrolling, we want move the scroll offset 2x slower than
51 // we would otherwise. Therefore, we "rewind" the newScrollOffset by half
52 // the amount that we moved it above. Notice that we clap the "old" value
53 // to 0.0 so that we only reduce the portion of scrollDelta that's applied
54 // beyond 0.0.
55 newScrollOffset -= (newScrollOffset - math.min(0.0, scrollOffset)) / 2.0;
56 }
57 return newScrollOffset;
58 }
59 }
OLDNEW
« no previous file with comments | « sky/framework/animation/scroll_behavior.dart ('k') | sky/framework/animation/simulation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698