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

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

Issue 1177243002: Refactor fn2.dart, since it breached our 1000-line threshold. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: 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
OLDNEW
(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 'dart:sky' as sky;
8 import '../fn2.dart';
9 import '../rendering/box.dart';
10 import '../rendering/object.dart';
11 import 'button_base.dart';
12
13 typedef void ValueChanged(value);
14
15 class Checkbox extends ButtonBase {
16
17 Checkbox({ Object key, this.onChanged, this.checked }) : super(key: key);
18
19 bool checked;
20 ValueChanged onChanged;
21
22 void syncFields(Checkbox source) {
23 checked = source.checked;
24 onChanged = source.onChanged;
25 super.syncFields(source);
26 }
27
28 void _handleClick(sky.Event e) {
29 onChanged(!checked);
30 }
31
32 UINode buildContent() {
33 // TODO(jackson): This should change colors with the theme
34 sky.Color color = highlight ? colors.Purple[500] : const sky.Color(0x8A00000 0);
35 const double kEdgeSize = 20.0;
36 const double kEdgeRadius = 1.0;
37 return new EventListenerNode(
38 new Container(
39 margin: const EdgeDims.symmetric(horizontal: 5.0),
40 width: kEdgeSize + 2.0,
41 height: kEdgeSize + 2.0,
42 child: new CustomPaint(
43 callback: (sky.Canvas canvas, Size size) {
44
45 sky.Paint paint = new sky.Paint()..color = color
46 ..strokeWidth = 2.0;
47
48 // Draw the outer rrect
49 paint.setStyle(checked ? sky.PaintingStyle.strokeAndFill : sky.Paint ingStyle.stroke);
50 sky.Rect rect = new sky.Rect.fromLTRB(0.0, 0.0, kEdgeSize, kEdgeSize );
51 sky.RRect rrect = new sky.RRect()..setRectXY(rect, kEdgeRadius, kEdg eRadius);
52 canvas.drawRRect(rrect, paint);
53
54 // Draw the inner check
55 if (checked) {
56 // TODO(jackson): Use the theme color
57 paint.color = const sky.Color(0xFFFFFFFF);
58 paint.setStyle(sky.PaintingStyle.stroke);
59 sky.Path path = new sky.Path();
60 path.moveTo(kEdgeSize * 0.2, kEdgeSize * 0.5);
61 path.lineTo(kEdgeSize * 0.4, kEdgeSize * 0.7);
62 path.lineTo(kEdgeSize * 0.8, kEdgeSize * 0.3);
63 canvas.drawPath(path, paint);
64 }
65 }
66 )
67 ),
68 onGestureTap: _handleClick
69 );
70 }
71
72 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/framework/components2/button_base.dart ('k') | sky/sdk/lib/framework/components2/drawer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698