rendering_tester.dart 1.29 KB
Newer Older
1
import 'package:flutter/rendering.dart';
2 3 4 5

const Size _kTestViewSize = const Size(800.0, 600.0);

class TestRenderView extends RenderView {
Hixie's avatar
Hixie committed
6
  TestRenderView() {
7 8 9
    attach();
    rootConstraints = new ViewConstraints(size: _kTestViewSize);
    scheduleInitialLayout();
10
    scheduleInitialPaint(new TransformLayer(transform: new Matrix4.identity()));
11
  }
12 13 14 15 16 17 18 19
}

enum EnginePhase {
  layout,
  paint,
  composite
}

Hixie's avatar
Hixie committed
20 21
RenderView _renderView;
RenderView get renderView => _renderView;
22

Hixie's avatar
Hixie committed
23 24 25 26 27 28 29 30
void layout(RenderBox box, { BoxConstraints constraints, EnginePhase phase: EnginePhase.layout }) {
  assert(box != null); // if you want to just repump the last box, call pumpFrame().

  if (renderView == null)
    _renderView = new TestRenderView();

  if (renderView.child != null)
    renderView.child = null;
31 32 33 34 35 36 37 38 39 40

  if (constraints != null) {
    box = new RenderPositionedBox(
      child: new RenderConstrainedBox(
        additionalConstraints: constraints,
        child: box
      )
    );
  }

Hixie's avatar
Hixie committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54
  renderView.child = box;

  pumpFrame(phase: phase);
}

void pumpFrame({ EnginePhase phase: EnginePhase.layout }) {
  RenderObject.flushLayout();
  if (phase == EnginePhase.layout)
    return;
  renderView.updateCompositingBits();
  RenderObject.flushPaint();
  if (phase == EnginePhase.paint)
    return;
  renderView.compositeFrame();
55
}