-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathTestAnimation2.dart
78 lines (65 loc) · 2.05 KB
/
TestAnimation2.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//Sample Code: Test Animation 2
import 'dart:html';
import 'dart:math';
import 'package:rikulo_ui/view.dart';
import 'package:rikulo_ui/gesture.dart';
import 'package:rikulo_ui/effect.dart';
import "package:rikulo_ui/html.dart";
View createCube(int size, String txt) {
View v = new View();
v.width = size;
v.height = size;
v.style.border = "2px solid #3D4C99";
v.style.borderRadius = "10px";
v.style.backgroundColor = "#5C73E5";
v.style.userSelect = "none";
v.style.zIndex = "10";
TextView txtv = new TextView(txt);
txtv.width = v.width;
txtv.style.lineHeight = "${v.height}px";
txtv.style.textAlign = "center";
txtv.style.color = "#EEEEEE";
txtv.style.fontFamily = "Arial";
txtv.style.fontWeight = "bold";
txtv.style.userSelect = "none";
v.addChild(txtv);
return v;
}
void main() {
final View mainView = new View()..addToDocument();
final View box = new Section();
box.width = 500;
box.height = 500;
box.left = 48;
box.top = 48;
box.style.border = "2px dashed #CCCCCC";
mainView.addChild(box);
final View cube = createCube(100, "Drag Me");
cube.left = 250;
cube.top = 250;
mainView.addChild(cube);
Rectangle range = new Rectangle(50, 50, 446 - 50, 446 - 50);
Element element = cube.node;
final num deceleration = 0.0005;
Motion motion;
new Dragger(element, snap: (Point ppos, Point pos) => Points.snap(range, pos),
start: (DraggerState dstate) {
if (motion != null)
motion.stop();
}, end: (DraggerState dstate) {
final Point vel = dstate.elementVelocity;
num speed = Points.norm(vel);
if (speed == 0)
return;
Point unitv = Points.divide(vel, speed);
Point pos = DomUtil.position(element);
motion = new Motion(move: (MotionState mstate) {
int elapsed = mstate.elapsedTime;
pos = Points.snap(range, pos + (unitv * speed * elapsed));
element.style.left = CssUtil.px(pos.x.toInt());
element.style.top = CssUtil.px(pos.y.toInt());
speed = max(0, speed - deceleration * elapsed);
return speed > 0;
})..run();
});
}