mirror of
https://github.com/flutter/flutter
synced 2024-07-04 17:38:56 +00:00
Fix the RenderFlex.computeDryBaseline implementation to match computeDistanceToActualBaseline (#149062)
Per Hixie's comment [here](https://github.com/flutter/flutter/issues/145739#issuecomment-2128006146), keep the current behavior
This commit is contained in:
parent
c109b3cb02
commit
0214afb40b
|
@ -308,6 +308,8 @@ enum CrossAxisAlignment {
|
||||||
/// See also:
|
/// See also:
|
||||||
///
|
///
|
||||||
/// * [RenderBox.getDistanceToBaseline], which defines the baseline of a box.
|
/// * [RenderBox.getDistanceToBaseline], which defines the baseline of a box.
|
||||||
|
/// * [IgnoreBaseline], which can be used to ignore a child for the purpose of
|
||||||
|
/// baseline alignment.
|
||||||
baseline;
|
baseline;
|
||||||
|
|
||||||
double _getChildCrossAxisOffset(double freeSpace, bool flipped) {
|
double _getChildCrossAxisOffset(double freeSpace, bool flipped) {
|
||||||
|
@ -821,13 +823,17 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
|
||||||
final double freeSpace = math.max(0.0, sizes.mainAxisFreeSpace);
|
final double freeSpace = math.max(0.0, sizes.mainAxisFreeSpace);
|
||||||
final bool flipMainAxis = _flipMainAxis;
|
final bool flipMainAxis = _flipMainAxis;
|
||||||
final (double leadingSpaceY, double spaceBetween) = mainAxisAlignment._distributeSpace(freeSpace, childCount, flipMainAxis);
|
final (double leadingSpaceY, double spaceBetween) = mainAxisAlignment._distributeSpace(freeSpace, childCount, flipMainAxis);
|
||||||
double y = leadingSpaceY;
|
double y = flipMainAxis
|
||||||
final (_NextChild nextChild, RenderBox? topLeftChild) = flipMainAxis ? (childBefore, lastChild) : (childAfter, firstChild);
|
? leadingSpaceY + (childCount - 1) * spaceBetween + (sizes.axisSize.mainAxisExtent - sizes.mainAxisFreeSpace)
|
||||||
for (RenderBox? child = topLeftChild; child != null; child = nextChild(child)) {
|
: leadingSpaceY;
|
||||||
|
final double directionUnit = flipMainAxis ? -1.0 : 1.0;
|
||||||
|
for (RenderBox? child = firstChild; baselineOffset == BaselineOffset.noBaseline && child != null; child = childAfter(child)) {
|
||||||
final BoxConstraints childConstraints = constraintsForChild(child);
|
final BoxConstraints childConstraints = constraintsForChild(child);
|
||||||
final Size childSize = child.getDryLayout(childConstraints);
|
final Size childSize = child.getDryLayout(childConstraints);
|
||||||
baselineOffset = baselineOffset.minOf(BaselineOffset(child.getDryBaseline(childConstraints, baseline)) + y);
|
final double? childBaselineOffset = child.getDryBaseline(childConstraints, baseline);
|
||||||
y += spaceBetween + childSize.height;
|
final double additionalY = flipMainAxis ? - childSize.height : 0.0;
|
||||||
|
baselineOffset = BaselineOffset(childBaselineOffset) + y + additionalY;
|
||||||
|
y += directionUnit * (spaceBetween + childSize.height);
|
||||||
}
|
}
|
||||||
case Axis.horizontal:
|
case Axis.horizontal:
|
||||||
final bool flipCrossAxis = _flipCrossAxis;
|
final bool flipCrossAxis = _flipCrossAxis;
|
||||||
|
|
|
@ -648,6 +648,53 @@ void main() {
|
||||||
expect(box2.localToGlobal(Offset.zero).dy, 0.0);
|
expect(box2.localToGlobal(Offset.zero).dy, 0.0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Vertical Flex Baseline', () {
|
||||||
|
const BoxConstraints square = BoxConstraints.tightFor(width: 100.0, height: 100.0);
|
||||||
|
final RenderConstrainedBox box1 = RenderConstrainedBox(
|
||||||
|
additionalConstraints: square,
|
||||||
|
child: RenderFlowBaselineTestBox()
|
||||||
|
..gridCount = 1
|
||||||
|
..baselinePlacer = (double height) => 10,
|
||||||
|
);
|
||||||
|
final RenderConstrainedBox box2 = RenderConstrainedBox(
|
||||||
|
additionalConstraints: square,
|
||||||
|
child: RenderFlowBaselineTestBox()
|
||||||
|
..gridCount = 1
|
||||||
|
..baselinePlacer = (double height) => 10,
|
||||||
|
);
|
||||||
|
RenderConstrainedBox filler() => RenderConstrainedBox(additionalConstraints: square);
|
||||||
|
final RenderFlex flex = RenderFlex(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
children: <RenderBox>[
|
||||||
|
filler(),
|
||||||
|
box1,
|
||||||
|
filler(),
|
||||||
|
box2,
|
||||||
|
filler(),
|
||||||
|
],
|
||||||
|
direction: Axis.vertical,
|
||||||
|
);
|
||||||
|
layout(flex, phase: EnginePhase.paint);
|
||||||
|
final double flexHeight = flex.size.height;
|
||||||
|
|
||||||
|
// We can't call the getDistanceToBaseline method directly. Check the dry
|
||||||
|
// baseline instead, and in debug mode there are asserts that verify
|
||||||
|
// the two methods return the same results.
|
||||||
|
expect(flex.getDryBaseline(flex.constraints, TextBaseline.alphabetic), 100 + 10);
|
||||||
|
|
||||||
|
flex.mainAxisAlignment = MainAxisAlignment.end;
|
||||||
|
pumpFrame(phase: EnginePhase.paint);
|
||||||
|
expect(flex.getDryBaseline(flex.constraints, TextBaseline.alphabetic), flexHeight - 400 + 10);
|
||||||
|
|
||||||
|
flex.verticalDirection = VerticalDirection.up;
|
||||||
|
pumpFrame(phase: EnginePhase.paint);
|
||||||
|
expect(flex.getDryBaseline(flex.constraints, TextBaseline.alphabetic), 300 + 10);
|
||||||
|
|
||||||
|
flex.mainAxisAlignment = MainAxisAlignment.start;
|
||||||
|
pumpFrame(phase: EnginePhase.paint);
|
||||||
|
expect(flex.getDryBaseline(flex.constraints, TextBaseline.alphabetic), flexHeight - 200 + 10);
|
||||||
|
});
|
||||||
|
|
||||||
group('Intrinsics', () {
|
group('Intrinsics', () {
|
||||||
test('main axis intrinsics with RenderAspectRatio 1', () {
|
test('main axis intrinsics with RenderAspectRatio 1', () {
|
||||||
const BoxConstraints square = BoxConstraints.tightFor(width: 100.0, height: 100.0);
|
const BoxConstraints square = BoxConstraints.tightFor(width: 100.0, height: 100.0);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user