skeletonFromTextRect method

Skeleton? skeletonFromTextRect(
  1. TextRect textRect,
  2. double leftPaddingElement,
  3. double topPaddingElement,
  4. Rect mainRect,
  5. double lineAscent,
  6. Rect elementRect,
)

Implementation

Skeleton? skeletonFromTextRect(
  TextRect textRect,
  double leftPaddingElement,
  double topPaddingElement,
  Rect mainRect,
  double lineAscent,
  Rect elementRect,
) {
  final topValue = textRect.topPosition + topPaddingElement + lineAscent;
  final leftValue = leftPaddingElement + textRect.leftPosition + textRect.lineLeft;

  final Rect rect = Rect.fromLTRB(
    leftValue,
    topValue + textRect.lineDescent - textRect.lineAscent,
    leftValue + textRect.lineWidth,
    topValue + textRect.lineDescent,
  );

  final Rect intersectedRect = rect.intersect(mainRect).intersect(elementRect);

  if (intersectedRect.height < 0.0) {
    return null;
  }

  return Skeleton(
    rect: intersectedRect,
    color: textRect.color!,
    opacity: textRect.color!.alpha / 0xFF,
    isText: !textRect.isIcon,
  );
}