[tiler] Add support for initializing tiler with template.
#comment MI4-2142
Change-Id: I32139d7d85e0cbe98128963d028292a81138c1cb
diff --git a/lib/tiler/lib/src/tiler.dart b/lib/tiler/lib/src/tiler.dart
index 83366c1..22b36f5 100644
--- a/lib/tiler/lib/src/tiler.dart
+++ b/lib/tiler/lib/src/tiler.dart
@@ -49,10 +49,17 @@
TileModel root;
/// Initializes the [TilerModel] to start layout in supplied [direction].
- TilerModel({Axis direction = Axis.horizontal}) {
- root = TileModel(
- type: direction == Axis.horizontal ? TileType.column : TileType.row,
- );
+ TilerModel({
+ Axis direction = Axis.horizontal,
+ this.root,
+ }) {
+ if (root == null) {
+ root = TileModel(
+ type: direction == Axis.horizontal ? TileType.column : TileType.row,
+ );
+ } else {
+ _initialize(root);
+ }
}
/// Returns the tile next to [tile] in the given [direction].
@@ -139,6 +146,14 @@
notifyListeners();
}
+ void _initialize(TileModel tile, [TileModel parent]) {
+ assert(tile != null);
+ tile.parent = parent;
+ for (final child in tile.tiles) {
+ _initialize(child, tile);
+ }
+ }
+
void _remove(TileModel tile) {
if (tile == root) {
return;