flip static method
Flips the portal to the opposite side of the child
if it does not cause the portal
to overflow out of the
viewport. Otherwise shifts the portal along the child
's edge.
Implementation
static Offset flip(Size view, FPortalChildBox child, FPortalBox portal) {
var anchor = none(view, child, portal).translate(child.offset.dx, child.offset.dy);
final viewBox = Offset.zero & view;
final portalBox = anchor & portal.size;
switch ((viewBox, portalBox)) {
case _ when portalBox.left < viewBox.left:
final flipped = _flip(child, portal, x: true);
if ((flipped & portal.size).right <= viewBox.right) {
anchor = flipped;
}
case _ when viewBox.right < portalBox.right:
final flipped = _flip(child, portal, x: true);
if (viewBox.left <= (flipped & portal.size).left) {
anchor = flipped;
}
}
switch ((viewBox, portalBox)) {
case _ when portalBox.top < viewBox.top:
final flipped = _flip(child, portal, x: false);
if ((flipped & portal.size).bottom <= viewBox.bottom) {
anchor = flipped;
}
case _ when viewBox.bottom < portalBox.bottom:
final flipped = _flip(child, portal, x: false);
if (viewBox.top <= (flipped & portal.size).top) {
anchor = flipped;
}
}
final adjustedAnchor = _along(anchor, viewBox, anchor & portal.size);
return adjustedAnchor.translate(-child.offset.dx, -child.offset.dy);
}