expressiveUncontainedKeylines function

ExpressiveCarouselKeylines expressiveUncontainedKeylines({
  1. required double mainAxisSize,
  2. required double itemSize,
  3. required double itemSpacing,
  4. required double anchorSize,
  5. double mediumLargeItemDiffThreshold = CarouselBehavior.mediumLargeItemDiffThreshold,
})

Compose's uncontainedKeylineList: items of itemSize from the start, the last one cut off at the end.

Implementation

ExpressiveCarouselKeylines expressiveUncontainedKeylines({
  required double mainAxisSize,
  required double itemSize,
  required double itemSpacing,
  required double anchorSize,
  double mediumLargeItemDiffThreshold =
      CarouselBehavior.mediumLargeItemDiffThreshold,
}) {
  if (mainAxisSize == 0 || itemSize == 0) {
    return ExpressiveCarouselKeylines.empty;
  }
  final largeSize = math.min(itemSize + itemSpacing, mainAxisSize);
  final largeCount = math.max(1, (mainAxisSize / largeSize).floor());
  final remaining = mainAxisSize - largeCount * largeSize;
  final mediumCount = remaining > 0 ? 1 : 0;
  // calculateMediumChildSize: the cut-off item shows a third of itself
  // cut off, or a fifth once that would near the large size (Compose).
  var mediumSize = math.max(remaining * 1.5, anchorSize);
  final threshold = largeSize * mediumLargeItemDiffThreshold;
  if (mediumSize > threshold) {
    mediumSize = math.min(math.max(threshold, remaining * 1.2), largeSize);
  }
  final arrangement = _Arrangement(
    0,
    0,
    0,
    mediumSize,
    mediumCount,
    largeSize,
    largeCount,
  );
  final xSmall = math.min(anchorSize, itemSize);
  final leftAnchor = math.max(xSmall, mediumSize * 0.5);
  return _leftAligned(
    mainAxisSize,
    itemSpacing,
    leftAnchor,
    anchorSize,
    arrangement,
  );
}