flex.dart 1.71 KB
Newer Older
1 2 3 4 5 6
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:sky' as sky;

7
import 'package:sky/rendering.dart';
8
import 'solid_color_box.dart';
9 10 11 12 13 14 15 16 17 18

RenderBox buildFlexExample() {
  RenderFlex flexRoot = new RenderFlex(direction: FlexDirection.vertical);

  RenderDecoratedBox root = new RenderDecoratedBox(
    decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFF000000)),
    child: flexRoot
  );

  void addFlexChildSolidColor(RenderFlex parent, sky.Color backgroundColor, { int flex: 0 }) {
19
    RenderSolidColorBox child = new RenderSolidColorBox(backgroundColor);
20 21 22 23 24 25 26 27
    parent.add(child);
    child.parentData.flex = flex;
  }

  // Yellow bar at top
  addFlexChildSolidColor(flexRoot, const sky.Color(0xFFFFFF00), flex: 1);

  // Turquoise box
28
  flexRoot.add(new RenderSolidColorBox(const sky.Color(0x7700FFFF), desiredSize: new sky.Size(100.0, 100.0)));
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

  var renderDecoratedBlock = new RenderDecoratedBox(
    decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFFFFFFFF))
  );

  flexRoot.add(new RenderPadding(padding: const EdgeDims.all(10.0), child: renderDecoratedBlock));

  var row = new RenderFlex(direction: FlexDirection.horizontal);

  // Purple and blue cells
  addFlexChildSolidColor(row, const sky.Color(0x77FF00FF), flex: 1);
  addFlexChildSolidColor(row, const sky.Color(0xFF0000FF), flex: 2);

  var decoratedRow = new RenderDecoratedBox(
    decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFF333333)),
    child: row
  );

  flexRoot.add(decoratedRow);
  decoratedRow.parentData.flex = 3;

  return root;
}

void main() {
  new SkyBinding(root: buildFlexExample());
}