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

Side by Side Diff: sky/sdk/lib/editing/input.dart

Issue 1194113002: EditableText underlines the word being edited (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
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 '../painting/text_style.dart';
6 import '../theme/colors.dart';
7 import '../theme/typography.dart' as typography;
5 import '../widgets/basic.dart'; 8 import '../widgets/basic.dart';
6 import 'editable_string.dart'; 9 import 'editable_string.dart';
7 import 'editable_text.dart'; 10 import 'editable_text.dart';
8 import 'keyboard.dart'; 11 import 'keyboard.dart';
9 12
10 typedef void ValueChanged(value); 13 typedef void ValueChanged(value);
11 14
12 class Input extends Component { 15 class Input extends Component {
13 16
14 Input({String key, 17 Input({String key,
15 this.placeholder, 18 this.placeholder,
16 this.onChanged, 19 this.onChanged,
17 this.focused}) 20 this.focused})
18 : super(key: key, stateful: true) { 21 : super(key: key, stateful: true) {
19 _editableValue = new EditableString( 22 _editableValue = new EditableString(
20 text: _value, 23 text: _value,
21 onUpdated: _handleTextUpdated 24 onUpdated: _handleTextUpdated
22 ); 25 );
23 } 26 }
24 27
25 // static final Style _style = new Style(''' 28 static final TextStyle _placeholderStyle = typography.black.caption;
26 // transform: translateX(0);
27 // margin: 8px;
28 // padding: 8px;
29 // border-bottom: 1px solid ${Grey[200]};
30 // align-self: center;
31 // height: 1.2em;
32 // white-space: pre;
Hixie 2015/06/19 22:39:44 did white-space:pre get carried over?
hansmuller 2015/06/19 23:32:12 Good point. The height and white-space haven't bee
33 // overflow: hidden;'''
34 // );
35
36 // static final Style _placeholderStyle = new Style('''
37 // top: 8px;
38 // left: 8px;
39 // position: absolute;
40 // ${typography.black.caption};'''
41 // );
42
43 // static final String _focusedInlineStyle = '''
44 // padding: 7px;
45 // border-bottom: 2px solid ${Blue[500]};''';
46 29
47 String placeholder; 30 String placeholder;
48 ValueChanged onChanged; 31 ValueChanged onChanged;
49 bool focused = false; 32 bool focused = false;
50 33
51 void syncFields(Input source) { 34 void syncFields(Input source) {
52 placeholder = source.placeholder; 35 placeholder = source.placeholder;
53 onChanged = source.onChanged; 36 onChanged = source.onChanged;
54 focused = source.focused; 37 focused = source.focused;
55 } 38 }
(...skipping 10 matching lines...) Expand all
66 onChanged(_value); 49 onChanged(_value);
67 } 50 }
68 } 51 }
69 52
70 Widget build() { 53 Widget build() {
71 if (focused && !_isAttachedToKeyboard) { 54 if (focused && !_isAttachedToKeyboard) {
72 keyboard.show(_editableValue.stub); 55 keyboard.show(_editableValue.stub);
73 _isAttachedToKeyboard = true; 56 _isAttachedToKeyboard = true;
74 } 57 }
75 58
76 List<Widget> children = []; 59 List<Widget> textChildren = [];
Hixie 2015/06/19 22:39:44 <Widget>[].
hansmuller 2015/06/19 23:32:12 Done.
77
78 if (placeholder != null && _value.isEmpty) { 60 if (placeholder != null && _value.isEmpty) {
79 children.add(new Container( 61 textChildren.add(new Container(
Hixie 2015/06/19 22:39:44 What is the Container() for?
hansmuller 2015/06/19 23:32:12 Oops, thanks for pointing that out.
80 // style: _placeholderStyle, 62 child: new Text(placeholder, style: _placeholderStyle)
81 child: new Text(placeholder)
82 )); 63 ));
83 } 64 }
65 textChildren.add(
66 new EditableText(value: _editableValue, focused: focused));
Hixie 2015/06/19 22:39:44 If you put a line break after a (, but a line brea
hansmuller 2015/06/19 23:32:12 Done.
84 67
85 children.add(new EditableText(value: _editableValue, focused: focused)); 68 Container text = new Container(
69 padding: const EdgeDims.only(left: 8.0, right: 8.0, top: 2.0),
70 child: new Stack(textChildren),
71 constraints: new BoxConstraints(minWidth: double.INFINITY)
abarth-chromium 2015/06/19 22:41:38 You might as well just write: width: double.INFIN
hansmuller 2015/06/19 23:32:12 Acknowledged.
72 );
73
74 Color focusColor = focused ? Blue[400] : Grey[200];
75 Container focusHighlight = new Container(
76 margin: const EdgeDims.only(top: 8.0),
77 constraints: new BoxConstraints.tightFor(height: focused ? 2.0 : 1.0),
78 decoration: new BoxDecoration(backgroundColor: focusColor)
abarth-chromium 2015/06/19 22:41:38 Why not use a bottom border to draw this line? Th
hansmuller 2015/06/19 23:32:12 Done.
79 );
80
81 Flex input = new Flex([text, focusHighlight],
82 direction: FlexDirection.vertical,
83 justifyContent: FlexJustifyContent.center
84 );
86 85
87 return new Listener( 86 return new Listener(
88 // style: _style, 87 child: input,
89 // inlineStyle: focused ? _focusedInlineStyle : null,
90 child: new Stack(children),
91 onPointerDown: (_) => keyboard.showByRequest() 88 onPointerDown: (_) => keyboard.showByRequest()
92 ); 89 );
93 } 90 }
94 91
95 void didUnmount() { 92 void didUnmount() {
96 if (_isAttachedToKeyboard) 93 if (_isAttachedToKeyboard)
97 keyboard.hide(); 94 keyboard.hide();
98 super.didUnmount(); 95 super.didUnmount();
99 } 96 }
100
101 } 97 }
OLDNEW
« sky/sdk/lib/editing/editable_text.dart ('K') | « sky/sdk/lib/editing/editable_text.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698