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

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

Issue 1211573003: Fill out some more documentation about building RenderBox subclasses. (Closed) Base URL: https://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
« no previous file with comments | « no previous file | sky/sdk/lib/rendering/block.dart » ('j') | sky/sdk/lib/rendering/block.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 Sky Rendering 1 Sky Rendering
2 ============= 2 =============
3 3
4 The Sky render tree is a low-level layout and painting system based on a 4 The Sky render tree is a low-level layout and painting system based on a
5 retained tree of objects that inherit from [`RenderObject`](object.dart). Most 5 retained tree of objects that inherit from [`RenderObject`](object.dart). Most
6 developers using Sky will not need to interact directly with the rendering tree. 6 developers using Sky will not need to interact directly with the rendering tree.
7 Instead, most developers should use [Sky widgets](../widgets/README.md), which 7 Instead, most developers should use [Sky widgets](../widgets/README.md), which
8 are built using the render tree. 8 are built using the render tree.
9 9
10 Overview 10 Overview
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 ### The RenderObject contract 114 ### The RenderObject contract
115 115
116 #### The ParentData contract 116 #### The ParentData contract
117 117
118 #### Using RenderObjectWithChildMixin 118 #### Using RenderObjectWithChildMixin
119 119
120 #### Using ContainerParentDataMixin and ContainerRenderObjectMixin 120 #### Using ContainerParentDataMixin and ContainerRenderObjectMixin
121 121
122 ### The RenderBox contract 122 ### The RenderBox contract
123 123
124 A RenderBox subclass is required to implement the following contract:
125
126 * If its constructor takes any nodes to be used as children, the
hansmuller 2015/06/24 19:53:30 I wasn't sure what "nodes" were here. It looks lik
Hixie 2015/06/25 19:15:31 done
127 constructor must call add() for each such child.
128
129 * If it has any data to store on its children, define a BoxParentData
hansmuller 2015/06/24 19:53:30 "it" is the the RenderBox subclass The setParentD
Hixie 2015/06/25 19:15:30 Fixed the sample code, clarified the text.
130 subclass and override setParentData() to initialise the child's
131 parent data appropriately, as in:
132
133 ```dart
134 class FooParentData extends BoxParentData { ... }
135
136 // In RenderFoo
137 void setParentData(RenderBox child) {
hansmuller 2015/06/24 19:53:30 I found this method name confusing; I'd expected t
Hixie 2015/06/25 19:15:31 Added a paragraph about this. In general parentDat
138 if (child.parentData is! FooParentData)
139 child.parentData = new FooParentData();
140 }
141 ```
142
143 * The class must encapsulate a layout algorithm that has the following
144 features:
145
146 ** It uses as input a set of constraints, described by a
147 BoxConstraints object, and a set of zero or more children, as
148 determined by the class itself, and has as output a Size, and
149 positions for each child.
hansmuller 2015/06/24 19:53:31 It also causes each child's size to be set?
Hixie 2015/06/25 19:15:31 elaborated.
150
151 ** The algorithm can decide the Size in one of two ways: either
hansmuller 2015/06/24 19:53:30 It would be nice to explain why RenderBoxes make t
Hixie 2015/06/25 19:15:31 done.
152 exclusively based on the given constraints (i.e. it is effectively
153 sized entirely by its parent), or based on those constraints and
154 the dimensions of the children.
155
156 In the former case, the class must have a sizedByParent getter that
157 returns true, and it must have a `performResize()` method that uses
hansmuller 2015/06/24 19:53:30 I'm not entirely clear on what a performResize() o
Hixie 2015/06/25 19:15:31 I don't understand. Doesn't this paragraph exactly
158 the object's `constraints` member to size itself by setting the
159 `size` member. The size must be consistent, a given set of
160 constraints must always result in the same size.
161
162 In the latter case, it will inherit the default `sizedByParent`
163 getter that returns false, and it will size itself in the
164 `performLayout()` function described below.
165
166 * The following methods must report numbers consistent with the output
167 of the layout algorithm used:
168
169 ** `double getMinIntrinsicWidth(BoxConstraints constraints)` must
170 return the width that fits within the given constraints below which
hansmuller 2015/06/24 19:53:30 This is somewhat hard to parse. Maybe you could su
Hixie 2015/06/25 19:15:31 Added example. "constrained width" doesn't say con
171 making the width constraint smaller would not increase the
172 resulting height, or, to put it another way, the narrowest width at
173 which the box can be rendered without failing to lay the children
174 out within itself.
175
176 ** `double getMaxIntrinsicWidth(BoxConstraints constraints)` must
177 return the width that fits within the given constraints above which
178 making the width constraint larger would not decrease the resulting
179 height.
180
181 ** `double getMinIntrinsicHeight(BoxConstraints constraints)` must
182 return the height that fits within the given constraints below
183 which making the height constraint smaller would not increase the
184 resulting width, or, to put it another way, the shortest height at
185 which the box can be rendered without failing to lay the children
186 out within itself.
hansmuller 2015/06/24 19:53:31 This constraint might also be explained with a tex
Hixie 2015/06/25 19:15:31 Added example.
187
188 ** `double getMaxIntrinsicHeight(BoxConstraints constraints)` must
189 return the height that fits within the given constraints above
190 which making the height constraint larger would not decrease the
191 resulting width. If the height depends exclusively on the width,
192 and the width does not depend on the height, then
193 `getMinIntrinsicHeight()` and `getMaxIntrinsicHeight()` will return the
194 same number given the same constraints.
195
196 * The box must have a `performLayout()` method that walks over the
hansmuller 2015/06/24 19:53:30 A slightly simplified version of RenderBlock's per
Hixie 2015/06/25 19:15:31 I've added a TODO to document how to walk over a C
197 object's children, if any, and for each one calls `child.layout()`
hansmuller 2015/06/24 19:53:30 It would be helpful to note here that child.layout
Hixie 2015/06/25 19:15:31 I've clarified that layout() sometimes results in
198 with a BoxConstraints object as the first argument, and optionally a
199 second argument named `parentUsesSize` which is set to true if the
200 child's resulting size will in any way influence the layout, and
201 must be false if the child's resulting size is ignored. The
202 children's positions (`child.parentData.position`) must also be set.
203
204 If `sizedByParent` is false, then `performLayout()` must also size
205 the object (by setting `size`), otherwise, the size must be left
hansmuller 2015/06/24 19:53:30 ...must also size the child? If sizedByParent is
Hixie 2015/06/25 19:15:31 This is about the parent's size, not the child's s
206 untouched.
207
208 * The `size` member must never be set to an infinite value.
hansmuller 2015/06/24 19:53:30 At some point I think we're going to need to expla
Hixie 2015/06/25 19:15:31 Added.
209
210 * The box must also implement `hitTestChildren()`.
211 TODO(ianh): Define this better
212
213 * The box must also implement `paint()`.
214 TODO(ianh): Define this better
215
124 #### Using RenderProxyBox 216 #### Using RenderProxyBox
125 217
126 ### The Hit Testing contract 218 ### The Hit Testing contract
127 219
128 220
129 Performance rules of thumb 221 Performance rules of thumb
130 -------------------------- 222 --------------------------
131 223
132 * Avoid using transforms where mere maths would be sufficient (e.g. 224 * Avoid using transforms where mere maths would be sufficient (e.g.
133 draw your rectangle at x,y rather than translating by x,y and 225 draw your rectangle at x,y rather than translating by x,y and
134 drawing it at 0,0). 226 drawing it at 0,0).
135 227
136 * Avoid using save/restore on canvases. 228 * Avoid using save/restore on canvases.
137 229
138 230
139 Dependencies 231 Dependencies
140 ------------ 232 ------------
141 233
142 * [`package:sky/base`](../base) 234 * [`package:sky/base`](../base)
143 * [`package:sky/mojo`](../mojo) 235 * [`package:sky/mojo`](../mojo)
144 * [`package:sky/animation`](../mojo) 236 * [`package:sky/animation`](../mojo)
OLDNEW
« no previous file with comments | « no previous file | sky/sdk/lib/rendering/block.dart » ('j') | sky/sdk/lib/rendering/block.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698