Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: sky/sdk/lib/framework/components2/radio.dart

Issue 1157573012: Implement radio button for Sky’s fn2 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Fix syntax error Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/examples/stocks2/lib/stock_app.dart ('k') | sky/sdk/lib/framework/fn2.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/theme2/colors.dart' as colors;
6
7 import 'dart:sky' as sky;
5 import '../fn2.dart'; 8 import '../fn2.dart';
9 import '../rendering/box.dart';
10 import '../rendering/object.dart';
6 import 'button_base.dart'; 11 import 'button_base.dart';
7 import 'ink_well.dart'; 12 import 'ink_well.dart';
8 13
9 typedef void ValueChanged(value); 14 typedef void ValueChanged(value);
10 15
11 class Radio extends ButtonBase { 16 class Radio extends ButtonBase {
12 Object value; 17 Object value;
13 Object groupValue; 18 Object groupValue;
14 ValueChanged onChanged; 19 ValueChanged onChanged;
15 20
16 static final Style _style = new Style('''
17 width: 14px;
18 height: 14px;
19 border-radius: 7px;
20 border: 1px solid blue;
21 margin: 0 5px;'''
22 );
23
24 static final Style _highlightStyle = new Style('''
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
41 Radio({ 21 Radio({
42 Object key, 22 Object key,
43 this.onChanged, 23 this.onChanged,
44 this.value, 24 this.value,
45 this.groupValue 25 this.groupValue
46 }) : super(key: key); 26 }) : super(key: key);
47 27
48 UINode buildContent() { 28 UINode buildContent() {
29 // TODO(jackson): This should change colors with the theme
30 sky.Color color = highlight ? colors.Purple[500] : const sky.Color(0x8A00000 0);
31 const double diameter = 16.0;
32 const double outerRadius = diameter / 2;
33 const double innerRadius = 5.0;
49 return new EventListenerNode( 34 return new EventListenerNode(
50 new StyleNode( 35 new Container(
51 new InkWell( 36 margin: const EdgeDims.symmetric(horizontal: 5.0),
52 children: value == groupValue ? [new Container(style: _dotStyle)] : [] 37 desiredSize: new sky.Size(diameter, diameter),
53 ), 38 child: new CustomPaint(
54 highlight ? _highlightStyle : _style 39 callback: (RenderObjectDisplayList canvas) {
40
41 sky.Paint paint = new sky.Paint()..color = color;
42
43 // Draw the outer circle
44 paint.style = 1; // SkPaint::STROKE_STYLE;
45 paint.strokeWidth = 2.0;
46 canvas.drawCircle(outerRadius, outerRadius, outerRadius, paint);
47
48 // Draw the inner circle
49 if (value == groupValue) {
50 paint.style = 0; // SkPaint::FILL_STYLE;
51 canvas.drawCircle(outerRadius, outerRadius, innerRadius, paint);
52 }
53 }
54 )
55 ), 55 ),
56 onGestureTap: _handleClick 56 onGestureTap: _handleClick
57 ); 57 );
58 } 58 }
59 59
60 void _handleClick(_) { 60 void _handleClick(_) {
61 onChanged(value); 61 onChanged(value);
62 } 62 }
63 } 63 }
OLDNEW
« no previous file with comments | « sky/examples/stocks2/lib/stock_app.dart ('k') | sky/sdk/lib/framework/fn2.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698