paintHoldFill function

void paintHoldFill(
  1. Canvas canvas,
  2. Rect rect,
  3. KeyFaceMotion motion,
  4. KeyFaceSpec spec, {
  5. required Path clip,
})

Paints the long-press progress (motion brief ยง4.4) clipped to clip (in the canvas' current space).

Families with a pressed state layer get a radial fill in the contrast-safe state-layer colour at exactly pressedOverlayOpacity (never more, so the label keeps its floor). Families without a tint (NeoPOP: "no tint") get a label-coloured bar sweeping along the bottom edge instead. Under Reduce Motion both fade in place instead of growing.

Implementation

void paintHoldFill(
  Canvas canvas,
  Rect rect,
  KeyFaceMotion motion,
  KeyFaceSpec spec, {
  required Path clip,
}) {
  final fraction = motion.holdFill;
  final tint = motion.tint.value.clamp(0.0, 1.0);
  if (fraction <= 0 || tint <= 0) return;
  final rm = spec.reduceMotion;
  canvas
    ..save()
    ..clipPath(clip);
  if (spec.pressedOverlayOpacity > 0) {
    final reach = math.sqrt(
      rect.width * rect.width / 4 + rect.height * rect.height / 4,
    );
    final alpha = spec.pressedOverlayOpacity * tint * (rm ? fraction : 1);
    canvas.drawCircle(
      rect.center,
      rm ? reach : reach * fraction,
      Paint()
        ..color = stateLayerColor(
          spec.style.fill,
          spec.style.label,
        ).withValues(alpha: alpha.clamp(0.0, 1.0)),
    );
  } else {
    final h = rect.height * 0.06;
    final width = rm ? rect.width : rect.width * fraction;
    canvas.drawRect(
      Rect.fromLTWH(rect.left, rect.bottom - h, width, h),
      Paint()
        ..color = spec.style.label.withValues(
          alpha: (rm ? fraction : 1) * tint,
        ),
    );
  }
  canvas.restore();
}