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

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: do not constrain the input components width 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/sdk/lib/editing/editable_text.dart ('k') | no next file » | 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 '../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;
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 = <Widget>[];
60 if (placeholder != null && _value.isEmpty) {
61 textChildren.add(new Text(placeholder, style: _placeholderStyle));
62 }
63 textChildren.add(
64 new EditableText(value: _editableValue, focused: focused)
65 );
77 66
78 if (placeholder != null && _value.isEmpty) { 67 Border focusHighlight = new Border(bottom: new BorderSide(
79 children.add(new Container( 68 color: focused ? Blue[400] : Grey[200],
80 // style: _placeholderStyle, 69 width: focused ? 2.0 : 1.0
81 child: new Text(placeholder) 70 ));
82 ));
83 }
84 71
85 children.add(new EditableText(value: _editableValue, focused: focused)); 72 // TODO(hansmuller): white-space: pre, height: 1.2em.
73 Container input = new Container(
74 child: new Stack(textChildren),
75 padding: const EdgeDims.only(left: 8.0, right: 8.0, bottom: 12.0),
76 decoration: new BoxDecoration(border: focusHighlight)
77 );
86 78
87 return new Listener( 79 return new Listener(
88 // style: _style, 80 child: input,
89 // inlineStyle: focused ? _focusedInlineStyle : null,
90 child: new Stack(children),
91 onPointerDown: (_) => keyboard.showByRequest() 81 onPointerDown: (_) => keyboard.showByRequest()
92 ); 82 );
93 } 83 }
94 84
95 void didUnmount() { 85 void didUnmount() {
96 if (_isAttachedToKeyboard) 86 if (_isAttachedToKeyboard)
97 keyboard.hide(); 87 keyboard.hide();
98 super.didUnmount(); 88 super.didUnmount();
99 } 89 }
100
101 } 90 }
OLDNEW
« no previous file with comments | « 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