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

Side by Side Diff: sky/examples/widgets/styled_text.dart

Issue 1218593002: Move sky/examples to sky/sdk/lib/example, and code changes to support that change. Fixes T277. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 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/painting/text_style.dart';
6 import 'package:sky/rendering/box.dart';
7 import 'package:sky/rendering/flex.dart';
8 import 'package:sky/rendering/sky_binding.dart';
9 import 'package:sky/theme/colors.dart';
10 import 'package:sky/theme/theme_data.dart';
11 import 'package:sky/widgets/basic.dart';
12 import 'package:sky/widgets/material.dart';
13 import 'package:sky/widgets/scaffold.dart';
14 import 'package:sky/widgets/theme.dart';
15 import 'package:sky/widgets/tool_bar.dart';
16 import 'package:sky/widgets/widget.dart';
17
18
19 class StyledTextApp extends App {
20
21 StyledTextApp() {
22 toText = toStyledText;
23 nameLines = dialogText
24 .split('\n')
25 .map((String line) => line.split(':'))
26 .toList();
27 }
28
29 Function toText;
30
31 // From https://en.wikiquote.org/wiki/2001:_A_Space_Odyssey_(film)
32 final String dialogText = '''
33 Dave: Open the pod bay doors, please, HAL. Open the pod bay doors, please, HAL. Hello, HAL. Do you read me? Hello, HAL. Do you read me? Do you read me, HAL?
34 HAL: Affirmative, Dave. I read you.
35 Dave: Open the pod bay doors, HAL.
36 HAL: I'm sorry, Dave. I'm afraid I can't do that.
37 Dave: What's the problem?
38 HAL: I think you know what the problem is just as well as I do.
39 Dave: What are you talking about, HAL?
40 HAL: This mission is too important for me to allow you to jeopardize it.''';
41
42 // [["Dave", "Open the pod bay..."] ...]
43 List<List<String>> nameLines;
44
45 final TextStyle daveStyle = new TextStyle(color: Indigo[400], height: 1.8);
46 final TextStyle halStyle = new TextStyle(color: Red[400], fontFamily: "monospa ce");
47 final TextStyle boldStyle = const TextStyle(fontWeight: bold);
48 final TextStyle underlineStyle = const TextStyle(
49 decoration: underline,
50 decorationColor: const Color(0xFF000000),
51 decorationStyle: TextDecorationStyle.wavy
52 );
53
54 Component toStyledText(String name, String text) {
55 TextStyle lineStyle = (name == "Dave") ? daveStyle : halStyle;
56 return new StyledText(
57 key: text,
58 elements: [lineStyle, [boldStyle, [underlineStyle, name], ":"], text]
59 );
60 }
61
62 Component toPlainText(String name, String text) => new Text(name + ":" + text) ;
63
64 Component createSeparator() {
65 return new Container(
66 constraints: const BoxConstraints.expandWidth(maxHeight: 0.0),
67 margin: const EdgeDims.symmetric(vertical: 10.0, horizontal: 64.0),
68 decoration: const BoxDecoration(
69 border: const Border(
70 bottom: const BorderSide(color: const Color.fromARGB(24, 0, 0, 0))
71 )
72 )
73 );
74 }
75
76 void toggleToTextFunction(_) {
77 setState(() {
78 toText = (toText == toPlainText) ? toStyledText : toPlainText;
79 });
80 }
81
82 Widget build() {
83 List<Component> lines = nameLines
84 .map((nameAndText) => Function.apply(toText, nameAndText))
85 .toList();
86
87 List<Component> children = [];
88 for (Component line in lines) {
89 children.add(line);
90 if (line != lines.last) {
91 children.add(createSeparator());
92 }
93 }
94
95 Container body = new Container(
96 padding: new EdgeDims.symmetric(horizontal: 8.0),
97 child: new Flex(children,
98 direction: FlexDirection.vertical,
99 justifyContent: FlexJustifyContent.center,
100 alignItems: FlexAlignItems.flexStart
101 )
102 );
103
104 Listener interactiveBody = new Listener(
105 child: body,
106 onPointerDown: toggleToTextFunction
107 );
108
109 return new Theme(
110 data: new ThemeData.light(primary: Blue, darkToolbar: true),
111 child: new Scaffold(
112 body: new Material(child: interactiveBody),
113 toolbar: new ToolBar(
114 center: new Text('Hal and Dave')
115 )
116 )
117 );
118 }
119 }
120
121 void main() {
122 runApp(new StyledTextApp());
123 SkyBinding.instance.onFrame = () {
124 // uncomment this for debugging:
125 // SkyBinding.instance.debugDumpRenderTree();
126 };
127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698