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 '../fn2.dart'; | 5 import '../fn2.dart'; |
6 import '../rendering/box.dart'; | 6 import '../rendering/box.dart'; |
7 import '../rendering/object.dart'; | 7 import '../rendering/object.dart'; |
8 | 8 |
9 enum ScaffoldSlots { | 9 enum ScaffoldSlots { |
10 toolbar, | 10 toolbar, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 bool get sizedByParent => true; | 74 bool get sizedByParent => true; |
75 void performResize() { | 75 void performResize() { |
76 size = constraints.constrain(Size.infinite); | 76 size = constraints.constrain(Size.infinite); |
77 assert(size.width < double.INFINITY); | 77 assert(size.width < double.INFINITY); |
78 assert(size.height < double.INFINITY); | 78 assert(size.height < double.INFINITY); |
79 } | 79 } |
80 | 80 |
81 static const kToolbarHeight = 100.0; | 81 static const kToolbarHeight = 100.0; |
82 static const kStatusbarHeight = 50.0; | 82 static const kStatusbarHeight = 50.0; |
83 static const kButtonX = -16.0; // from right edge of body | 83 static const kButtonX = 16.0; // left from right edge of body |
84 static const kButtonY = -16.0; // from bottom edge of body | 84 static const kButtonY = 16.0; // up from bottom edge of body |
85 | 85 |
86 void performLayout() { | 86 void performLayout() { |
87 double bodyHeight = size.height; | 87 double bodyHeight = size.height; |
88 double bodyPosition = 0.0; | 88 double bodyPosition = 0.0; |
89 if (_slots[ScaffoldSlots.toolbar] != null) { | 89 if (_slots[ScaffoldSlots.toolbar] != null) { |
90 RenderBox toolbar = _slots[ScaffoldSlots.toolbar]; | 90 RenderBox toolbar = _slots[ScaffoldSlots.toolbar]; |
91 toolbar.layout(new BoxConstraints.tight(new Size(size.width, kToolbarHeigh
t))); | 91 toolbar.layout(new BoxConstraints.tight(new Size(size.width, kToolbarHeigh
t))); |
92 assert(toolbar.parentData is BoxParentData); | 92 assert(toolbar.parentData is BoxParentData); |
93 toolbar.parentData.position = Point.origin; | 93 toolbar.parentData.position = Point.origin; |
94 bodyPosition = kToolbarHeight; | 94 bodyPosition = kToolbarHeight; |
(...skipping 13 matching lines...) Expand all Loading... |
108 body.parentData.position = new Point(0.0, bodyPosition); | 108 body.parentData.position = new Point(0.0, bodyPosition); |
109 } | 109 } |
110 if (_slots[ScaffoldSlots.drawer] != null) { | 110 if (_slots[ScaffoldSlots.drawer] != null) { |
111 RenderBox drawer = _slots[ScaffoldSlots.drawer]; | 111 RenderBox drawer = _slots[ScaffoldSlots.drawer]; |
112 drawer.layout(new BoxConstraints(minWidth: 0.0, maxWidth: size.width, minH
eight: size.height, maxHeight: size.height)); | 112 drawer.layout(new BoxConstraints(minWidth: 0.0, maxWidth: size.width, minH
eight: size.height, maxHeight: size.height)); |
113 assert(drawer.parentData is BoxParentData); | 113 assert(drawer.parentData is BoxParentData); |
114 drawer.parentData.position = Point.origin; | 114 drawer.parentData.position = Point.origin; |
115 } | 115 } |
116 if (_slots[ScaffoldSlots.floatingActionButton] != null) { | 116 if (_slots[ScaffoldSlots.floatingActionButton] != null) { |
117 RenderBox floatingActionButton = _slots[ScaffoldSlots.floatingActionButton
]; | 117 RenderBox floatingActionButton = _slots[ScaffoldSlots.floatingActionButton
]; |
118 Size area = new Size(size.width + kButtonX, size.height + kButtonY); | 118 Size area = new Size(size.width - kButtonX, size.height - kButtonY); |
119 floatingActionButton.layout(new BoxConstraints.loose(area)); | 119 floatingActionButton.layout(new BoxConstraints.loose(area)); |
120 assert(floatingActionButton.parentData is BoxParentData); | 120 assert(floatingActionButton.parentData is BoxParentData); |
121 floatingActionButton.parentData.position = (area - floatingActionButton.si
ze).toPoint(); | 121 floatingActionButton.parentData.position = (area - floatingActionButton.si
ze).toPoint(); |
122 } | 122 } |
123 } | 123 } |
124 | 124 |
125 void paint(RenderObjectDisplayList canvas) { | 125 void paint(RenderObjectDisplayList canvas) { |
126 for (ScaffoldSlots slot in [ScaffoldSlots.body, ScaffoldSlots.statusBar, Sca
ffoldSlots.toolbar, ScaffoldSlots.floatingActionButton, ScaffoldSlots.drawer]) { | 126 for (ScaffoldSlots slot in [ScaffoldSlots.body, ScaffoldSlots.statusBar, Sca
ffoldSlots.toolbar, ScaffoldSlots.floatingActionButton, ScaffoldSlots.drawer]) { |
127 RenderBox box = _slots[slot]; | 127 RenderBox box = _slots[slot]; |
128 if (box != null) { | 128 if (box != null) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 void syncRenderObject(UINode old) { | 203 void syncRenderObject(UINode old) { |
204 super.syncRenderObject(old); | 204 super.syncRenderObject(old); |
205 syncChild(toolbar, old is Scaffold ? old.toolbar : null, ScaffoldSlots.toolb
ar); | 205 syncChild(toolbar, old is Scaffold ? old.toolbar : null, ScaffoldSlots.toolb
ar); |
206 syncChild(body, old is Scaffold ? old.body : null, ScaffoldSlots.body); | 206 syncChild(body, old is Scaffold ? old.body : null, ScaffoldSlots.body); |
207 syncChild(statusbar, old is Scaffold ? old.statusbar : null, ScaffoldSlots.s
tatusBar); | 207 syncChild(statusbar, old is Scaffold ? old.statusbar : null, ScaffoldSlots.s
tatusBar); |
208 syncChild(drawer, old is Scaffold ? old.drawer : null, ScaffoldSlots.drawer)
; | 208 syncChild(drawer, old is Scaffold ? old.drawer : null, ScaffoldSlots.drawer)
; |
209 syncChild(floatingActionButton, old is Scaffold ? old.floatingActionButton :
null, ScaffoldSlots.floatingActionButton); | 209 syncChild(floatingActionButton, old is Scaffold ? old.floatingActionButton :
null, ScaffoldSlots.floatingActionButton); |
210 } | 210 } |
211 | 211 |
212 } | 212 } |
OLD | NEW |