OLD | NEW |
| (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 'package:sky/framework/theme2/colors.dart' as colors; | |
6 | |
7 import '../fn2.dart'; | |
8 import '../rendering/object.dart'; | |
9 import 'button_base.dart'; | |
10 import 'ink_well.dart'; | |
11 import 'dart:sky' as sky; | |
12 | |
13 typedef void ValueChanged(value); | |
14 | |
15 class Radio extends ButtonBase { | |
16 | |
17 Radio({ | |
18 Object key, | |
19 this.value, | |
20 this.groupValue, | |
21 this.onChanged | |
22 }) : super(key: key); | |
23 | |
24 Object value; | |
25 Object groupValue; | |
26 ValueChanged onChanged; | |
27 | |
28 void syncFields(Radio source) { | |
29 value = source.value; | |
30 groupValue = source.groupValue; | |
31 onChanged = source.onChanged; | |
32 super.syncFields(source); | |
33 } | |
34 | |
35 UINode buildContent() { | |
36 // TODO(jackson): This should change colors with the theme | |
37 Color color = highlight ? colors.Purple[500] : const Color(0x8A000000); | |
38 const double kDiameter = 16.0; | |
39 const double kOuterRadius = kDiameter / 2; | |
40 const double kInnerRadius = 5.0; | |
41 return new EventListenerNode( | |
42 new Container( | |
43 margin: const EdgeDims.symmetric(horizontal: 5.0), | |
44 width: kDiameter, | |
45 height: kDiameter, | |
46 child: new CustomPaint( | |
47 callback: (sky.Canvas canvas, Size size) { | |
48 | |
49 Paint paint = new Paint()..color = color; | |
50 | |
51 // Draw the outer circle | |
52 paint.setStyle(sky.PaintingStyle.stroke); | |
53 paint.strokeWidth = 2.0; | |
54 canvas.drawCircle(kOuterRadius, kOuterRadius, kOuterRadius, paint); | |
55 | |
56 // Draw the inner circle | |
57 if (value == groupValue) { | |
58 paint.setStyle(sky.PaintingStyle.fill); | |
59 canvas.drawCircle(kOuterRadius, kOuterRadius, kInnerRadius, paint)
; | |
60 } | |
61 } | |
62 ) | |
63 ), | |
64 onGestureTap: _handleClick | |
65 ); | |
66 } | |
67 | |
68 void _handleClick(_) { | |
69 onChanged(value); | |
70 } | |
71 | |
72 } | |
OLD | NEW |