TextSelectionToolbarAnchors.fromSelection constructor

TextSelectionToolbarAnchors.fromSelection({
  1. required RenderBox renderBox,
  2. required double startGlyphHeight,
  3. required double endGlyphHeight,
  4. required List<TextSelectionPoint> selectionEndpoints,
})

Creates an instance of TextSelectionToolbarAnchors for some selection.

Implementation

factory TextSelectionToolbarAnchors.fromSelection({
  required RenderBox renderBox,
  required double startGlyphHeight,
  required double endGlyphHeight,
  required List<TextSelectionPoint> selectionEndpoints,
}) {
  final Rect selectionRect = getSelectionRect(
    renderBox,
    startGlyphHeight,
    endGlyphHeight,
    selectionEndpoints,
  );
  if (selectionRect == Rect.zero) {
    return const TextSelectionToolbarAnchors(primaryAnchor: Offset.zero);
  }

  final Rect editingRegion = _getEditingRegion(renderBox);
  return TextSelectionToolbarAnchors(
    primaryAnchor: Offset(
      selectionRect.left + selectionRect.width / 2,
      clampDouble(selectionRect.top, editingRegion.top, editingRegion.bottom),
    ),
    secondaryAnchor: Offset(
      selectionRect.left + selectionRect.width / 2,
      clampDouble(selectionRect.bottom, editingRegion.top, editingRegion.bottom),
    ),
  );
}