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

Side by Side Diff: sky/sdk/lib/widgets/README.md

Issue 1188163004: Improve widgets/README.md based on Hixie's feeback (Closed) Base URL: git@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
« no previous file with comments | « no previous file | 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 Sky Widgets 1 Sky Widgets
2 =========== 2 ===========
3 3
4 Sky widgets are built using a functional-reactive framework, which takes 4 Sky widgets are built using a functional-reactive framework, which takes
5 inspiration from [React](http://facebook.github.io/react/). The central idea is 5 inspiration from [React](http://facebook.github.io/react/). The central idea is
6 that you build your UI out of components. Components describe what their view 6 that you build your UI out of components. Components describe what their view
7 should look like given their current configuration and state. When a component's 7 should look like given their current configuration and state. When a component's
8 state changes, the component rebuilds its description, which the framework diffs 8 state changes, the component rebuilds its description, which the framework diffs
9 against the previous description in order to determine the minial changes needed 9 against the previous description in order to determine the minial changes needed
10 in the underlying render tree to transition from one state to the next. 10 in the underlying render tree to transition from one state to the next.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 refer to the same URL, they'll share the underlying image resource. 62 refer to the same URL, they'll share the underlying image resource.
63 63
64 Below is a simple toolbar example that shows how to combine these widgets: 64 Below is a simple toolbar example that shows how to combine these widgets:
65 65
66 ```dart 66 ```dart
67 import 'package:sky/widgets/basic.dart'; 67 import 'package:sky/widgets/basic.dart';
68 68
69 class MyToolBar extends Component { 69 class MyToolBar extends Component {
70 Widget build() { 70 Widget build() {
71 return new Container( 71 return new Container(
72 height: 56.0,
73 padding: new EdgeDims.symmetric(horizontal: 8.0),
74 decoration: const BoxDecoration(
Hixie 2015/06/17 17:13:16 decoration should go first, since you say "cyan" b
abarth-chromium 2015/06/17 17:39:29 Done.
75 backgroundColor: const Color(0xFF00FFFF),
76 ),
72 child: new Flex([ 77 child: new Flex([
73 new Image(src: 'menu.png', size: const Size(25.0, 25.0)), 78 new Image(src: 'menu.png', size: const Size(25.0, 25.0)),
74 new Flexible(child: new Text('My awesome toolbar')), 79 new Flexible(child: new Text('My awesome toolbar')),
75 new Image(src: 'search.png', size: const Size(25.0, 25.0)), 80 new Image(src: 'search.png', size: const Size(25.0, 25.0)),
76 ]), 81 ])
77 height: 56.0,
78 padding: new EdgeDims.symmetric(horizontal: 8.0),
79 decoration: const BoxDecoration(
80 backgroundColor: const Color(0xFF00FFFF),
81 )
82 ); 82 );
83 } 83 }
84 } 84 }
85 ``` 85 ```
86 86
87 The `MyToolBar` component creates a cyan `Container` with a height of 56 87 The `MyToolBar` component creates a cyan `Container` with a height of 56
88 device-independent pixels with an internal padding of 8 pixels, both on the 88 device-independent pixels with an internal padding of 8 pixels, both on the
89 left and the right. Inside the container, `MyToolBar` uses a `Flex` layout 89 left and the right. Inside the container, `MyToolBar` uses a `Flex` layout
90 in the (default) horizontal direction. The middle child, the `Text` widget, is 90 in the (default) horizontal direction. The middle child, the `Text` widget, is
91 marked as `Flexible`, which means it expands to fill any remaining available 91 marked as `Flexible`, which means it expands to fill any remaining available
(...skipping 14 matching lines...) Expand all
106 return new Center(child: new MyToolBar()); 106 return new Center(child: new MyToolBar());
107 } 107 }
108 } 108 }
109 109
110 void main() { 110 void main() {
111 new DemoApp(); 111 new DemoApp();
112 } 112 }
113 ``` 113 ```
114 114
115 Here, we've used the `Center` widget to center the toolbar within the view, both 115 Here, we've used the `Center` widget to center the toolbar within the view, both
116 vertically and horizontally. Because the toolbar uses a flexible layout 116 vertically and horizontally. If we didn't center the toolbar, it would fill the
117 internally, it expands to fill all the available horizontal space. 117 view, both vertically and horizontally, because the root widget is sized to fill
118 the view.
118 119
119 Listening to Events 120 Listening to Events
120 ------------------- 121 -------------------
121 122
122 In addition to being stunningly beautiful, most applications react to user 123 In addition to being stunningly beautiful, most applications react to user
123 input. The first step in building an interactive application is to listen for 124 input. The first step in building an interactive application is to listen for
124 input events. Let's see how that works by creating a simple button: 125 input events. Let's see how that works by creating a simple button:
125 126
126 ```dart 127 ```dart
127 import 'package:sky/widgets/basic.dart'; 128 import 'package:sky/widgets/basic.dart';
128 129
129 final BoxDecoration _decoration = new BoxDecoration( 130 final BoxDecoration _decoration = new BoxDecoration(
130 borderRadius: 5.0, 131 borderRadius: 5.0,
131 gradient: new LinearGradient( 132 gradient: new LinearGradient(
132 endPoints: [ Point.origin, new Point(0.0, 36.0) ], 133 endPoints: [ Point.origin, new Point(0.0, 36.0) ],
133 colors: [ const Color(0xFFEEEEEE), const Color(0xFFCCCCCC) ] 134 colors: [ const Color(0xFFEEEEEE), const Color(0xFFCCCCCC) ]
134 ) 135 )
135 ); 136 );
136 137
137 class MyButton extends Component { 138 class MyButton extends Component {
138 Widget build() { 139 Widget build() {
139 return new Listener( 140 return new Listener(
141 onGestureTap: (event) {
142 print('MyButton was tapped!');
143 },
140 child: new Container( 144 child: new Container(
141 child: new Center(
142 child: new Text('Engage')
143 ),
144 height: 36.0, 145 height: 36.0,
145 padding: new EdgeDims.all(8.0), 146 padding: new EdgeDims.all(8.0),
146 margin: new EdgeDims.symmetric(horizontal: 8.0), 147 margin: new EdgeDims.symmetric(horizontal: 8.0),
147 decoration: _decoration 148 decoration: _decoration,
148 ), 149 child: new Center(
149 onGestureTap: (event) { 150 child: new Text('Engage')
150 print('MyButton was tapped!'); 151 )
151 } 152 )
152 ); 153 );
153 } 154 }
154 } 155 }
155 ``` 156 ```
156 157
157 The `Listener` widget doesn't have an visual representation but instead listens 158 The `Listener` widget doesn't have an visual representation but instead listens
158 for events bubbling through the application. When a tap gesture bubbles out from 159 for events bubbling through the application. When a tap gesture bubbles out from
159 the `Container`, the `Listener` will call its `onGestureTap` callback, in this 160 the `Container`, the `Listener` will call its `onGestureTap` callback, in this
160 case printing a message to the console. 161 case printing a message to the console.
161 162
(...skipping 11 matching lines...) Expand all
173 174
174 ```dart 175 ```dart
175 class MyButton extends Component { 176 class MyButton extends Component {
176 MyButton({ this.child, this.onPressed }); 177 MyButton({ this.child, this.onPressed });
177 178
178 final Widget child; 179 final Widget child;
179 final Function onPressed; 180 final Function onPressed;
180 181
181 Widget build() { 182 Widget build() {
182 return new Listener( 183 return new Listener(
184 onGestureTap: (_) {
185 if (onPressed != null)
186 onPressed();
187 },
183 child: new Container( 188 child: new Container(
184 child: new Center(child: child),
185 height: 36.0, 189 height: 36.0,
186 padding: new EdgeDims.all(8.0), 190 padding: new EdgeDims.all(8.0),
187 margin: new EdgeDims.symmetric(horizontal: 8.0), 191 margin: new EdgeDims.symmetric(horizontal: 8.0),
188 decoration: _decoration 192 decoration: _decoration,
189 ), 193 child: new Center(child: child)
190 onGestureTap: (_) { 194 )
191 if (onPressed != null)
192 onPressed();
193 }
194 ); 195 );
195 } 196 }
196 } 197 }
197 ``` 198 ```
198 199
199 Rather than providing the button's label as a `String`, we've let the code that 200 Rather than providing the button's label as a `String`, we've let the code that
200 uses `MyButton` provide an arbitrary `Widget` to put inside the button. For 201 uses `MyButton` provide an arbitrary `Widget` to put inside the button. For
201 example, we can put an elaborate layout involving text and an image inside the 202 example, we can put an elaborate layout involving text and an image inside the
202 button: 203 button:
203 204
204 ```dart 205 ```dart
205 Widget build() { 206 Widget build() {
206 return new MyButton( 207 return new MyButton(
207 child: new ShrinkWrapWidth( 208 child: new ShrinkWrapWidth(
208 child: new Flex([ 209 child: new Flex([
209 new Image(src: 'thumbs-up.png', size: const Size(25.0, 25.0)), 210 new Image(src: 'thumbs-up.png', size: const Size(25.0, 25.0)),
210 new Container( 211 new Container(
212 padding: new EdgeDims.only(left: 10.0)
211 child: new Text('Thumbs up'), 213 child: new Text('Thumbs up'),
212 padding: new EdgeDims.only(left: 10.0)
213 ) 214 )
214 ]) 215 ])
215 ) 216 )
216 ); 217 );
217 } 218 }
218 ``` 219 ```
219 220
220 State 221 State
221 ----- 222 -----
222 223
223 TODO(abarth) 224 TODO(abarth)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698