axisStateScale function

ScaleAxisState axisStateScale(
  1. double signedAmount,
  2. double currentWidth,
  3. double baseWidth,
  4. ShrinkBounds? shrink,
  5. ExpandBounds? expand,
)

Computes the scale-axis state given the current width and motion direction.

signedAmount = direction-bearing scalar (e.g., width-velocity or width delta). currentWidth = the rect's width now. baseWidth = scale-1.0 rest width. shrink / expand carry the configured min/maxScale.

Implementation

ScaleAxisState axisStateScale(
  double signedAmount,
  double currentWidth,
  double baseWidth,
  ShrinkBounds? shrink,
  ExpandBounds? expand,
) {
  final inExpand = currentWidth > baseWidth;
  final ScaleSide activeSide = inExpand ? .expand : .shrink;
  final shrinkLow =
      shrink?.minScale != null ? shrink!.minScale! * baseWidth : double.negativeInfinity;
  final expandHigh =
      expand?.maxScale != null ? expand!.maxScale! * baseWidth : double.infinity;
  final pastDisplay = inExpand ? currentWidth > expandHigh : currentWidth < shrinkLow;
  // Progress: in-display = distance from base normalized to half-range; past = depth past edge.
  final progress = pastDisplay
      ? (inExpand
              ? (currentWidth - expandHigh) / (expandHigh - baseWidth).abs()
              : (shrinkLow - currentWidth) / (baseWidth - shrinkLow).abs())
          .clamp(0.0, 1.0)
      : (inExpand
              ? (currentWidth - baseWidth) / (expandHigh - baseWidth).abs()
              : (baseWidth - currentWidth) / (baseWidth - shrinkLow).abs())
          .clamp(0.0, 1.0);
  // extending = motion increases the magnitude (further from base).
  final extending = (inExpand && signedAmount > 0) || (!inExpand && signedAmount < 0);
  return (
    activeSide: activeSide,
    extending: extending,
    pastDisplay: pastDisplay,
    progress: progress.isNaN ? 0.0 : progress,
  );
}