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

Side by Side Diff: sky/examples/rendering/sector_layout.dart

Issue 1196553004: Short-circuit the relayoutSubtreeRoot when the child couldn't change dimensions anyway because the … (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
« no previous file with comments | « no previous file | sky/sdk/lib/rendering/box.dart » ('j') | 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 'dart:math' as math; 5 import 'dart:math' as math;
6 import 'dart:sky' as sky; 6 import 'dart:sky' as sky;
7 7
8 import 'package:sky/rendering/box.dart'; 8 import 'package:sky/rendering/box.dart';
9 import 'package:sky/rendering/object.dart'; 9 import 'package:sky/rendering/object.dart';
10 import 'package:sky/rendering/sky_binding.dart'; 10 import 'package:sky/rendering/sky_binding.dart';
11 11
12 const double kTwoPi = 2 * math.PI; 12 const double kTwoPi = 2 * math.PI;
13 13
14 class SectorConstraints { 14 class SectorConstraints extends Constraints {
15 const SectorConstraints({ 15 const SectorConstraints({
16 this.minDeltaRadius: 0.0, 16 this.minDeltaRadius: 0.0,
17 this.maxDeltaRadius: double.INFINITY, 17 this.maxDeltaRadius: double.INFINITY,
18 this.minDeltaTheta: 0.0, 18 this.minDeltaTheta: 0.0,
19 this.maxDeltaTheta: kTwoPi 19 this.maxDeltaTheta: kTwoPi
20 }); 20 });
21 21
22 const SectorConstraints.tight({ double deltaRadius: 0.0, double deltaTheta: 0. 0 }) 22 const SectorConstraints.tight({ double deltaRadius: 0.0, double deltaTheta: 0. 0 })
23 : minDeltaRadius = deltaRadius, 23 : minDeltaRadius = deltaRadius,
24 maxDeltaRadius = deltaRadius, 24 maxDeltaRadius = deltaRadius,
25 minDeltaTheta = deltaTheta, 25 minDeltaTheta = deltaTheta,
26 maxDeltaTheta = deltaTheta; 26 maxDeltaTheta = deltaTheta;
27 27
28 final double minDeltaRadius; 28 final double minDeltaRadius;
29 final double maxDeltaRadius; 29 final double maxDeltaRadius;
30 final double minDeltaTheta; 30 final double minDeltaTheta;
31 final double maxDeltaTheta; 31 final double maxDeltaTheta;
32 32
33 double constrainDeltaRadius(double deltaRadius) { 33 double constrainDeltaRadius(double deltaRadius) {
34 return clamp(min: minDeltaRadius, max: maxDeltaRadius, value: deltaRadius); 34 return clamp(min: minDeltaRadius, max: maxDeltaRadius, value: deltaRadius);
35 } 35 }
36 36
37 double constrainDeltaTheta(double deltaTheta) { 37 double constrainDeltaTheta(double deltaTheta) {
38 return clamp(min: minDeltaTheta, max: maxDeltaTheta, value: deltaTheta); 38 return clamp(min: minDeltaTheta, max: maxDeltaTheta, value: deltaTheta);
39 } 39 }
40
41 bool get isTight => minDeltaTheta >= maxDeltaTheta && minDeltaTheta >= maxDelt aTheta;
40 } 42 }
41 43
42 class SectorDimensions { 44 class SectorDimensions {
43 const SectorDimensions({ this.deltaRadius: 0.0, this.deltaTheta: 0.0 }); 45 const SectorDimensions({ this.deltaRadius: 0.0, this.deltaTheta: 0.0 });
44 46
45 factory SectorDimensions.withConstraints( 47 factory SectorDimensions.withConstraints(
46 SectorConstraints constraints, 48 SectorConstraints constraints,
47 { double deltaRadius: 0.0, double deltaTheta: 0.0 } 49 { double deltaRadius: 0.0, double deltaTheta: 0.0 }
48 ) { 50 ) {
49 return new SectorDimensions( 51 return new SectorDimensions(
(...skipping 15 matching lines...) Expand all
65 67
66 void setParentData(RenderObject child) { 68 void setParentData(RenderObject child) {
67 if (child.parentData is! SectorParentData) 69 if (child.parentData is! SectorParentData)
68 child.parentData = new SectorParentData(); 70 child.parentData = new SectorParentData();
69 } 71 }
70 72
71 SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double radius) { 73 SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double radius) {
72 return new SectorDimensions.withConstraints(constraints); 74 return new SectorDimensions.withConstraints(constraints);
73 } 75 }
74 76
75 SectorConstraints get constraints { SectorConstraints result = super.constrain ts; return result; } 77 SectorConstraints get constraints => super.constraints;
76 void performResize() { 78 void performResize() {
77 // default behaviour for subclasses that have sizedByParent = true 79 // default behaviour for subclasses that have sizedByParent = true
78 deltaRadius = constraints.constrainDeltaRadius(0.0); 80 deltaRadius = constraints.constrainDeltaRadius(0.0);
79 deltaTheta = constraints.constrainDeltaTheta(0.0); 81 deltaTheta = constraints.constrainDeltaTheta(0.0);
80 } 82 }
81 void performLayout() { 83 void performLayout() {
82 // descendants have to either override performLayout() to set both 84 // descendants have to either override performLayout() to set both
83 // the dimensions and lay out children, or, set sizedByParent to 85 // the dimensions and lay out children, or, set sizedByParent to
84 // true so that performResize()'s logic above does its thing. 86 // true so that performResize()'s logic above does its thing.
85 assert(sizedByParent); 87 assert(sizedByParent);
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 stack.add(new RenderSolidColor(const Color(0xFFFFFF00), desiredDeltaRadius: 20 .0)); 520 stack.add(new RenderSolidColor(const Color(0xFFFFFF00), desiredDeltaRadius: 20 .0));
519 stack.add(new RenderSolidColor(const Color(0xFFFF9000), desiredDeltaRadius: 20 .0)); 521 stack.add(new RenderSolidColor(const Color(0xFFFF9000), desiredDeltaRadius: 20 .0));
520 stack.add(new RenderSolidColor(const Color(0xFF00FF00))); 522 stack.add(new RenderSolidColor(const Color(0xFF00FF00)));
521 rootCircle.add(stack); 523 rootCircle.add(stack);
522 return new RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCircle ); 524 return new RenderBoxToRenderSectorAdapter(innerRadius: 50.0, child: rootCircle );
523 } 525 }
524 526
525 void main() { 527 void main() {
526 new SkyBinding(root: buildSectorExample()); 528 new SkyBinding(root: buildSectorExample());
527 } 529 }
OLDNEW
« no previous file with comments | « no previous file | sky/sdk/lib/rendering/box.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698