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 'dart:sky' as sky; | 6 import 'dart:sky' as sky; |
7 import '../rendering/box.dart'; | 7 import '../rendering/box.dart'; |
8 import '../rendering/node.dart'; | 8 import '../rendering/object.dart'; |
9 | 9 |
10 | 10 |
11 enum ScaffoldSlots { | 11 enum ScaffoldSlots { |
12 Toolbar, | 12 Toolbar, |
13 Body, | 13 Body, |
14 StatusBar, | 14 StatusBar, |
15 Drawer, | 15 Drawer, |
16 FloatingActionButton | 16 FloatingActionButton |
17 } | 17 } |
18 | 18 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 drawer.parentData.position = new sky.Point(0.0, 0.0); | 100 drawer.parentData.position = new sky.Point(0.0, 0.0); |
101 } | 101 } |
102 if (_slots[ScaffoldSlots.FloatingActionButton] != null) { | 102 if (_slots[ScaffoldSlots.FloatingActionButton] != null) { |
103 RenderBox floatingActionButton = _slots[ScaffoldSlots.FloatingActionButton
]; | 103 RenderBox floatingActionButton = _slots[ScaffoldSlots.FloatingActionButton
]; |
104 floatingActionButton.layout(new BoxConstraints(minWidth: 0.0, maxWidth: si
ze.width, minHeight: size.height, maxHeight: size.height)); | 104 floatingActionButton.layout(new BoxConstraints(minWidth: 0.0, maxWidth: si
ze.width, minHeight: size.height, maxHeight: size.height)); |
105 assert(floatingActionButton.parentData is BoxParentData); | 105 assert(floatingActionButton.parentData is BoxParentData); |
106 floatingActionButton.parentData.position = new sky.Point(size.width - kBut
tonX, bodyPosition + bodyHeight - kButtonY); | 106 floatingActionButton.parentData.position = new sky.Point(size.width - kBut
tonX, bodyPosition + bodyHeight - kButtonY); |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 void paint(RenderNodeDisplayList canvas) { | 110 void paint(RenderObjectDisplayList canvas) { |
111 for (ScaffoldSlots slot in [ScaffoldSlots.Body, ScaffoldSlots.StatusBar, Sca
ffoldSlots.Toolbar, ScaffoldSlots.FloatingActionButton, ScaffoldSlots.Drawer]) { | 111 for (ScaffoldSlots slot in [ScaffoldSlots.Body, ScaffoldSlots.StatusBar, Sca
ffoldSlots.Toolbar, ScaffoldSlots.FloatingActionButton, ScaffoldSlots.Drawer]) { |
112 RenderBox box = _slots[slot]; | 112 RenderBox box = _slots[slot]; |
113 if (box != null) { | 113 if (box != null) { |
114 assert(box.parentData is BoxParentData); | 114 assert(box.parentData is BoxParentData); |
115 canvas.paintChild(box, box.parentData.position); | 115 canvas.paintChild(box, box.parentData.position); |
116 } | 116 } |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 void hitTestChildren(HitTestResult result, { sky.Point position }) { | 120 void hitTestChildren(HitTestResult result, { sky.Point position }) { |
121 for (ScaffoldSlots slot in [ScaffoldSlots.Drawer, ScaffoldSlots.FloatingActi
onButton, ScaffoldSlots.Toolbar, ScaffoldSlots.StatusBar, ScaffoldSlots.Body]) { | 121 for (ScaffoldSlots slot in [ScaffoldSlots.Drawer, ScaffoldSlots.FloatingActi
onButton, ScaffoldSlots.Toolbar, ScaffoldSlots.StatusBar, ScaffoldSlots.Body]) { |
122 RenderBox box = _slots[slot]; | 122 RenderBox box = _slots[slot]; |
123 if (box != null) { | 123 if (box != null) { |
124 assert(box.parentData is BoxParentData); | 124 assert(box.parentData is BoxParentData); |
125 if (new sky.Rect.fromPointAndSize(box.parentData.position, box.size).con
tains(position)) { | 125 if (new sky.Rect.fromPointAndSize(box.parentData.position, box.size).con
tains(position)) { |
126 if (box.hitTest(result, position: (position - box.parentData.position)
.toPoint())) | 126 if (box.hitTest(result, position: (position - box.parentData.position)
.toPoint())) |
127 return; | 127 return; |
128 } | 128 } |
129 } | 129 } |
130 } | 130 } |
131 } | 131 } |
132 | 132 |
133 } | 133 } |
134 | 134 |
135 class Scaffold extends RenderNodeWrapper { | 135 class Scaffold extends RenderObjectWrapper { |
136 | 136 |
137 // static final Style _style = new Style(''' | 137 // static final Style _style = new Style(''' |
138 // ${typography.typeface}; | 138 // ${typography.typeface}; |
139 // ${typography.black.body1};'''); | 139 // ${typography.black.body1};'''); |
140 | 140 |
141 Scaffold({ | 141 Scaffold({ |
142 Object key, | 142 Object key, |
143 this.toolbar, | 143 this.toolbar, |
144 this.body, | 144 this.body, |
145 this.statusbar, | 145 this.statusbar, |
146 this.drawer, | 146 this.drawer, |
147 this.floatingActionButton | 147 this.floatingActionButton |
148 }) : super( | 148 }) : super( |
149 key: key | 149 key: key |
150 ); | 150 ); |
151 | 151 |
152 final UINode toolbar; | 152 final UINode toolbar; |
153 final UINode body; | 153 final UINode body; |
154 final UINode statusbar; | 154 final UINode statusbar; |
155 final UINode drawer; | 155 final UINode drawer; |
156 final UINode floatingActionButton; | 156 final UINode floatingActionButton; |
157 | 157 |
158 RenderScaffold root; | 158 RenderScaffold root; |
159 RenderScaffold createNode() => new RenderScaffold(); | 159 RenderScaffold createNode() => new RenderScaffold(); |
160 | 160 |
161 void insert(RenderNodeWrapper child, ScaffoldSlots slot) { | 161 void insert(RenderObjectWrapper child, ScaffoldSlots slot) { |
162 root[slot] = child != null ? child.root : null; | 162 root[slot] = child != null ? child.root : null; |
163 } | 163 } |
164 | 164 |
165 void removeChild(UINode node) { | 165 void removeChild(UINode node) { |
166 assert(node != null); | 166 assert(node != null); |
167 root.remove(node.root); | 167 root.remove(node.root); |
168 super.removeChild(node); | 168 super.removeChild(node); |
169 } | 169 } |
170 | 170 |
171 void syncRenderNode(UINode old) { | 171 void syncRenderObject(UINode old) { |
172 super.syncRenderNode(old); | 172 super.syncRenderObject(old); |
173 syncChild(toolbar, old is Scaffold ? old.toolbar : null, ScaffoldSlots.Toolb
ar); | 173 syncChild(toolbar, old is Scaffold ? old.toolbar : null, ScaffoldSlots.Toolb
ar); |
174 syncChild(body, old is Scaffold ? old.body : null, ScaffoldSlots.Body); | 174 syncChild(body, old is Scaffold ? old.body : null, ScaffoldSlots.Body); |
175 syncChild(statusbar, old is Scaffold ? old.statusbar : null, ScaffoldSlots.S
tatusBar); | 175 syncChild(statusbar, old is Scaffold ? old.statusbar : null, ScaffoldSlots.S
tatusBar); |
176 syncChild(drawer, old is Scaffold ? old.drawer : null, ScaffoldSlots.Drawer)
; | 176 syncChild(drawer, old is Scaffold ? old.drawer : null, ScaffoldSlots.Drawer)
; |
177 syncChild(floatingActionButton, old is Scaffold ? old.floatingActionButton :
null, ScaffoldSlots.FloatingActionButton); | 177 syncChild(floatingActionButton, old is Scaffold ? old.floatingActionButton :
null, ScaffoldSlots.FloatingActionButton); |
178 } | 178 } |
179 | 179 |
180 } | 180 } |
OLD | NEW |