furthestEdge function
The furthest edge on axis -- the lowest bottom, or the rightmost right
-- of anything laid out under child, in child's own coordinates. The
transform is carried down the tree rather than asked of each box, which
walks to the root every time. Read during layout, it must be asked from
a layout callback (invokeLayoutCallback): only a box's parent may read
its size there otherwise.
AN ALIGN UNDER A FRACTIONALTRANSLATION IS NO BOX OF THE PAGE. It is how
left: 68%; top: 28% stands an absolute box in its containing block: the
Align is as big as the block so that the fractions are of the block, and
the translation carries all of it, empty, that far over and down. Only what
it places counts (css-overflow-3 2.2), or a map's labels at the foot of a
page ran the document 206 past its end with nothing on it.
A CLIP THAT LEAVES THE FAR EDGE OPEN is entered, and what is under it
counts out to the clip's own edge: a box that clips on one axis
(overflow-x: clip beside a visible, css-overflow-3 3.1) cuts only
across, as a ClipRect whose rectangle runs far past the box above and
below (InsetClip), and the document scrolls on down to what hangs
out of it. A news site's body is one window tall and clipped across
over 7000px of page. A clip of the box itself, or any other shape,
still ends the walk, and so does a scroller: what is inside it is
scrolled to inside it (css-overflow-3 2.2) -- all but a ScrollBox's
port across axis, which scrolls the other way, clips nothing and
holds the content of a box that scrolls both ways.
Implementation
double furthestEdge(RenderBox child, Axis axis) {
final down = axis == Axis.vertical;
var far = 0.0;
void visit(RenderObject o, Matrix4 m, double cap) {
if (o is RenderFixedLayer) return;
if (o is RenderBox) {
if (!o.hasSize) return;
if (o is! RenderPositionedBox || o.parent is! RenderFractionalTranslation) {
final r = MatrixUtils.transformRect(m, Offset.zero & o.size);
final edge = math.min(down ? r.bottom : r.right, cap);
if (edge > far) far = edge;
}
if (o is RenderClipRect) {
final clip = o.clipper?.getClip(o.size);
if (clip == null || (down ? clip.bottom <= o.size.height : clip.right <= o.size.width)) return;
final at = MatrixUtils.transformRect(m, clip);
cap = math.min(cap, down ? at.bottom : at.right);
} else if (o is RenderScrollPort && o.axis != axis) {
// Enter it.
} else if (o is RenderClipRRect || o is RenderClipPath || o is RenderClipOval || o is RenderAbstractViewport) {
return;
}
}
o.visitChildren((c) {
final cm = m.clone();
o.applyPaintTransform(c, cm);
visit(c, cm, cap);
});
}
visit(child, Matrix4.identity(), double.infinity);
return far;
}