flip static method

Offset flip(
  1. Size view,
  2. FPortalTarget target,
  3. FPortalFollower follower
)

Flips the follower to the opposite side of the target if it does not cause the follower to overflow out of the viewport. Otherwise shifts the follower along the target's edge.

Implementation

static Offset flip(Size view, FPortalTarget target, FPortalFollower follower) {
  var anchor = none(view, target, follower).translate(target.offset.dx, target.offset.dy);

  final viewBox = Offset.zero & view;
  final followerBox = anchor & follower.size;

  switch ((viewBox, followerBox)) {
    case _ when followerBox.left < viewBox.left:
      final flipped = _flip(target, follower, x: true);
      if ((flipped & follower.size).right <= viewBox.right) {
        anchor = flipped;
      }

    case _ when viewBox.right < followerBox.right:
      final flipped = _flip(target, follower, x: true);
      if (viewBox.left <= (flipped & follower.size).left) {
        anchor = flipped;
      }
  }

  switch ((viewBox, followerBox)) {
    case _ when followerBox.top < viewBox.top:
      final flipped = _flip(target, follower, x: false);
      if ((flipped & follower.size).bottom <= viewBox.bottom) {
        anchor = flipped;
      }

    case _ when viewBox.bottom < followerBox.bottom:
      final flipped = _flip(target, follower, x: false);
      if (viewBox.top <= (flipped & follower.size).top) {
        anchor = flipped;
      }
  }

  final foo = _along(anchor, viewBox, anchor & follower.size);
  return foo.translate(-target.offset.dx, -target.offset.dy);
}