updateGroupResize method

void updateGroupResize(
  1. Offset delta
)

Updates the group size during a resize operation.

Implementation

void updateGroupResize(Offset delta) {
  final groupId = _resizingGroupId.value;
  final handlePosition = _resizeHandlePosition.value;
  if (groupId == null || handlePosition == null) return;

  final annotation = _annotations[groupId];
  if (annotation is! GroupAnnotation) return;

  final startPos = _resizeStartPosition;
  final startSize = _resizeStartSize;
  if (startPos == null || startSize == null) return;

  runInAction(() {
    // Calculate new position and size based on handle being dragged
    var newX = annotation.position.dx;
    var newY = annotation.position.dy;
    var newWidth = annotation.size.width;
    var newHeight = annotation.size.height;

    switch (handlePosition) {
      case ResizeHandlePosition.topLeft:
        newX += delta.dx;
        newY += delta.dy;
        newWidth -= delta.dx;
        newHeight -= delta.dy;
      case ResizeHandlePosition.topCenter:
        newY += delta.dy;
        newHeight -= delta.dy;
      case ResizeHandlePosition.topRight:
        newY += delta.dy;
        newWidth += delta.dx;
        newHeight -= delta.dy;
      case ResizeHandlePosition.centerLeft:
        newX += delta.dx;
        newWidth -= delta.dx;
      case ResizeHandlePosition.centerRight:
        newWidth += delta.dx;
      case ResizeHandlePosition.bottomLeft:
        newX += delta.dx;
        newWidth -= delta.dx;
        newHeight += delta.dy;
      case ResizeHandlePosition.bottomCenter:
        newHeight += delta.dy;
      case ResizeHandlePosition.bottomRight:
        newWidth += delta.dx;
        newHeight += delta.dy;
    }

    // Apply minimum size constraints
    const minWidth = 100.0;
    const minHeight = 60.0;

    // If new size would be below minimum, adjust position back
    if (newWidth < minWidth) {
      if (handlePosition == ResizeHandlePosition.topLeft ||
          handlePosition == ResizeHandlePosition.centerLeft ||
          handlePosition == ResizeHandlePosition.bottomLeft) {
        newX = annotation.position.dx + annotation.size.width - minWidth;
      }
      newWidth = minWidth;
    }

    if (newHeight < minHeight) {
      if (handlePosition == ResizeHandlePosition.topLeft ||
          handlePosition == ResizeHandlePosition.topCenter ||
          handlePosition == ResizeHandlePosition.topRight) {
        newY = annotation.position.dy + annotation.size.height - minHeight;
      }
      newHeight = minHeight;
    }

    // Update position if changed
    final newPosition = Offset(newX, newY);
    if (newPosition != annotation.position) {
      annotation.position = newPosition;
      annotation.visualPosition = _parentController.config
          .snapAnnotationsToGridIfEnabled(newPosition);
    }

    // Update size
    annotation.setSize(Size(newWidth, newHeight));

    // Mark annotation dirty
    _parentController.internalMarkAnnotationDirty(groupId);
  });
}