OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 import 'package:sky/framework/fn2.dart'; | 5 import 'package:sky/framework/fn2.dart'; |
6 import 'package:vector_math/vector_math.dart'; | 6 import 'package:vector_math/vector_math.dart'; |
7 import 'package:sky/framework/rendering/box.dart'; | 7 import 'package:sky/framework/rendering/box.dart'; |
8 import 'package:sky/framework/rendering/object.dart'; | 8 import 'package:sky/framework/rendering/object.dart'; |
9 import 'package:sky/framework/theme2/colors.dart' as colors; | 9 import 'package:sky/framework/theme2/colors.dart' as colors; |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 return colors.Green[_colorIndexForPercentChange(percentChange)]; | 27 return colors.Green[_colorIndexForPercentChange(percentChange)]; |
28 return colors.Red[_colorIndexForPercentChange(percentChange)]; | 28 return colors.Red[_colorIndexForPercentChange(percentChange)]; |
29 } | 29 } |
30 | 30 |
31 UINode build() { | 31 UINode build() { |
32 // TODO(jackson): This should change colors with the theme | 32 // TODO(jackson): This should change colors with the theme |
33 Color color = _colorForPercentChange(percentChange); | 33 Color color = _colorForPercentChange(percentChange); |
34 const double size = 40.0; | 34 const double size = 40.0; |
35 var arrow = new CustomPaint(callback: (sky.Canvas canvas) { | 35 var arrow = new CustomPaint(callback: (sky.Canvas canvas) { |
36 Paint paint = new Paint()..color = color; | 36 Paint paint = new Paint()..color = color; |
37 paint.setStyle(sky.PaintingStyle.stroke); | 37 paint.strokeWidth = 1.0; |
38 paint.strokeWidth = 2.0; | |
39 var padding = paint.strokeWidth * 3.0; | 38 var padding = paint.strokeWidth * 3.0; |
40 var w = size - padding * 2.0; | 39 var r = size / 2.0 - padding; |
41 var h = size - padding * 2.0; | |
42 canvas.save(); | 40 canvas.save(); |
43 canvas.translate(padding, padding); | 41 canvas.translate(padding, padding); |
| 42 |
| 43 // The arrow (below) is drawn upwards by default. |
44 if (percentChange < 0.0) { | 44 if (percentChange < 0.0) { |
45 var cx = w / 2.0; | 45 canvas.translate(r, r); |
46 var cy = h / 2.0; | |
47 canvas.translate(cx, cy); | |
48 canvas.rotate(math.PI); | 46 canvas.rotate(math.PI); |
49 canvas.translate(-cx, -cy); | 47 canvas.translate(-r, -r); |
50 } | 48 } |
51 canvas.drawLine(0.0, h, w, h, paint); | 49 |
52 canvas.drawLine(w, h, w / 2.0, 0.0, paint); | 50 // Draw the (equliateral triangle) arrow. |
53 canvas.drawLine(w / 2.0, 0.0, 0.0, h, paint); | 51 var dx = math.sqrt(3.0) * r / 2.0; |
| 52 var path = new Path(); |
| 53 path.moveTo(r, 0.0); |
| 54 path.lineTo(r + dx, r * 1.5); |
| 55 path.lineTo(r - dx, r * 1.5); |
| 56 path.lineTo(r, 0.0); |
| 57 path.close(); |
| 58 paint.setStyle(sky.PaintingStyle.fill); |
| 59 canvas.drawPath(path, paint); |
| 60 |
| 61 // Draw a circle that circumscribes the arrow. |
| 62 paint.setStyle(sky.PaintingStyle.stroke); |
| 63 canvas.drawCircle(r, r, r + 2.0, paint); |
| 64 |
54 canvas.restore(); | 65 canvas.restore(); |
55 }); | 66 }); |
| 67 |
56 return new Container( | 68 return new Container( |
57 child: arrow, | 69 child: arrow, |
58 width: size, | 70 width: size, |
59 height: size, | 71 height: size, |
60 margin: const EdgeDims.symmetric(horizontal: 5.0)); | 72 margin: const EdgeDims.symmetric(horizontal: 5.0)); |
61 } | 73 } |
62 } | 74 } |
OLD | NEW |