Chromium Code Reviews| 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 '../fn2.dart'; | 6 import '../fn2.dart'; |
| 7 import '../rendering/box.dart'; | |
| 8 import '../rendering/object.dart'; | |
| 6 import 'button_base.dart'; | 9 import 'button_base.dart'; |
| 7 import 'ink_well.dart'; | 10 import 'ink_well.dart'; |
| 8 | 11 |
| 9 typedef void ValueChanged(value); | 12 typedef void ValueChanged(value); |
| 10 | 13 |
| 11 class Radio extends ButtonBase { | 14 class Radio extends ButtonBase { |
| 12 Object value; | 15 Object value; |
| 13 Object groupValue; | 16 Object groupValue; |
| 14 ValueChanged onChanged; | 17 ValueChanged onChanged; |
| 15 | 18 |
| 16 static final Style _style = new Style(''' | 19 static const BoxDecoration highlightDecoration = const BoxDecoration( |
| 17 width: 14px; | 20 backgroundColor: const sky.Color.fromARGB(102, 153, 153, 153) |
| 18 height: 14px; | 21 ); |
|
abarth-chromium
2015/06/04 23:58:39
No need for this.
jackson
2015/06/05 00:23:10
Done.
| |
| 19 border-radius: 7px; | |
| 20 border: 1px solid blue; | |
| 21 margin: 0 5px;''' | |
| 22 ); | |
| 23 | 22 |
| 24 static final Style _highlightStyle = new Style(''' | 23 static const sky.Size outerSize = const sky.Size(outerRadius * 2, outerRadius * 2); |
|
abarth-chromium
2015/06/04 23:58:39
No need for this either.
jackson
2015/06/05 00:23:10
Done.
| |
| 25 width: 14px; | |
| 26 height: 14px; | |
| 27 border-radius: 7px; | |
| 28 border: 1px solid blue; | |
| 29 margin: 0 5px; | |
| 30 background-color: orange;''' | |
| 31 ); | |
| 32 | |
| 33 static final Style _dotStyle = new Style(''' | |
| 34 width: 10px; | |
| 35 height: 10px; | |
| 36 border-radius: 5px; | |
| 37 background-color: black; | |
| 38 margin: 2px;''' | |
| 39 ); | |
| 40 | 24 |
| 41 Radio({ | 25 Radio({ |
| 42 Object key, | 26 Object key, |
| 43 this.onChanged, | 27 this.onChanged, |
| 44 this.value, | 28 this.value, |
| 45 this.groupValue | 29 this.groupValue |
| 46 }) : super(key: key); | 30 }) : super(key: key); |
| 47 | 31 |
| 48 UINode buildContent() { | 32 UINode buildContent() { |
| 33 sky.Color color = highlight ? new sky.Color(0xFF673AB7) : new sky.Color(0x8A 000000); | |
|
eseidel
2015/06/04 23:50:54
I take it these are not material colors?
abarth-chromium
2015/06/04 23:58:38
const sky.Color
jackson
2015/06/05 00:23:10
Done.
| |
| 34 const double outerWidth = 16.0; | |
| 35 const double outerRadius = outerWidth / 2; | |
| 36 | |
| 37 CustomPaint buildDot() { | |
| 38 const double innerRadius = 5.0; | |
| 39 return new CustomPaint( | |
| 40 child: new Container(desiredSize: new sky.Size(outerWidth, outerWidth)), | |
| 41 callback: (RenderObjectDisplayList canvas) { | |
| 42 sky.Paint paint = new sky.Paint()..color = color; | |
| 43 paint.style = 0; // SkPaint::FILL_STYLE; | |
|
eseidel
2015/06/04 23:50:54
Do we not have an enum?
jackson
2015/06/05 00:23:10
I am going to fix this in the next CL
| |
| 44 canvas.drawCircle(outerRadius, outerRadius, innerRadius, paint); | |
| 45 } | |
| 46 ); | |
| 47 } | |
| 48 | |
| 49 return new EventListenerNode( | 49 return new EventListenerNode( |
| 50 new StyleNode( | 50 new Container( |
| 51 new InkWell( | 51 margin: const EdgeDims.symmetric(horizontal: 5.0), |
| 52 children: value == groupValue ? [new Container(style: _dotStyle)] : [] | 52 child: new CustomPaint( |
| 53 ), | 53 callback: (RenderObjectDisplayList canvas) { |
| 54 highlight ? _highlightStyle : _style | 54 sky.Paint paint = new sky.Paint()..color = color; |
| 55 paint.style = 1; // SkPaint::STROKE_STYLE; | |
| 56 paint.strokeWidth = 2.0; | |
| 57 canvas.drawCircle(outerRadius, outerRadius, outerRadius, paint); | |
| 58 }, | |
| 59 child: new Container( | |
| 60 desiredSize: new sky.Size(outerWidth, outerWidth), | |
| 61 child: new InkWell( | |
| 62 children: value == groupValue ? [buildDot()] : [] | |
| 63 ) | |
| 64 ) | |
| 65 ) | |
| 55 ), | 66 ), |
| 56 onGestureTap: _handleClick | 67 onGestureTap: _handleClick |
| 57 ); | 68 ); |
| 58 } | 69 } |
| 59 | 70 |
| 60 void _handleClick(_) { | 71 void _handleClick(_) { |
| 61 onChanged(value); | 72 onChanged(value); |
| 62 } | 73 } |
| 63 } | 74 } |
| OLD | NEW |