highlight method

Widget highlight(
  1. ComponentData componentData,
  2. Color color
)

Implementation

Widget highlight(ComponentData componentData, Color color) {
  List<ComponentData> childPorts = [];
  canvasReader.model.getAllComponents().forEach((id, comp) {
    if (comp.parentId == componentData.id) {
      childPorts.add(comp);
    }
  });

  Rect combinedRect = Rect.fromPoints(
    componentData.position,
    componentData.position + componentData.size.bottomRight(Offset.zero),
  );
  for (var port in childPorts) {
    Rect portRect = Rect.fromPoints(
        port.position, port.position + port.size.bottomRight(Offset.zero));
    combinedRect = combinedRect.expandToInclude(portRect);
  }

  // Ajuster la position et la taille du contour
  Offset highlightPosition = combinedRect.topLeft - const Offset(2, 2);
  double width = combinedRect.width + 4;
  double height = combinedRect.height + 4;

  return Positioned(
    left: canvasReader.state.toCanvasCoordinates(highlightPosition).dx,
    top: canvasReader.state.toCanvasCoordinates(highlightPosition).dy,
    child: CustomPaint(
      painter: ComponentHighlightPainter(
        width: width * canvasReader.state.scale,
        height: height * canvasReader.state.scale,
        color: color,
      ),
    ),
  );
}