mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Merge pull request #1694 from Hixie/overflow-tests
RenderOverflowBox baseline logic
This commit is contained in:
commit
a52409df03
@ -37,7 +37,7 @@ RenderBox getBox(double lh) {
|
||||
padding: new EdgeDims.all(10.0),
|
||||
child: new RenderCustomPaint(
|
||||
child: paragraph,
|
||||
onPaint: (canvas, size) {
|
||||
onPaint: (PaintingCanvas canvas, Size size) {
|
||||
double baseline = paragraph.getDistanceToBaseline(TextBaseline.alphabetic);
|
||||
double w = paragraph.getMaxIntrinsicWidth(new BoxConstraints.loose(size));
|
||||
double h = paragraph.getMaxIntrinsicHeight(new BoxConstraints.loose(size));
|
||||
|
||||
@ -108,6 +108,12 @@ class RenderOverflowBox extends RenderBox with RenderObjectWithChildMixin<Render
|
||||
return constraints.constrainHeight();
|
||||
}
|
||||
|
||||
double computeDistanceToActualBaseline(TextBaseline baseline) {
|
||||
if (child != null)
|
||||
return child.getDistanceToActualBaseline(baseline);
|
||||
return super.computeDistanceToActualBaseline(baseline);
|
||||
}
|
||||
|
||||
bool get sizedByParent => true;
|
||||
|
||||
void performResize() {
|
||||
|
||||
42
sky/unit/test/rendering/overflow_test.dart
Normal file
42
sky/unit/test/rendering/overflow_test.dart
Normal file
@ -0,0 +1,42 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'rendering_tester.dart';
|
||||
|
||||
void main() {
|
||||
test("overflow should not affect baseline", () {
|
||||
RenderBox root, child, text;
|
||||
double baseline1, baseline2, height1, height2;
|
||||
|
||||
root = new RenderPositionedBox(
|
||||
child: new RenderCustomPaint(
|
||||
child: child = text = new RenderParagraph(new PlainTextSpan('Hello World')),
|
||||
onPaint: (PaintingCanvas canvas, Size size) {
|
||||
baseline1 = child.getDistanceToBaseline(TextBaseline.alphabetic);
|
||||
height1 = text.size.height;
|
||||
}
|
||||
)
|
||||
);
|
||||
layout(root, phase: EnginePhase.paint);
|
||||
|
||||
root = new RenderPositionedBox(
|
||||
child: new RenderCustomPaint(
|
||||
child: child = new RenderOverflowBox(
|
||||
child: text = new RenderParagraph(new PlainTextSpan('Hello World')),
|
||||
maxHeight: height1 / 2.0
|
||||
),
|
||||
onPaint: (PaintingCanvas canvas, Size size) {
|
||||
baseline2 = child.getDistanceToBaseline(TextBaseline.alphabetic);
|
||||
height2 = text.size.height;
|
||||
}
|
||||
)
|
||||
);
|
||||
layout(root, phase: EnginePhase.paint);
|
||||
|
||||
expect(baseline1, lessThan(height1));
|
||||
expect(height2, equals(height1 / 2.0));
|
||||
expect(baseline2, equals(baseline1));
|
||||
expect(baseline2, greaterThan(height2));
|
||||
});
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user