baseline.dart 2.28 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 9 10

RenderBox getBox(double lh) {
  RenderParagraph paragraph = new RenderParagraph(
Eric Seidel's avatar
Eric Seidel committed
11
    new StyledTextSpan(
12 13 14 15
      new TextStyle(
        color: const Color(0xFF0000A0)
      ),
      [
Eric Seidel's avatar
Eric Seidel committed
16 17
        new PlainTextSpan('test'),
        new StyledTextSpan(
18 19 20 21 22
          new TextStyle(
            fontFamily: 'serif',
            fontSize: 50.0,
            height: lh
          ),
Eric Seidel's avatar
Eric Seidel committed
23
          [new PlainTextSpan('مرحبا Hello')]
24 25 26 27 28 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
        )
      ]
    )
  );
  return new RenderPadding(
    padding: new EdgeDims.all(10.0),
    child: new RenderConstrainedBox(
      additionalConstraints: new BoxConstraints.tightFor(height: 200.0),
      child: new RenderDecoratedBox(
        decoration: new BoxDecoration(
          backgroundColor: const Color(0xFFFFFFFF)
        ),
        child: new RenderPadding(
          padding: new EdgeDims.all(10.0),
          child: new RenderCustomPaint(
            child: paragraph,
            callback: (canvas, size) {
              double baseline = paragraph.getDistanceToBaseline(TextBaseline.alphabetic);
              double w = paragraph.getMaxIntrinsicWidth(new BoxConstraints.loose(size));
              double h = paragraph.getMaxIntrinsicHeight(new BoxConstraints.loose(size));
              Path path = new Path();
              path.moveTo(0.0, 0.0);
              path.lineTo(w, 0.0);
              path.moveTo(0.0, baseline);
              path.lineTo(w, baseline);
              path.moveTo(0.0, h);
              path.lineTo(w, h);
              Paint paint = new Paint();
              paint.color = const Color(0xFFFF9000);
              paint.setStyle(sky.PaintingStyle.stroke);
              paint.strokeWidth = 3.0;
55
              canvas.drawPath(path, paint);
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
            }
          )
        )
      )
    )
  );
}

void main() {
  RenderBox root = new RenderFlex(children: [
      new RenderConstrainedBox(
        additionalConstraints: new BoxConstraints.tightFor(height: 50.0)
      ),
      getBox(1.0),
      getBox(null),
    ],
    direction: FlexDirection.vertical,
    alignItems: FlexAlignItems.stretch
  );
75
  new FlutterBinding(root: root);
76
}