layout static method

  1. @visibleForTesting
({Rect endRect, HarborPanesMode mode, Rect startRect}) layout({
  1. required Size size,
  2. required List<Rect> hinges,
  3. required TextDirection direction,
  4. double minWideWidth = 840.0,
  5. double minTallHeight = double.infinity,
  6. double startFraction = 0.5,
})

The layout HarborPanes would choose for size, with hinges (the bounds of the hinges and folds its policy keeps off) in the same coordinates.

Implementation

@visibleForTesting
static ({HarborPanesMode mode, Rect startRect, Rect endRect}) layout({
  required final Size size,
  required final List<Rect> hinges,
  required final TextDirection direction,
  final double minWideWidth = 840.0,
  final double minTallHeight = double.infinity,
  final double startFraction = 0.5,
}) {
  final Rect all = Offset.zero & size;
  for (final Rect hinge in hinges) {
    final bool vertical =
        hinge.top <= 0.5 && hinge.bottom >= size.height - 0.5 && hinge.left > 0 && hinge.right < size.width;
    final bool horizontal =
        hinge.left <= 0.5 && hinge.right >= size.width - 0.5 && hinge.top > 0 && hinge.bottom < size.height;
    if (vertical) {
      final Rect left = Rect.fromLTRB(0, 0, hinge.left, size.height);
      final Rect right = Rect.fromLTRB(hinge.right, 0, size.width, size.height);
      return direction == TextDirection.ltr
          ? (mode: HarborPanesMode.wide, startRect: left, endRect: right)
          : (mode: HarborPanesMode.wide, startRect: right, endRect: left);
    }
    if (horizontal) {
      return (
        mode: HarborPanesMode.tall,
        startRect: Rect.fromLTRB(0, 0, size.width, hinge.top),
        endRect: Rect.fromLTRB(0, hinge.bottom, size.width, size.height),
      );
    }
  }
  if (size.width >= minWideWidth) {
    final double split = size.width * (direction == TextDirection.ltr ? startFraction : 1 - startFraction);
    final Rect left = Rect.fromLTRB(0, 0, split, size.height);
    final Rect right = Rect.fromLTRB(split, 0, size.width, size.height);
    return direction == TextDirection.ltr
        ? (mode: HarborPanesMode.wide, startRect: left, endRect: right)
        : (mode: HarborPanesMode.wide, startRect: right, endRect: left);
  }
  if (size.height >= minTallHeight) {
    final double split = size.height * startFraction;
    return (
      mode: HarborPanesMode.tall,
      startRect: Rect.fromLTRB(0, 0, size.width, split),
      endRect: Rect.fromLTRB(0, split, size.width, size.height),
    );
  }
  return (mode: HarborPanesMode.single, startRect: all, endRect: all);
}