defaultOverflowAlgorithm function

Placement defaultOverflowAlgorithm(
  1. OverflowEdge edge,
  2. Placement input
)

Implementation

Placement defaultOverflowAlgorithm(
  OverflowEdge edge,
  Placement input,
) {
  bool outTop = edge.top;
  bool outBottom = edge.bottom;
  bool outLeft = edge.left;
  bool outRight = edge.right;

  if (edge.noOverflow) return input;

  if (!outBottom && input.isBottom) {
    return Placement.bottom;
  }

  if (!outTop && input.isTop) {
    return Placement.top;
  }

  if (!outLeft && input.isLeft) {
    return Placement.left;
  }

  if (!outRight && input.isRight) {
    return Placement.right;
  }

  Placement effectPlacement = input;

  Placement shiftToVertical() {
    if (outTop) return Placement.bottom;
    return Placement.top;
  }

  if (outLeft && outRight) {
    return shiftToVertical();
  }

  /// TODO: ::边界响应策略:: 可以将转换策略作为函数参数,使用者来自定义。
  // if(placement.isHorizontal&&(outTop||outBottom)){
  //   return shiftToVertical();
  // }
  switch (input) {
    case Placement.left:
      if (outLeft) return Placement.right;
      if (outBottom) return Placement.leftEnd;
      if (outTop) return Placement.leftStart;
      break;
    case Placement.leftStart:
      if (outBottom) return Placement.leftEnd;
      if (outLeft) return Placement.rightStart;
      break;
    case Placement.leftEnd:
      if (outTop) return Placement.leftStart;
      if (outLeft) return Placement.rightEnd;
      break;
    case Placement.right:
      if (outRight) return Placement.left;
      if (outBottom) return Placement.rightEnd;
      if (outTop) return Placement.rightStart;

      break;
    case Placement.rightStart:
      if (outBottom) return Placement.rightEnd;
      if (outRight) return Placement.leftStart;
      break;
    case Placement.rightEnd:
      if (outTop) return Placement.rightStart;
      if (outRight) return Placement.leftEnd;
      break;
    default:
      if (outBottom && input.isBottom || outTop && input.isTop) {
        return input.shift;
      }
  }
  return effectPlacement;
}