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

Side by Side Diff: sky/sdk/lib/framework/components2/scaffold.dart

Issue 1156303004: Use Point, Size, and Rect in layout2.dart (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: address review comments 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/framework/app.dart ('k') | sky/sdk/lib/framework/fn2.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 '../fn2.dart'; 5 import '../fn2.dart';
6 import '../layout2.dart'; 6 import '../layout2.dart';
7 import '../theme/typography.dart' as typography; 7 import '../theme/typography.dart' as typography;
8 import 'dart:sky' as sky;
8 9
9 // RenderNode 10 // RenderNode
10 class RenderScaffold extends RenderDecoratedBox { 11 class RenderScaffold extends RenderDecoratedBox {
11 12
12 RenderScaffold({ 13 RenderScaffold({
13 BoxDecoration decoration, 14 BoxDecoration decoration,
14 RenderBox toolbar, 15 RenderBox toolbar,
15 RenderBox body, 16 RenderBox body,
16 RenderBox statusbar, 17 RenderBox statusbar,
17 RenderBox drawer, 18 RenderBox drawer,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 if (_floatingActionButton != null) 75 if (_floatingActionButton != null)
75 dropChild(_floatingActionButton); 76 dropChild(_floatingActionButton);
76 _floatingActionButton = value; 77 _floatingActionButton = value;
77 if (_floatingActionButton != null) 78 if (_floatingActionButton != null)
78 adoptChild(_floatingActionButton); 79 adoptChild(_floatingActionButton);
79 markNeedsLayout(); 80 markNeedsLayout();
80 } 81 }
81 82
82 bool get sizedByParent => true; 83 bool get sizedByParent => true;
83 void performResize() { 84 void performResize() {
84 width = constraints.constrainWidth(double.INFINITY); 85 size = constraints.constrain(new sky.Size.infinite());
85 assert(width < double.INFINITY); 86 assert(size.width < double.INFINITY);
86 height = constraints.constrainHeight(double.INFINITY); 87 assert(size.height < double.INFINITY);
87 assert(height < double.INFINITY);
88 } 88 }
89 89
90 static const kToolbarHeight = 100.0; 90 static const kToolbarHeight = 100.0;
91 static const kStatusbarHeight = 50.0; 91 static const kStatusbarHeight = 50.0;
92 static const kButtonX = -16.0; // from right edge of body 92 static const kButtonX = -16.0; // from right edge of body
93 static const kButtonY = -16.0; // from bottom edge of body 93 static const kButtonY = -16.0; // from bottom edge of body
94 94
95 void performLayout() { 95 void performLayout() {
96 double bodyHeight = height; 96 double bodyHeight = size.height;
97 double bodyPosition = 0.0; 97 double bodyPosition = 0.0;
98 if (toolbar != null) { 98 if (toolbar != null) {
99 toolbar.layout(new BoxConstraints.tight(width: width, height: kToolbarHeig ht)); 99 toolbar.layout(new BoxConstraints.tight(width: size.width, height: kToolba rHeight));
100 assert(toolbar.parentData is BoxParentData); 100 assert(toolbar.parentData is BoxParentData);
101 toolbar.parentData.x = 0.0; 101 toolbar.parentData.position = new sky.Point(0.0, 0.0);
102 toolbar.parentData.y = 0.0;
103 bodyPosition = kToolbarHeight; 102 bodyPosition = kToolbarHeight;
104 bodyHeight -= kToolbarHeight; 103 bodyHeight -= kToolbarHeight;
105 } 104 }
106 if (statusbar != null) { 105 if (statusbar != null) {
107 statusbar.layout(new BoxConstraints.tight(width: width, height: kStatusbar Height)); 106 statusbar.layout(new BoxConstraints.tight(width: size.width, height: kStat usbarHeight));
108 assert(statusbar.parentData is BoxParentData); 107 assert(statusbar.parentData is BoxParentData);
109 statusbar.parentData.x = 0.0; 108 statusbar.parentData.position = new sky.Point(0.0, size.height - kStatusba rHeight);
110 statusbar.parentData.y = height - kStatusbarHeight;
111 bodyHeight -= kStatusbarHeight; 109 bodyHeight -= kStatusbarHeight;
112 } 110 }
113 if (body != null) { 111 if (body != null) {
114 body.layout(new BoxConstraints.tight(width: width, height: bodyHeight)); 112 body.layout(new BoxConstraints.tight(width: size.width, height: bodyHeight ));
115 assert(body.parentData is BoxParentData); 113 assert(body.parentData is BoxParentData);
116 body.parentData.x = 0.0; 114 body.parentData.position = new sky.Point(0.0, bodyPosition);
117 body.parentData.y = bodyPosition;
118 } 115 }
119 if (drawer != null) { 116 if (drawer != null) {
120 drawer.layout(new BoxConstraints(minWidth: 0.0, maxWidth: width, minHeight : height, maxHeight: height)); 117 drawer.layout(new BoxConstraints(minWidth: 0.0, maxWidth: size.width, minH eight: size.height, maxHeight: size.height));
121 assert(drawer.parentData is BoxParentData); 118 assert(drawer.parentData is BoxParentData);
122 drawer.parentData.x = 0.0; 119 drawer.parentData.position = new sky.Point(0.0, 0.0);
123 drawer.parentData.y = 0.0;
124 } 120 }
125 if (floatingActionButton != null) { 121 if (floatingActionButton != null) {
126 floatingActionButton.layout(new BoxConstraints(minWidth: 0.0, maxWidth: wi dth, minHeight: height, maxHeight: height)); 122 floatingActionButton.layout(new BoxConstraints(minWidth: 0.0, maxWidth: si ze.width, minHeight: size.height, maxHeight: size.height));
127 assert(floatingActionButton.parentData is BoxParentData); 123 assert(floatingActionButton.parentData is BoxParentData);
128 floatingActionButton.parentData.x = width - xButtonX; 124 floatingActionButton.parentData.position = new sky.Point(size.width - xBut tonX, bodyPosition + bodyHeight - kButtonY);
129 floatingActionButton.parentData.y = bodyPosition + bodyHeight - kButtonY;
130 } 125 }
131 } 126 }
132 127
133 void paint(RenderNodeDisplayList canvas) { 128 void paint(RenderNodeDisplayList canvas) {
134 if (body != null) 129 if (body != null)
135 canvas.paintChild(body, (body.parentData as BoxParentData).x, (body.parent Data as BoxParentData).y); 130 canvas.paintChild(body, (body.parentData as BoxParentData).position);
136 if (statusbar != null) 131 if (statusbar != null)
137 canvas.paintChild(statusbar, (statusbar.parentData as BoxParentData).x, (s tatusbar.parentData as BoxParentData).y); 132 canvas.paintChild(statusbar, (statusbar.parentData as BoxParentData).posit ion);
138 if (toolbar != null) 133 if (toolbar != null)
139 canvas.paintChild(toolbar, (toolbar.parentData as BoxParentData).x, (toolb ar.parentData as BoxParentData).y); 134 canvas.paintChild(toolbar, (toolbar.parentData as BoxParentData).position) ;
140 if (floatingActionButton != null) 135 if (floatingActionButton != null)
141 canvas.paintChild(floatingActionButton, (floatingActionButton.parentData a s BoxParentData).x, (floatingActionButton.parentData as BoxParentData).y); 136 canvas.paintChild(floatingActionButton, (floatingActionButton.parentData a s BoxParentData).position);
142 if (drawer != null) 137 if (drawer != null)
143 canvas.paintChild(drawer, (drawer.parentData as BoxParentData).x, (drawer. parentData as BoxParentData).y); 138 canvas.paintChild(drawer, (drawer.parentData as BoxParentData).position);
144 } 139 }
145 140
146 void hitTestChildren(HitTestResult result, { double x, double y }) { 141 void hitTestChildren(HitTestResult result, { sky.Point position }) {
147 assert(floatingActionButton == null || floatingActionButton.parentData is Bo xParentData); 142 assert(floatingActionButton == null || floatingActionButton.parentData is Bo xParentData);
148 assert(statusbar == null || statusbar.parentData is BoxParentData); 143 assert(statusbar == null || statusbar.parentData is BoxParentData);
149 if ((drawer != null) && (x < drawer.width)) { 144 if ((drawer != null) && (x < drawer.size.width)) {
150 drawer.hitTest(result, x: x, y: y); 145 drawer.hitTest(result, position: position);
151 } else if ((floatingActionButton != null) && (x >= floatingActionButton.pare ntData.x) && (x < floatingActionButton.parentData.x + floatingActionButton.width ) 146 } else if ((floatingActionButton != null) && (position.x >= floatingActionBu tton.parentData.position.x) && (position.x < floatingActionButton.parentData.pos ition.x + floatingActionButton.size.width)
152 && (y >= floatingActionButton.pare ntData.y) && (y < floatingActionButton.parentData.y + floatingActionButton.heigh t)) { 147 && (position.y >= floatingActionBu tton.parentData.position.y) && (position.y < floatingActionButton.parentData.pos ition.y + floatingActionButton.size.height)) {
153 floatingActionButton.hitTest(result, x: x-floatingActionButton.parentData. x, y: y-floatingActionButton.parentData.y); 148 floatingActionButton.hitTest(result, position: new sky.Point(position.x - floatingActionButton.parentData.position.x, position.y - floatingActionButton.pa rentData.position.y));
154 } else if ((toolbar != null) && (y < toolbar.height)) { 149 } else if ((toolbar != null) && (position.y < toolbar.size.height)) {
155 toolbar.hitTest(result, x: x, y: y); 150 toolbar.hitTest(result, position: position);
156 } else if ((statusbar != null) && (y > statusbar.parentData.y)) { 151 } else if ((statusbar != null) && (position.y > statusbar.parentData.positio n.y)) {
157 statusbar.hitTest(result, x: x, y: y-statusbar.parentData.y); 152 statusbar.hitTest(result, position: new sky.Point(position.x, position.y - statusbar.parentData.position.y));
158 } else if (body != null) { 153 } else if (body != null) {
159 body.hitTest(result, x: x, y: y-body.parentData.y); 154 body.hitTest(result, position: new sky.Point(position.x, position.y - body .parentData.position.y));
160 } 155 }
161 } 156 }
162 157
163 } 158 }
164 159
165 class Scaffold extends RenderNodeWrapper { 160 class Scaffold extends RenderNodeWrapper {
166 161
167 // static final Style _style = new Style(''' 162 // static final Style _style = new Style('''
168 // ${typography.typeface}; 163 // ${typography.typeface};
169 // ${typography.black.body1};'''); 164 // ${typography.black.body1};''');
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 void syncRenderNode(UINode old) { 214 void syncRenderNode(UINode old) {
220 super.syncRenderNode(old); 215 super.syncRenderNode(old);
221 syncChild(toolbar, old is Scaffold ? old.toolbar : null, #toolbar); 216 syncChild(toolbar, old is Scaffold ? old.toolbar : null, #toolbar);
222 syncChild(body, old is Scaffold ? old.body : null, #body); 217 syncChild(body, old is Scaffold ? old.body : null, #body);
223 syncChild(statusbar, old is Scaffold ? old.statusbar : null, #statusbar); 218 syncChild(statusbar, old is Scaffold ? old.statusbar : null, #statusbar);
224 syncChild(drawer, old is Scaffold ? old.drawer : null, #drawer); 219 syncChild(drawer, old is Scaffold ? old.drawer : null, #drawer);
225 syncChild(floatingActionButton, old is Scaffold ? old.floatingActionButton : null, #floatingActionButton); 220 syncChild(floatingActionButton, old is Scaffold ? old.floatingActionButton : null, #floatingActionButton);
226 } 221 }
227 222
228 } 223 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/framework/app.dart ('k') | sky/sdk/lib/framework/fn2.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698