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

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: 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
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 void set floatingActionButton (RenderBox value) { 74 void set floatingActionButton (RenderBox value) {
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 void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) { 83 void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) {
83 width = constraints.constrainWidth(double.INFINITY); 84 size = constraints.constrain(new sky.Size.infinite());
84 assert(width < double.INFINITY); 85 assert(size.width < double.INFINITY);
85 height = constraints.constrainHeight(double.INFINITY); 86 assert(size.height < double.INFINITY);
86 assert(height < double.INFINITY);
87 relayout(); 87 relayout();
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 relayout() { 95 void relayout() {
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();
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();
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 layoutDone(); 126 layoutDone();
132 } 127 }
133 128
134 void paint(RenderNodeDisplayList canvas) { 129 void paint(RenderNodeDisplayList canvas) {
135 if (body != null) 130 if (body != null)
136 canvas.paintChild(body, (body.parentData as BoxParentData).x, (body.parent Data as BoxParentData).y); 131 canvas.paintChild(body, (body.parentData as BoxParentData).position);
137 if (statusbar != null) 132 if (statusbar != null)
138 canvas.paintChild(statusbar, (statusbar.parentData as BoxParentData).x, (s tatusbar.parentData as BoxParentData).y); 133 canvas.paintChild(statusbar, (statusbar.parentData as BoxParentData).posit ion);
139 if (toolbar != null) 134 if (toolbar != null)
140 canvas.paintChild(toolbar, (toolbar.parentData as BoxParentData).x, (toolb ar.parentData as BoxParentData).y); 135 canvas.paintChild(toolbar, (toolbar.parentData as BoxParentData).position) ;
141 if (floatingActionButton != null) 136 if (floatingActionButton != null)
142 canvas.paintChild(floatingActionButton, (floatingActionButton.parentData a s BoxParentData).x, (floatingActionButton.parentData as BoxParentData).y); 137 canvas.paintChild(floatingActionButton, (floatingActionButton.parentData a s BoxParentData).position);
143 if (drawer != null) 138 if (drawer != null)
144 canvas.paintChild(drawer, (drawer.parentData as BoxParentData).x, (drawer. parentData as BoxParentData).y); 139 canvas.paintChild(drawer, (drawer.parentData as BoxParentData).position);
145 } 140 }
146 141
147 void hitTestChildren(HitTestResult result, { double x, double y }) { 142 void hitTestChildren(HitTestResult result, { sky.Point position }) {
148 assert(floatingActionButton == null || floatingActionButton.parentData is Bo xParentData); 143 assert(floatingActionButton == null || floatingActionButton.parentData is Bo xParentData);
149 assert(statusbar == null || statusbar.parentData is BoxParentData); 144 assert(statusbar == null || statusbar.parentData is BoxParentData);
150 if ((drawer != null) && (x < drawer.width)) { 145 if ((drawer != null) && (x < drawer.size.width)) {
151 drawer.hitTest(result, x: x, y: y); 146 drawer.hitTest(result, position: position);
152 } else if ((floatingActionButton != null) && (x >= floatingActionButton.pare ntData.x) && (x < floatingActionButton.parentData.x + floatingActionButton.width ) 147 } else if ((floatingActionButton != null) && (position.x >= floatingActionBu tton.parentData.position.x) && (position.x < floatingActionButton.parentData.pos ition.x + floatingActionButton.size.width)
153 && (y >= floatingActionButton.pare ntData.y) && (y < floatingActionButton.parentData.y + floatingActionButton.heigh t)) { 148 && (position.y >= floatingActionBu tton.parentData.position.y) && (position.y < floatingActionButton.parentData.pos ition.y + floatingActionButton.size.height)) {
154 floatingActionButton.hitTest(result, x: x-floatingActionButton.parentData. x, y: y-floatingActionButton.parentData.y); 149 floatingActionButton.hitTest(result, position: new sky.Point(position.x - floatingActionButton.parentData.position.x, position.y - floatingActionButton.pa rentData.position.y));
155 } else if ((toolbar != null) && (y < toolbar.height)) { 150 } else if ((toolbar != null) && (position.y < toolbar.size.height)) {
156 toolbar.hitTest(result, x: x, y: y); 151 toolbar.hitTest(result, position: position);
157 } else if ((statusbar != null) && (y > statusbar.parentData.y)) { 152 } else if ((statusbar != null) && (position.y > statusbar.parentData.positio n.y)) {
158 statusbar.hitTest(result, x: x, y: y-statusbar.parentData.y); 153 statusbar.hitTest(result, position: new sky.Point(position.x, position.y - statusbar.parentData.position.y));
159 } else if (body != null) { 154 } else if (body != null) {
160 body.hitTest(result, x: x, y: y-body.parentData.y); 155 body.hitTest(result, position: new sky.Point(position.x, position.y - body .parentData.position.y));
161 } 156 }
162 } 157 }
163 158
164 } 159 }
165 160
166 class Scaffold extends RenderNodeWrapper { 161 class Scaffold extends RenderNodeWrapper {
167 162
168 // static final Style _style = new Style(''' 163 // static final Style _style = new Style('''
169 // ${typography.typeface}; 164 // ${typography.typeface};
170 // ${typography.black.body1};'''); 165 // ${typography.black.body1};''');
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 void syncRenderNode(UINode old) { 215 void syncRenderNode(UINode old) {
221 super.syncRenderNode(old); 216 super.syncRenderNode(old);
222 syncChild(toolbar, old is Scaffold ? old.toolbar : null, #toolbar); 217 syncChild(toolbar, old is Scaffold ? old.toolbar : null, #toolbar);
223 syncChild(body, old is Scaffold ? old.body : null, #body); 218 syncChild(body, old is Scaffold ? old.body : null, #body);
224 syncChild(statusbar, old is Scaffold ? old.statusbar : null, #statusbar); 219 syncChild(statusbar, old is Scaffold ? old.statusbar : null, #statusbar);
225 syncChild(drawer, old is Scaffold ? old.drawer : null, #drawer); 220 syncChild(drawer, old is Scaffold ? old.drawer : null, #drawer);
226 syncChild(floatingActionButton, old is Scaffold ? old.floatingActionButton : null, #floatingActionButton); 221 syncChild(floatingActionButton, old is Scaffold ? old.floatingActionButton : null, #floatingActionButton);
227 } 222 }
228 223
229 } 224 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698