OLD | NEW |
| (Empty) |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 import 'package:immi/dart/immi.dart'; | |
6 | |
7 // Export generated code for nodes in drawer.immi | |
8 import 'package:immi/dart/drawer.dart'; | |
9 export 'package:immi/dart/drawer.dart'; | |
10 | |
11 class Drawer { | |
12 var left; | |
13 var _center; | |
14 var right; | |
15 | |
16 bool _leftVisible = false; | |
17 bool _rightVisible = false; | |
18 | |
19 Drawer(this._center, {left, right}) { | |
20 this.left = left; | |
21 this.right = right; | |
22 } | |
23 | |
24 get center => _center; | |
25 | |
26 set center(presenter) { | |
27 _center = presenter; | |
28 _leftVisible = false; | |
29 _rightVisible = false; | |
30 } | |
31 | |
32 DrawerNode present(Node previous) { | |
33 Node previousLeft = new EmptyPaneNode(); | |
34 Node previousCenter = null; | |
35 Node previousRight = new EmptyPaneNode(); | |
36 if (previous is DrawerNode) { | |
37 previousLeft = previous.left; | |
38 previousCenter = previous.center; | |
39 previousRight = previous.right; | |
40 } | |
41 return new DrawerNode( | |
42 left: _presentPane(left, _leftVisible, previousLeft, 'left'), | |
43 center: center.present(previousCenter), | |
44 right: _presentPane(right, _rightVisible, previousRight, 'right'), | |
45 leftVisible: _leftVisible, | |
46 rightVisible: _rightVisible, | |
47 toggleLeft: _toggleLeft, | |
48 toggleRight: _toggleRight); | |
49 } | |
50 | |
51 Node _presentPane(presenter, bool visible, Node previous, String pane) { | |
52 if (presenter == null) return new EmptyPaneNode(); | |
53 if (!visible) return previous; | |
54 return presenter.present(previous); | |
55 } | |
56 | |
57 void _toggleLeft() { | |
58 _leftVisible = !_leftVisible; | |
59 if (_leftVisible && _rightVisible) _rightVisible = false; | |
60 } | |
61 | |
62 void _toggleRight() { | |
63 _rightVisible = !_rightVisible; | |
64 if (_leftVisible && _rightVisible) _leftVisible = false; | |
65 } | |
66 } | |
OLD | NEW |