paintTemporaryConnection method

void paintTemporaryConnection(
  1. Canvas canvas,
  2. Offset startPoint,
  3. Offset currentPoint, {
  4. Port? sourcePort,
  5. Port? targetPort,
  6. Rect? sourceNodeBounds,
  7. Rect? targetNodeBounds,
  8. double? animationValue,
})

Implementation

void paintTemporaryConnection(
  Canvas canvas,
  Offset startPoint,
  Offset currentPoint, {
  Port? sourcePort,
  Port? targetPort,
  Rect? sourceNodeBounds,
  Rect? targetNodeBounds,
  double? animationValue,
}) {
  final connectionTheme = theme.temporaryConnectionTheme;

  // Always use the full connection style machinery for consistent appearance
  // Calculate source endpoint positions (from the port we started dragging from)
  final ({Offset endpointPos, Offset linePos}) source;
  if (sourcePort != null) {
    // Use proper endpoint calculation to account for endpoint marker size and gap
    final startEndpoint = connectionTheme.startPoint;
    final startPointSize = startEndpoint.shape is NoneMarkerShape
        ? Size.zero
        : startEndpoint.size;
    source = EndpointPositionCalculator.calculatePortConnectionPoints(
      startPoint,
      sourcePort.position,
      startPointSize,
      gap: connectionTheme.startGap,
    );
  } else {
    source = (endpointPos: startPoint, linePos: startPoint);
  }

  // Calculate target endpoint positions (where we're dragging to)
  final ({Offset endpointPos, Offset linePos}) target;
  if (targetPort != null) {
    // Use proper endpoint calculation to account for endpoint marker size and gap
    // This ensures the connection snaps to the correct attachment point
    final endEndpoint = connectionTheme.endPoint;
    final endPointSize = endEndpoint.shape is NoneMarkerShape
        ? Size.zero
        : endEndpoint.size;
    target = EndpointPositionCalculator.calculatePortConnectionPoints(
      currentPoint,
      targetPort.position,
      endPointSize,
      gap: connectionTheme.endGap,
    );
  } else {
    target = (endpointPos: currentPoint, linePos: currentPoint);
  }

  _drawConnectionWithEndpoints(
    canvas,
    null,
    source: source,
    target: target,
    sourcePort: sourcePort,
    targetPort: targetPort,
    sourceNodeBounds: sourceNodeBounds,
    targetNodeBounds: targetNodeBounds,
    isSelected: false,
    isTemporary: true,
    drawTargetEndpoint: targetPort != null,
    animationValue: animationValue,
  );
}