OLD | NEW |
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 'dart:math' as math; | 5 import 'dart:math' as math; |
6 import 'dart:sky' as sky; | 6 import 'dart:sky' as sky; |
7 import 'package:sky/framework/layout2.dart'; | 7 import 'package:sky/framework/layout2.dart'; |
8 | 8 |
9 const double kTwoPi = 2 * math.PI; | 9 const double kTwoPi = 2 * math.PI; |
10 | 10 |
11 double deg(double radians) => radians * 180.0 / math.PI; | 11 double deg(double radians) => radians * 180.0 / math.PI; |
12 | 12 |
13 class SectorConstraints { | 13 class SectorConstraints { |
14 const SectorConstraints({ | 14 const SectorConstraints({ |
15 this.minDeltaRadius: 0.0, | 15 this.minDeltaRadius: 0.0, |
16 this.maxDeltaRadius: double.INFINITY, | 16 this.maxDeltaRadius: double.INFINITY, |
17 this.minDeltaTheta: 0.0, | 17 this.minDeltaTheta: 0.0, |
18 this.maxDeltaTheta: kTwoPi}); | 18 this.maxDeltaTheta: kTwoPi |
| 19 }); |
19 | 20 |
20 const SectorConstraints.tight({ double deltaRadius: 0.0, double deltaTheta: 0.
0 }) | 21 const SectorConstraints.tight({ double deltaRadius: 0.0, double deltaTheta: 0.
0 }) |
21 : minDeltaRadius = deltaRadius, | 22 : minDeltaRadius = deltaRadius, |
22 maxDeltaRadius = deltaRadius, | 23 maxDeltaRadius = deltaRadius, |
23 minDeltaTheta = deltaTheta, | 24 minDeltaTheta = deltaTheta, |
24 maxDeltaTheta = deltaTheta; | 25 maxDeltaTheta = deltaTheta; |
25 | 26 |
26 final double minDeltaRadius; | 27 final double minDeltaRadius; |
27 final double maxDeltaRadius; | 28 final double maxDeltaRadius; |
28 final double minDeltaTheta; | 29 final double minDeltaTheta; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 64 |
64 void setParentData(RenderNode child) { | 65 void setParentData(RenderNode child) { |
65 if (child.parentData is! SectorParentData) | 66 if (child.parentData is! SectorParentData) |
66 child.parentData = new SectorParentData(); | 67 child.parentData = new SectorParentData(); |
67 } | 68 } |
68 | 69 |
69 SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double
radius) { | 70 SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double
radius) { |
70 return new SectorDimensions.withConstraints(constraints); | 71 return new SectorDimensions.withConstraints(constraints); |
71 } | 72 } |
72 | 73 |
73 void layout(SectorConstraints constraints, double radius, { RenderNode relayou
tSubtreeRoot }) { | 74 void layout(SectorConstraints constraints, { RenderNode relayoutSubtreeRoot })
{ |
74 deltaRadius = constraints.constrainDeltaRadius(0.0); | 75 deltaRadius = constraints.constrainDeltaRadius(0.0); |
75 deltaTheta = constraints.constrainDeltaTheta(0.0); | 76 deltaTheta = constraints.constrainDeltaTheta(0.0); |
76 layoutDone(); | 77 layoutDone(); |
77 } | 78 } |
78 | 79 |
79 double deltaRadius; | 80 double deltaRadius; |
80 double deltaTheta; | 81 double deltaTheta; |
81 } | 82 } |
82 | 83 |
83 class RenderDecoratedSector extends RenderSector { | 84 class RenderDecoratedSector extends RenderSector { |
(...skipping 13 matching lines...) Expand all Loading... |
97 assert(deltaRadius != null); | 98 assert(deltaRadius != null); |
98 assert(deltaTheta != null); | 99 assert(deltaTheta != null); |
99 assert(parentData is SectorParentData); | 100 assert(parentData is SectorParentData); |
100 | 101 |
101 if (_decoration == null) | 102 if (_decoration == null) |
102 return; | 103 return; |
103 | 104 |
104 if (_decoration.backgroundColor != null) { | 105 if (_decoration.backgroundColor != null) { |
105 sky.Paint paint = new sky.Paint()..color = _decoration.backgroundColor; | 106 sky.Paint paint = new sky.Paint()..color = _decoration.backgroundColor; |
106 sky.Path path = new sky.Path(); | 107 sky.Path path = new sky.Path(); |
107 double outerRadiusOver2 = (parentData.radius + deltaRadius) / 2.0; | 108 double outerRadius = (parentData.radius + deltaRadius); |
108 sky.Rect outerBounds = new sky.Rect()..setLTRB(-outerRadiusOver2, -outerRa
diusOver2, outerRadiusOver2, outerRadiusOver2); | 109 sky.Rect outerBounds = new sky.Rect()..setLTRB(-outerRadius, -outerRadius,
outerRadius, outerRadius); |
109 path.arcTo(outerBounds, deg(parentData.theta), deg(deltaTheta), true); | 110 path.arcTo(outerBounds, deg(parentData.theta), deg(deltaTheta), true); |
110 double innerRadiusOver2 = parentData.radius / 2.0; | 111 double innerRadius = parentData.radius; |
111 sky.Rect innerBounds = new sky.Rect()..setLTRB(-innerRadiusOver2, -innerRa
diusOver2, innerRadiusOver2, innerRadiusOver2); | 112 sky.Rect innerBounds = new sky.Rect()..setLTRB(-innerRadius, -innerRadius,
innerRadius, innerRadius); |
112 path.arcTo(innerBounds, deg(parentData.theta + deltaTheta), deg(-deltaThet
a), false); | 113 path.arcTo(innerBounds, deg(parentData.theta + deltaTheta), deg(-deltaThet
a), false); |
113 path.close(); | 114 path.close(); |
114 canvas.drawPath(path, paint); | 115 canvas.drawPath(path, paint); |
115 } | 116 } |
116 } | 117 } |
117 } | 118 } |
118 | 119 |
119 class SectorChildListParentData extends SectorParentData with ContainerParentDat
aMixin<RenderSector> { } | 120 class SectorChildListParentData extends SectorParentData with ContainerParentDat
aMixin<RenderSector> { } |
120 | 121 |
121 class RenderSectorRing extends RenderDecoratedSector with ContainerRenderNodeMix
in<RenderSector, SectorChildListParentData> { | 122 class RenderSectorRing extends RenderDecoratedSector with ContainerRenderNodeMix
in<RenderSector, SectorChildListParentData> { |
(...skipping 11 matching lines...) Expand all Loading... |
133 assert(value != null); | 134 assert(value != null); |
134 if (_desiredDeltaRadius != value) { | 135 if (_desiredDeltaRadius != value) { |
135 _desiredDeltaRadius = value; | 136 _desiredDeltaRadius = value; |
136 markNeedsLayout(); | 137 markNeedsLayout(); |
137 } | 138 } |
138 } | 139 } |
139 | 140 |
140 double _padding; | 141 double _padding; |
141 double get padding => _padding; | 142 double get padding => _padding; |
142 void set padding(double value) { | 143 void set padding(double value) { |
| 144 // TODO(ianh): avoid code duplication |
143 assert(value != null); | 145 assert(value != null); |
144 if (_padding != value) { | 146 if (_padding != value) { |
145 _padding = value; | 147 _padding = value; |
146 markNeedsLayout(); | 148 markNeedsLayout(); |
147 } | 149 } |
148 } | 150 } |
149 | 151 |
150 void setParentData(RenderNode child) { | 152 void setParentData(RenderNode child) { |
| 153 // TODO(ianh): avoid code duplication |
151 if (child.parentData is! SectorChildListParentData) | 154 if (child.parentData is! SectorChildListParentData) |
152 child.parentData = new SectorChildListParentData(); | 155 child.parentData = new SectorChildListParentData(); |
153 } | 156 } |
154 | 157 |
155 SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double
radius) { | 158 SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double
radius) { |
156 double outerDeltaRadius = constraints.constrainDeltaRadius(desiredDeltaRadiu
s); | 159 double outerDeltaRadius = constraints.constrainDeltaRadius(desiredDeltaRadiu
s); |
157 double innerDeltaRadius = outerDeltaRadius - padding * 2.0; | 160 double innerDeltaRadius = outerDeltaRadius - padding * 2.0; |
158 double childRadius = radius + padding; | 161 double childRadius = radius + padding; |
159 double paddingTheta = math.atan(padding / (radius + outerDeltaRadius)); | 162 double paddingTheta = math.atan(padding / (radius + outerDeltaRadius)); |
160 double innerTheta = paddingTheta; // increments with each child | 163 double innerTheta = paddingTheta; // increments with each child |
161 double remainingTheta = constraints.maxDeltaTheta - (innerTheta + paddingThe
ta); | 164 double remainingDeltaTheta = constraints.maxDeltaTheta - (innerTheta + paddi
ngTheta); |
162 RenderSector child = firstChild; | 165 RenderSector child = firstChild; |
163 while (child != null) { | 166 while (child != null) { |
164 SectorConstraints innerConstraints = new SectorConstraints( | 167 SectorConstraints innerConstraints = new SectorConstraints( |
165 maxDeltaRadius: innerDeltaRadius, | 168 maxDeltaRadius: innerDeltaRadius, |
166 maxDeltaTheta: remainingTheta | 169 maxDeltaTheta: remainingDeltaTheta |
167 ); | 170 ); |
168 SectorDimensions childDimensions = child.getIntrinsicDimensions(innerConst
raints, childRadius); | 171 SectorDimensions childDimensions = child.getIntrinsicDimensions(innerConst
raints, childRadius); |
169 innerTheta += childDimensions.deltaTheta; | 172 innerTheta += childDimensions.deltaTheta; |
170 remainingTheta -= childDimensions.deltaTheta; | 173 remainingDeltaTheta -= childDimensions.deltaTheta; |
171 assert(child.parentData is SectorChildListParentData); | 174 assert(child.parentData is SectorChildListParentData); |
172 child = child.parentData.nextSibling; | 175 child = child.parentData.nextSibling; |
173 if (child != null) { | 176 if (child != null) { |
174 innerTheta += paddingTheta; | 177 innerTheta += paddingTheta; |
175 remainingTheta -= paddingTheta; | 178 remainingDeltaTheta -= paddingTheta; |
176 } | 179 } |
177 } | 180 } |
178 return new SectorDimensions.withConstraints(constraints, | 181 return new SectorDimensions.withConstraints(constraints, |
179 deltaRadius: outerDeltaRadius, | 182 deltaRadius: outerDeltaRadius, |
180 deltaTheta: innerTheta); | 183 deltaTheta: innerTheta); |
181 } | 184 } |
182 | 185 |
183 SectorConstraints _constraints; | 186 SectorConstraints _constraints; |
184 void layout(SectorConstraints constraints, double radius, { RenderNode relayou
tSubtreeRoot }) { | 187 void layout(SectorConstraints constraints, { RenderNode relayoutSubtreeRoot })
{ |
185 if (relayoutSubtreeRoot != null) | 188 if (relayoutSubtreeRoot != null) |
186 saveRelayoutSubtreeRoot(relayoutSubtreeRoot); | 189 saveRelayoutSubtreeRoot(relayoutSubtreeRoot); |
187 relayoutSubtreeRoot = relayoutSubtreeRoot == null ? this : relayoutSubtreeRo
ot; | 190 relayoutSubtreeRoot = relayoutSubtreeRoot == null ? this : relayoutSubtreeRo
ot; |
188 deltaRadius = constraints.constrainDeltaRadius(desiredDeltaRadius); | 191 deltaRadius = constraints.constrainDeltaRadius(desiredDeltaRadius); |
189 assert(deltaRadius < double.INFINITY); | 192 assert(deltaRadius < double.INFINITY); |
190 _constraints = constraints; | 193 _constraints = constraints; |
191 internalLayout(radius, relayoutSubtreeRoot); | 194 internalLayout(relayoutSubtreeRoot); |
192 } | 195 } |
193 | 196 |
194 void relayout() { | 197 void relayout() { |
| 198 // TODO(ianh): avoid code duplication |
195 assert(parentData is SectorParentData); | 199 assert(parentData is SectorParentData); |
196 internalLayout(parentData.radius, this); | 200 internalLayout(this); |
197 } | 201 } |
198 | 202 |
199 void internalLayout(double radius, RenderNode relayoutSubtreeRoot) { | 203 void internalLayout(RenderNode relayoutSubtreeRoot) { |
| 204 assert(this.parentData is SectorParentData); |
200 double innerDeltaRadius = deltaRadius - padding * 2.0; | 205 double innerDeltaRadius = deltaRadius - padding * 2.0; |
201 double childRadius = radius + padding; | 206 double childRadius = this.parentData.radius + padding; |
202 double paddingTheta = math.atan(padding / (radius + deltaRadius)); | 207 double paddingTheta = math.atan(padding / (this.parentData.radius + deltaRad
ius)); |
203 double innerTheta = paddingTheta; // increments with each child | 208 double innerTheta = paddingTheta; // increments with each child |
204 double remainingTheta = _constraints.maxDeltaTheta - (innerTheta + paddingTh
eta); | 209 double remainingDeltaTheta = _constraints.maxDeltaTheta - (innerTheta + padd
ingTheta); |
205 RenderSector child = firstChild; | 210 RenderSector child = firstChild; |
206 while (child != null) { | 211 while (child != null) { |
207 SectorConstraints innerConstraints = new SectorConstraints( | 212 SectorConstraints innerConstraints = new SectorConstraints( |
208 maxDeltaRadius: innerDeltaRadius, | 213 maxDeltaRadius: innerDeltaRadius, |
209 maxDeltaTheta: remainingTheta | 214 maxDeltaTheta: remainingDeltaTheta |
210 ); | 215 ); |
211 child.layout(innerConstraints, childRadius, relayoutSubtreeRoot: relayoutS
ubtreeRoot); | |
212 assert(child.parentData is SectorParentData); | 216 assert(child.parentData is SectorParentData); |
213 child.parentData.theta = innerTheta; | 217 child.parentData.theta = innerTheta; |
214 child.parentData.radius = childRadius; | 218 child.parentData.radius = childRadius; |
| 219 child.layout(innerConstraints, relayoutSubtreeRoot: relayoutSubtreeRoot); |
215 innerTheta += child.deltaTheta; | 220 innerTheta += child.deltaTheta; |
216 remainingTheta -= child.deltaTheta; | 221 remainingDeltaTheta -= child.deltaTheta; |
217 assert(child.parentData is SectorChildListParentData); | 222 assert(child.parentData is SectorChildListParentData); |
218 child = child.parentData.nextSibling; | 223 child = child.parentData.nextSibling; |
219 if (child != null) { | 224 if (child != null) { |
220 innerTheta += paddingTheta; | 225 innerTheta += paddingTheta; |
221 remainingTheta -= paddingTheta; | 226 remainingDeltaTheta -= paddingTheta; |
222 } | 227 } |
223 } | 228 } |
224 deltaTheta = innerTheta; | 229 deltaTheta = innerTheta; |
225 } | 230 } |
226 | 231 |
227 // TODO(ianh): hit testing et al is pending on adam's patch | 232 // TODO(ianh): hit testing et al is pending on adam's patch |
228 | 233 |
229 // paint origin is 0,0 of our circle | 234 // paint origin is 0,0 of our circle |
230 // each sector then knows how to paint itself at its location | 235 // each sector then knows how to paint itself at its location |
231 void paint(RenderNodeDisplayList canvas) { | 236 void paint(RenderNodeDisplayList canvas) { |
| 237 // TODO(ianh): avoid code duplication |
232 super.paint(canvas); | 238 super.paint(canvas); |
233 RenderSector child = firstChild; | 239 RenderSector child = firstChild; |
234 while (child != null) { | 240 while (child != null) { |
| 241 assert(child.parentData is SectorChildListParentData); |
| 242 canvas.paintChild(child, 0.0, 0.0); |
| 243 child = child.parentData.nextSibling; |
| 244 } |
| 245 } |
| 246 |
| 247 } |
| 248 |
| 249 class RenderSectorSlice extends RenderDecoratedSector with ContainerRenderNodeMi
xin<RenderSector, SectorChildListParentData> { |
| 250 // lays out RenderSector children in a stack |
| 251 |
| 252 RenderSectorSlice({ |
| 253 BoxDecoration decoration, |
| 254 double deltaTheta: kTwoPi, |
| 255 double padding: 0.0 |
| 256 }) : super(decoration), _padding = padding, _desiredDeltaTheta = deltaTheta; |
| 257 |
| 258 double _desiredDeltaTheta; |
| 259 double get desiredDeltaTheta => _desiredDeltaTheta; |
| 260 void set desiredDeltaTheta(double value) { |
| 261 assert(value != null); |
| 262 if (_desiredDeltaTheta != value) { |
| 263 _desiredDeltaTheta = value; |
| 264 markNeedsLayout(); |
| 265 } |
| 266 } |
| 267 |
| 268 double _padding; |
| 269 double get padding => _padding; |
| 270 void set padding(double value) { |
| 271 // TODO(ianh): avoid code duplication |
| 272 assert(value != null); |
| 273 if (_padding != value) { |
| 274 _padding = value; |
| 275 markNeedsLayout(); |
| 276 } |
| 277 } |
| 278 |
| 279 void setParentData(RenderNode child) { |
| 280 // TODO(ianh): avoid code duplication |
| 281 if (child.parentData is! SectorChildListParentData) |
| 282 child.parentData = new SectorChildListParentData(); |
| 283 } |
| 284 |
| 285 SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double
radius) { |
| 286 assert(this.parentData is SectorParentData); |
| 287 double paddingTheta = math.atan(padding / this.parentData.radius); |
| 288 double outerDeltaTheta = constraints.constrainDeltaTheta(desiredDeltaTheta); |
| 289 double innerDeltaTheta = outerDeltaTheta - paddingTheta * 2.0; |
| 290 double childRadius = this.parentData.radius + padding; |
| 291 double remainingDeltaRadius = constraints.maxDeltaRadius - (padding * 2.0); |
| 292 RenderSector child = firstChild; |
| 293 while (child != null) { |
| 294 SectorConstraints innerConstraints = new SectorConstraints( |
| 295 maxDeltaRadius: remainingDeltaRadius, |
| 296 maxDeltaTheta: innerDeltaTheta |
| 297 ); |
| 298 SectorDimensions childDimensions = child.getIntrinsicDimensions(innerConst
raints, childRadius); |
| 299 childRadius += childDimensions.deltaRadius; |
| 300 remainingDeltaRadius -= childDimensions.deltaRadius; |
| 301 assert(child.parentData is SectorChildListParentData); |
| 302 child = child.parentData.nextSibling; |
| 303 childRadius += padding; |
| 304 remainingDeltaRadius -= padding; |
| 305 } |
| 306 return new SectorDimensions.withConstraints(constraints, |
| 307 deltaRadius: childRadius - this.
parentData.radius, |
| 308 deltaTheta: outerDeltaTheta); |
| 309 } |
| 310 |
| 311 SectorConstraints _constraints; |
| 312 void layout(SectorConstraints constraints, { RenderNode relayoutSubtreeRoot })
{ |
| 313 if (relayoutSubtreeRoot != null) |
| 314 saveRelayoutSubtreeRoot(relayoutSubtreeRoot); |
| 315 relayoutSubtreeRoot = relayoutSubtreeRoot == null ? this : relayoutSubtreeRo
ot; |
| 316 deltaTheta = constraints.constrainDeltaTheta(desiredDeltaTheta); |
| 317 assert(deltaTheta <= kTwoPi); |
| 318 _constraints = constraints; |
| 319 internalLayout(relayoutSubtreeRoot); |
| 320 } |
| 321 |
| 322 void relayout() { |
| 323 // TODO(ianh): avoid code duplication |
| 324 assert(parentData is SectorParentData); |
| 325 internalLayout(this); |
| 326 } |
| 327 |
| 328 void internalLayout(RenderNode relayoutSubtreeRoot) { |
| 329 assert(this.parentData is SectorParentData); |
| 330 double paddingTheta = math.atan(padding / this.parentData.radius); |
| 331 double innerTheta = this.parentData.theta + paddingTheta; |
| 332 double innerDeltaTheta = deltaTheta - paddingTheta * 2.0; |
| 333 double childRadius = this.parentData.radius + padding; |
| 334 double remainingDeltaRadius = _constraints.maxDeltaRadius - (padding * 2.0); |
| 335 RenderSector child = firstChild; |
| 336 while (child != null) { |
| 337 SectorConstraints innerConstraints = new SectorConstraints( |
| 338 maxDeltaRadius: remainingDeltaRadius, |
| 339 maxDeltaTheta: innerDeltaTheta |
| 340 ); |
| 341 child.parentData.theta = innerTheta; |
| 342 child.parentData.radius = childRadius; |
| 343 child.layout(innerConstraints); |
| 344 childRadius += child.deltaRadius; |
| 345 remainingDeltaRadius -= child.deltaRadius; |
| 346 assert(child.parentData is SectorChildListParentData); |
| 347 child = child.parentData.nextSibling; |
| 348 childRadius += padding; |
| 349 remainingDeltaRadius -= padding; |
| 350 } |
| 351 deltaRadius = childRadius - this.parentData.radius; |
| 352 } |
| 353 |
| 354 // TODO(ianh): hit testing et al is pending on adam's patch |
| 355 |
| 356 // paint origin is 0,0 of our circle |
| 357 // each sector then knows how to paint itself at its location |
| 358 void paint(RenderNodeDisplayList canvas) { |
| 359 // TODO(ianh): avoid code duplication |
| 360 super.paint(canvas); |
| 361 RenderSector child = firstChild; |
| 362 while (child != null) { |
235 assert(child.parentData is SectorChildListParentData); | 363 assert(child.parentData is SectorChildListParentData); |
236 canvas.paintChild(child, 0.0, 0.0); | 364 canvas.paintChild(child, 0.0, 0.0); |
237 child = child.parentData.nextSibling; | 365 child = child.parentData.nextSibling; |
238 } | 366 } |
239 } | 367 } |
240 | 368 |
241 } | 369 } |
242 | 370 |
243 class RenderBoxToRenderSectorAdapter extends RenderBox { | 371 class RenderBoxToRenderSectorAdapter extends RenderBox { |
244 | 372 |
(...skipping 24 matching lines...) Expand all Loading... |
269 if (child.parentData is! SectorParentData) | 397 if (child.parentData is! SectorParentData) |
270 child.parentData = new SectorParentData(); | 398 child.parentData = new SectorParentData(); |
271 } | 399 } |
272 | 400 |
273 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { | 401 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { |
274 if (child == null) | 402 if (child == null) |
275 return new BoxDimensions.withConstraints(constraints, width: 0.0, height:
0.0); | 403 return new BoxDimensions.withConstraints(constraints, width: 0.0, height:
0.0); |
276 assert(child is RenderSector); | 404 assert(child is RenderSector); |
277 assert(child.parentData is SectorParentData); | 405 assert(child.parentData is SectorParentData); |
278 assert(!constraints.isInfinite); | 406 assert(!constraints.isInfinite); |
279 double maxChildDeltaRadius = math.max(constraints.maxWidth, constraints.maxH
eight) / 2.0 - innerRadius; | 407 double maxChildDeltaRadius = math.min(constraints.maxWidth, constraints.maxH
eight) / 2.0 - innerRadius; |
280 SectorDimensions childDimensions = child.getIntrinsicDimensions(new SectorCo
nstraints(maxDeltaRadius: maxChildDeltaRadius), innerRadius); | 408 SectorDimensions childDimensions = child.getIntrinsicDimensions(new SectorCo
nstraints(maxDeltaRadius: maxChildDeltaRadius), innerRadius); |
281 double dimension = (innerRadius + childDimensions.deltaRadius) * 2.0; | 409 double dimension = (innerRadius + childDimensions.deltaRadius) * 2.0; |
282 return new BoxDimensions.withConstraints(constraints, width: dimension, heig
ht: dimension); | 410 return new BoxDimensions.withConstraints(constraints, width: dimension, heig
ht: dimension); |
283 } | 411 } |
284 | 412 |
285 void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) { | 413 void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) { |
286 if (relayoutSubtreeRoot != null) | 414 if (relayoutSubtreeRoot != null) |
287 saveRelayoutSubtreeRoot(relayoutSubtreeRoot); | 415 saveRelayoutSubtreeRoot(relayoutSubtreeRoot); |
288 relayoutSubtreeRoot = relayoutSubtreeRoot == null ? this : relayoutSubtreeRo
ot; | 416 relayoutSubtreeRoot = relayoutSubtreeRoot == null ? this : relayoutSubtreeRo
ot; |
289 BoxDimensions ourDimensions; | 417 BoxDimensions ourDimensions; |
290 if (child == null) { | 418 if (child == null) { |
291 ourDimensions = new BoxDimensions.withConstraints(constraints, width: 0.0,
height: 0.0); | 419 ourDimensions = new BoxDimensions.withConstraints(constraints, width: 0.0,
height: 0.0); |
292 } else { | 420 } else { |
293 assert(child is RenderSector); | 421 assert(child is RenderSector); |
294 assert(child.parentData is SectorParentData); | |
295 assert(!constraints.isInfinite); | 422 assert(!constraints.isInfinite); |
296 double maxChildDeltaRadius = math.min(constraints.maxWidth, constraints.ma
xHeight) / 2.0 - innerRadius; | 423 double maxChildDeltaRadius = math.min(constraints.maxWidth, constraints.ma
xHeight) / 2.0 - innerRadius; |
297 child.layout(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), i
nnerRadius, relayoutSubtreeRoot: relayoutSubtreeRoot); | 424 assert(child.parentData is SectorParentData); |
| 425 child.parentData.radius = innerRadius; |
| 426 child.parentData.theta = 0.0; |
| 427 child.layout(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), r
elayoutSubtreeRoot: relayoutSubtreeRoot); |
298 double dimension = (innerRadius + child.deltaRadius) * 2.0; | 428 double dimension = (innerRadius + child.deltaRadius) * 2.0; |
299 ourDimensions = new BoxDimensions.withConstraints(constraints, width: dime
nsion, height: dimension); | 429 ourDimensions = new BoxDimensions.withConstraints(constraints, width: dime
nsion, height: dimension); |
300 } | 430 } |
301 width = ourDimensions.width; | 431 width = ourDimensions.width; |
302 height = ourDimensions.height; | 432 height = ourDimensions.height; |
303 print("adapter is: ${width}x${height}"); | |
304 layoutDone(); | 433 layoutDone(); |
305 } | 434 } |
306 | 435 |
307 double width; | 436 double width; |
308 double height; | 437 double height; |
309 | 438 |
310 // TODO(ianh): hit testing et al is pending on adam's patch | 439 // TODO(ianh): hit testing et al is pending on adam's patch |
311 | 440 |
312 // paint origin is 0,0 of our circle | 441 // paint origin is 0,0 of our circle |
313 void paint(RenderNodeDisplayList canvas) { | 442 void paint(RenderNodeDisplayList canvas) { |
314 super.paint(canvas); | 443 super.paint(canvas); |
315 if (child != null) { | 444 if (child != null) |
316 print("painting child at ${width/2.0},${height/2.0}"); | |
317 sky.Paint paint; | |
318 paint = new sky.Paint()..color = 0xFF474700; | |
319 canvas.drawRect(new sky.Rect()..setLTRB(0.0, 0.0, width, height), paint); | |
320 paint = new sky.Paint()..color = 0xFFF7F700; | |
321 canvas.drawRect(new sky.Rect()..setLTRB(10.0, 10.0, width-10.0, height-10.
0), paint); | |
322 paint = new sky.Paint()..color = 0xFFFFFFFF; | |
323 canvas.drawRect(new sky.Rect()..setLTRB(width/2.0-5.0, height/2.0-5.0, wid
th/2.0+5.0, height/2.0+5.0), paint); | |
324 canvas.paintChild(child, width/2.0, height/2.0); | 445 canvas.paintChild(child, width/2.0, height/2.0); |
325 } | |
326 } | 446 } |
327 | 447 |
328 } | 448 } |
329 | 449 |
330 class RenderSolidColor extends RenderDecoratedSector { | 450 class RenderSolidColor extends RenderDecoratedSector { |
331 final int backgroundColor; | 451 RenderSolidColor(int backgroundColor, { |
| 452 this.desiredDeltaRadius: double.INFINITY, |
| 453 this.desiredDeltaTheta: kTwoPi |
| 454 }) : super(new BoxDecoration(backgroundColor: backgroundColor)); |
332 | 455 |
333 RenderSolidColor(int backgroundColor) | 456 double desiredDeltaRadius; |
334 : super(new BoxDecoration(backgroundColor: backgroundColor)), | 457 double desiredDeltaTheta; |
335 backgroundColor = backgroundColor; | |
336 | 458 |
337 SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double
radius) { | 459 SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double
radius) { |
338 return new SectorDimensions.withConstraints(constraints, deltaTheta: 1.0); /
/ 1.0 radians | 460 return new SectorDimensions.withConstraints(constraints, deltaTheta: 1.0); /
/ 1.0 radians |
339 } | 461 } |
340 | 462 |
341 void layout(SectorConstraints constraints, double radius, { RenderNode relayou
tSubtreeRoot }) { | 463 void layout(SectorConstraints constraints, { RenderNode relayoutSubtreeRoot })
{ |
342 deltaRadius = constraints.constrainDeltaRadius(constraints.maxDeltaRadius); | 464 deltaRadius = constraints.constrainDeltaRadius(desiredDeltaRadius); |
343 deltaTheta = constraints.constrainDeltaTheta(1.0); // 1.0 radians | 465 deltaTheta = constraints.constrainDeltaTheta(desiredDeltaTheta); |
344 layoutDone(); | 466 layoutDone(); |
345 } | 467 } |
346 } | 468 } |
347 | 469 |
348 RenderView renderView; | 470 RenderView renderView; |
349 | 471 |
350 void beginFrame(double timeStamp) { | 472 void beginFrame(double timeStamp) { |
351 RenderNode.flushLayout(); | 473 RenderNode.flushLayout(); |
352 | 474 |
353 renderView.paintFrame(); | 475 renderView.paintFrame(); |
354 } | 476 } |
355 | 477 |
356 bool handleEvent(sky.Event event) { | 478 bool handleEvent(sky.Event event) { |
357 if (event is! sky.PointerEvent) | 479 if (event is! sky.PointerEvent) |
358 return false; | 480 return false; |
359 return renderView.handlePointer(event, x: event.x, y: event.y); | 481 return renderView.handlePointer(event, x: event.x, y: event.y); |
360 } | 482 } |
361 | 483 |
362 void main() { | 484 void main() { |
363 print("test..."); | 485 print("test..."); |
364 sky.view.setEventCallback(handleEvent); | 486 sky.view.setEventCallback(handleEvent); |
365 sky.view.setBeginFrameCallback(beginFrame); | 487 sky.view.setBeginFrameCallback(beginFrame); |
366 | 488 |
367 var rootCircle = new RenderSectorRing(padding: 10.0); | 489 var rootCircle = new RenderSectorRing(padding: 10.0); |
368 rootCircle.add(new RenderSolidColor(0xFF00FF00)); | 490 rootCircle.add(new RenderSolidColor(0xFF00FFFF, desiredDeltaTheta: kTwoPi * 0.
25)); |
369 rootCircle.add(new RenderSolidColor(0xFF0000FF)); | 491 rootCircle.add(new RenderSolidColor(0xFF0000FF, desiredDeltaTheta: kTwoPi * 0.
3)); |
| 492 var stack = new RenderSectorSlice(padding: 10.0); |
| 493 stack.add(new RenderSolidColor(0xFFFFFF00, desiredDeltaRadius: 20.0)); |
| 494 stack.add(new RenderSolidColor(0xFFFF9000, desiredDeltaRadius: 20.0)); |
| 495 stack.add(new RenderSolidColor(0xFF00FF00, desiredDeltaRadius: 20.0)); |
| 496 rootCircle.add(stack); |
370 | 497 |
371 var root = new RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCi
rcle); | 498 var root = new RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCi
rcle); |
372 renderView = new RenderView(root: root); | 499 renderView = new RenderView(root: root); |
373 renderView.layout(newWidth: sky.view.width, newHeight: sky.view.height); | 500 renderView.layout(newWidth: sky.view.width, newHeight: sky.view.height); |
374 | 501 |
375 sky.view.scheduleFrame(); | 502 sky.view.scheduleFrame(); |
376 print("window is ${sky.view.width}x${sky.view.height}"); | |
377 } | 503 } |
OLD | NEW |