insertTextEntity method

void insertTextEntity()

Insert a text entity at the centre of the visible canvas — the fit rect less the chrome lift — and open the keyboard editor on it. Pose cancels the viewer zoom and the crop transform so the string sits upright in the current viewport.

Implementation

void insertTextEntity() {
  final layer = entities;
  final body = _lastBody;
  if (layer == null || body == null) return;
  final rect = _fitRect(body);
  final cropLayer = crop;
  final pose = textEntityViewPose(
    viewerCamera: viewerCamera.value,
    crop: cropLayer,
  );
  final wrap = cropLayer != null && cropLayer.hasAppliedEdits
      ? cropLayer.crop.width
      : layer.imageSize.width;
  layer.insertAndEdit(
    TextEntity(
      text: '',
      style: layer.pendingStyle,
      align: layer.pendingAlign,
      colour: layer.pendingColour,
      fontSize: layer.pendingFontSize,
      position: toSourcePoint(
        Offset(
          rect.center.dx,
          (rect.top + rect.bottom - editorKeyboardLift) / 2,
        ),
        hostCamera: camera.value,
        viewerCamera: viewerCamera.value,
        crop: crop,
      ),
      width: (wrap * 0.9).floorToDouble(),
      rotation: pose.rotation,
      scale: pose.scale,
    ),
  );
}