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 'dart:sky' as sky; | 5 import 'dart:sky' as sky; |
6 | 6 |
7 import 'package:sky/theme/colors.dart' as colors; | 7 import 'package:sky/widgets/theme.dart'; |
8 | 8 |
9 import 'basic.dart'; | 9 import 'basic.dart'; |
10 import 'toggleable.dart'; | 10 import 'toggleable.dart'; |
11 export 'toggleable.dart' show ValueChanged; | 11 export 'toggleable.dart' show ValueChanged; |
12 | 12 |
13 const double _kMidpoint = 0.5; | 13 const double _kMidpoint = 0.5; |
14 const sky.Color _kUncheckedColor = const sky.Color(0x8A000000); | 14 const sky.Color _kUncheckedColor = const sky.Color(0x8A000000); |
15 // TODO(jackson): This should change colors with the theme | |
16 sky.Color _kCheckedColor = colors.Purple[500]; | |
17 const double _kEdgeSize = 20.0; | 15 const double _kEdgeSize = 20.0; |
18 const double _kEdgeRadius = 1.0; | 16 const double _kEdgeRadius = 1.0; |
19 | 17 |
20 class Checkbox extends Toggleable { | 18 class Checkbox extends Toggleable { |
21 | 19 |
22 Checkbox({ | 20 Checkbox({ |
23 String key, | 21 String key, |
24 bool value, | 22 bool value, |
25 ValueChanged onChanged | 23 ValueChanged onChanged |
26 }) : super(key: key, value: value, onChanged: onChanged); | 24 }) : super(key: key, value: value, onChanged: onChanged); |
(...skipping 25 matching lines...) Expand all Loading... |
52 ) | 50 ) |
53 ); | 51 ); |
54 canvas.drawRRect(rrect, paint); | 52 canvas.drawRRect(rrect, paint); |
55 } | 53 } |
56 | 54 |
57 if (toggleAnimation.value > _kMidpoint) { | 55 if (toggleAnimation.value > _kMidpoint) { |
58 double t = (toggleAnimation.value - _kMidpoint) / (1.0 - _kMidpoint); | 56 double t = (toggleAnimation.value - _kMidpoint) / (1.0 - _kMidpoint); |
59 | 57 |
60 // Solid filled rrect | 58 // Solid filled rrect |
61 paint.setStyle(sky.PaintingStyle.strokeAndFill); | 59 paint.setStyle(sky.PaintingStyle.strokeAndFill); |
| 60 Color themeColor = Theme.of(this).color[500]; |
62 paint.color = new Color.fromARGB((t * 255).floor(), | 61 paint.color = new Color.fromARGB((t * 255).floor(), |
63 _kCheckedColor.red, | 62 themeColor.red, |
64 _kCheckedColor.green, | 63 themeColor.green, |
65 _kCheckedColor.blue); | 64 themeColor.blue); |
66 canvas.drawRRect(rrect, paint); | 65 canvas.drawRRect(rrect, paint); |
67 | 66 |
68 // White inner check | 67 // White inner check |
69 paint.color = const sky.Color(0xFFFFFFFF); | 68 paint.color = const sky.Color(0xFFFFFFFF); |
70 paint.setStyle(sky.PaintingStyle.stroke); | 69 paint.setStyle(sky.PaintingStyle.stroke); |
71 sky.Path path = new sky.Path(); | 70 sky.Path path = new sky.Path(); |
72 sky.Point start = new sky.Point(_kEdgeSize * 0.2, _kEdgeSize * 0.5); | 71 sky.Point start = new sky.Point(_kEdgeSize * 0.2, _kEdgeSize * 0.5); |
73 sky.Point mid = new sky.Point(_kEdgeSize * 0.4, _kEdgeSize * 0.7); | 72 sky.Point mid = new sky.Point(_kEdgeSize * 0.4, _kEdgeSize * 0.7); |
74 sky.Point end = new sky.Point(_kEdgeSize * 0.8, _kEdgeSize * 0.3); | 73 sky.Point end = new sky.Point(_kEdgeSize * 0.8, _kEdgeSize * 0.3); |
75 Point lerp(Point p1, Point p2, double t) | 74 Point lerp(Point p1, Point p2, double t) |
76 => new Point(p1.x * (1.0 - t) + p2.x * t, p1.y * (1.0 - t) + p2.y * t); | 75 => new Point(p1.x * (1.0 - t) + p2.x * t, p1.y * (1.0 - t) + p2.y * t); |
77 sky.Point drawStart = lerp(start, mid, 1.0 - t); | 76 sky.Point drawStart = lerp(start, mid, 1.0 - t); |
78 sky.Point drawEnd = lerp(mid, end, t); | 77 sky.Point drawEnd = lerp(mid, end, t); |
79 path.moveTo(drawStart.x, drawStart.y); | 78 path.moveTo(drawStart.x, drawStart.y); |
80 path.lineTo(mid.x, mid.y); | 79 path.lineTo(mid.x, mid.y); |
81 path.lineTo(drawEnd.x, drawEnd.y); | 80 path.lineTo(drawEnd.x, drawEnd.y); |
82 canvas.drawPath(path, paint); | 81 canvas.drawPath(path, paint); |
83 } | 82 } |
84 } | 83 } |
85 } | 84 } |
OLD | NEW |