resolveOffset static method

Offset resolveOffset(
  1. Paragraph paragraph,
  2. DrawableTextAnchorPosition anchor,
  3. Offset offset
)

Determines the correct location for an Offset given laid-out paragraph and a DrawableTextPosition.

Implementation

static Offset resolveOffset(
  Paragraph paragraph,
  DrawableTextAnchorPosition anchor,
  Offset offset,
) {
  assert(paragraph != null); // ignore: unnecessary_null_comparison
  assert(anchor != null); // ignore: unnecessary_null_comparison
  assert(offset != null); // ignore: unnecessary_null_comparison
  switch (anchor) {
    case DrawableTextAnchorPosition.middle:
      return Offset(
        offset.dx - paragraph.minIntrinsicWidth / 2,
        offset.dy - paragraph.alphabeticBaseline,
      );
    case DrawableTextAnchorPosition.end:
      return Offset(
        offset.dx - paragraph.minIntrinsicWidth,
        offset.dy - paragraph.alphabeticBaseline,
      );
    case DrawableTextAnchorPosition.start:
      return Offset(
        offset.dx,
        offset.dy - paragraph.alphabeticBaseline,
      );
    default:
      return offset;
  }
}